In this HackerRank Class 2 - Find the Torsional Angle problem solution You are given four points A, B, C, and A, C, D in a 3-dimensional Cartesian coordinate system. You are required to print the angle between the plane made by the points A, B, C and B, C, D in degrees(not radians). Let the angle be P H I.

Cos(P H I) = (X.Y)/X||Y| where X = AB x BC and Y = BC x CD.

Here, X.Y means the dot product of X and Y, and AB x BC means the cross product of vectors AB and BC. Also, AB = B - A.

## HackerRank Class 2 - Find the Torsional Anglein python problem solution

```# Enter your code here. Read input from STDIN. Print output to STDOUT
import math
class coords:
def __init__(self,A):
self.x = A[0]
self.y = A[1]
self.z = A[2]
def __sub__(self,B):
AB_x = self.x - B.x
AB_y = self.y - B.y
AB_z = self.z - B.z
AB = [AB_x,AB_y,AB_z]
return coords(AB)
def cross(A,B):
AB_x = A.y * B.z - A.z * B.y
AB_y = A.z * B.x - A.x * B.z
AB_z = A.x * B.y - A.y * B.x
AB = [AB_x,AB_y,AB_z]
return coords(AB)
def dot(A,B):
return A.x * B.x + A.y * B.y + A.z * B.z
def mod(A):
return math.sqrt(A.x **2 + A.y **2 + A.z **2)
def printc(A):
print "{}".format(A.x) + " " + "{}".format(A.y) + " " + "{}".format(A.z)

A = coords(map(float,raw_input().split()))
B = coords(map(float,raw_input().split()))
C = coords(map(float,raw_input().split()))
D = coords(map(float,raw_input().split()))
AB = A - B
BC = B - C
CD = C - D
X = cross(AB,BC)
Y = cross(BC,CD)
if mod(X) and mod(Y):
phi = math.acos(dot(X,Y)/(mod(X)*mod(Y)))
print "{:0.2f}".format(phi*180/math.pi)
elif mod(X) == 0 or mod(y) ==0:
print "90.00"```