-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass 2 - Find the torsional angle.py
45 lines (36 loc) · 1.1 KB
/
Class 2 - Find the torsional angle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Enter your code here. Read input from STDIN. Print output to STDOUT
# Author : Vineet
import math
class Points(object):
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def __sub__(self, no):
x = self.x - no.x
y = self.y - no.y
z = self.z - no.z
return Points(x, y, z)
def dot(self, no):
x = self.x * no.x
y = self.y * no.y
z = self.z * no.z
return x + y + z
def cross(self, no):
x = self.y * no.z - self.z * no.y
y = self.z * no.x - self.x * no.z
z = self.x * no.y - self.y * no.x
return Points(x, y, z)
def absolute_scale(self):
return pow((self.x ** 2 + self.y ** 2 + self.z ** 2), .5)
def solve(A, B, C, D):
A, B, C, D = Points(*A), Points(*B), Points(*C), Points(*D)
X = (B - A).cross(C - B)
Y = (C - B).cross(D - C)
angle = math.acos(X.dot(Y) / (X.absolute_scale() * Y.absolute_scale()))
print "%.2f" % math.degrees(angle)
points = list()
for i in range(4):
a = map(float, raw_input().split())
points.append(a)
solve(*points)