forked from abrahamalbert18/HackerRank-Solutions-in-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClasses Torsion Angle without Numpy.py
53 lines (37 loc) · 1.42 KB
/
Classes Torsion Angle without Numpy.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
# Enter your code here. Read input from STDIN. Print output to STDOUT
import math
class CartesianCoordinates(object):
def __init__(self,A,B,C,D):
self.A=A
self.B=B
self.C=C
self.D=D
self.Angle= None
def vectorDiff(self, X,Y):
return [Y[i]- X[i] for i in range(len(X))]
def crossProduct(self, X,Y):
vector=[]
vector.append( X[1] * Y[2]- X[2]* Y[1])
vector.append( X[2] * Y[0]- X[0]* Y[2])
vector.append( X[0] * Y[1]- X[1]* Y[0])
return vector
def dotProduct(self,X,Y):
return sum([X[i] * Y[i] for i in range(len(X))])
def modulus(self, X):
return math.sqrt(sum([i**2 for i in X]))
def TorsionAngle(self,X,Y):
self.Angle= math.degrees(math.acos( self.dotProduct(X,Y) / (self.modulus(X) * self.modulus(Y)) ) )
def Program(self):
AB=self.vectorDiff(self.A,self.B)
BC=self.vectorDiff(self.B, self.C)
CD=self.vectorDiff(self.C, self.D)
X= self.crossProduct(AB,BC)
Y= self.crossProduct(BC,CD)
self.TorsionAngle(X,Y)
print round(self.Angle,2)
A= map(float, raw_input().split())
B= map(float, raw_input().split())
C= map(float, raw_input().split())
D= map(float, raw_input().split())
CC=CartesianCoordinates(A,B,C,D)
CC.Program()