Skip to content

Commit 4986968

Browse files
committed
added 'Points' solution
1 parent 015523c commit 4986968

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

hackerrank/classes/Points.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import math
2+
3+
class Points(object):
4+
def __init__(self, x, y, z):
5+
self.x = x
6+
self.y = y
7+
self.z = z
8+
def __sub__(self, other):
9+
return Points(self.x - other.x, self.y - other.y, self.z - other.z)
10+
def __str__(self):
11+
return '({}, {}, {})'.format(self.x, self.y, self.z)
12+
def dot(self, other):
13+
return (self.x * other.x) + (self.y * other.y) + (self.z * other.z)
14+
def cross(self, other):
15+
return Points((self.y * other.z) - (self.z * other.y), (self.x * other.z) - (self.z * other.x), (self.x * other.y) - (self.y * other.x))
16+
def absolute(self):
17+
return pow((self.x ** 2 + self.y ** 2 + self.z ** 2), 0.5)
18+
19+
if __name__ == '__main__':
20+
points = list()
21+
for i in range(4):
22+
a = list(map(float, input().split()))
23+
points.append(a)
24+
25+
a, b, c, d = Points(*points[0]), Points(*points[1]), Points(*points[2]), Points(*points[3])
26+
x = (b - a).cross(c - b)
27+
y = (c - b).cross(d - c)
28+
print(b-a, c-b, d-c)
29+
print(x, y)
30+
angle = math.acos(x.dot(y) / (x.absolute() * y.absolute()))
31+
32+
print("%.2f" % math.degrees(angle))

0 commit comments

Comments
 (0)