-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtorsion_angle.py
68 lines (49 loc) · 1.57 KB
/
torsion_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import math
class PointIterator:
def __init__(self, point):
self._point = point
self._index = 0
def __next__(self):
if self._index < 3:
if self._index == 0:
res = self._point.x
elif self._index == 1:
res = self._point.y
else:
res = self._point.z
self._index += 1
return res
raise StopIteration
class Point:
def __init__(self, x=0, y=0, z=0):
self.x = x
self.y = y
self.z = z
def __iter__(self):
return PointIterator(self)
def __repr__(self):
return f'<x={self.x}, y={self.y}, z={self.z}>'
def __str__(self):
return f'({self.x}, {self.y}, {self.z})'
def __sub__(self, other):
return Point(other.x - self.x, other.y - self.y, other.z - self.z)
def abs(self):
return (self.x**2 + self.y**2 + self.z**2)**(0.5)
def dot(self, other):
return sum(self_i * other_i for self_i, other_i in zip(self, other))
def cross(self, other):
return Point(self.y * other.z - self.z * other.y,
self.z * other.x - self.x * other.z,
self.x * other.y - self.y * other.x)
def main():
points = []
for _ in range(4):
point = Point(*map(int, input().split()))
points.append(point)
a, b, c, d = points
x = (b - a).cross(c - b)
y = (c - b).cross(d - c)
angle = math.acos(x.dot(y)/(x.abs() * y.abs()))
print(f'{math.degrees(angle):.2f}')
if __name__ == '__main__':
main()