Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Class 2 – Find the Torsional Angle Hacker Rank Solution – Queslers

Problem : Class 2 – Find the Torsional Angle in Python – Hacker Rank Solution

You are given four points A, B, c and 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 PHI.
Cos(PHI) = (X*Y) / |X| |Y| where X = ABxBC and Y = BC x CD.Here, X.Y means the dot product of X and Y, and ABxBC means the cross product of vectors and . Also, AB = B – A.


Input Format :

One line of input containing the space separated floating number values of the X,Y and Z coordinates of a point.

Output Format :

Output the angle correct up to two decimal places.


Sample Input :

0 4 5
1 7 6
0 5 9
1 7 2

Sample Output :

8.19

Class 2 – Find the Torsional Angle Hacker Rank Solution in python 2

import math

class Point:
  """docstring for Point"""
  def __init__(self, x, y, z):
    # super(Point, self).__init__()
    self.x = x
    self.y = y
    self.z = z

  def minus(self, other):
    return Point(self.x - other.x, self.y - other.y, self.z - other.z)

  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 dot(self, other):
    return self.x * other.x + self.y * other.y + self.z * other.z

  def abs(self):
    return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)

  def str(self):
    return "(" + str(self.x) + ", " + str(self.y) + ", " + str(self.z) + ")"

def get_Point():
  lst = map(float, raw_input().strip().split())
  return Point(lst[0], lst[1], lst[2])

a = get_Point()
b = get_Point()
c = get_Point()
d = get_Point()

ab = a.minus(b)
bc = b.minus(c)
cd = c.minus(d)

x = ab.cross(bc)
y = bc.cross(cd)

v = x.dot(y) / (x.abs() * y.abs())


print "%.2f" % (math.acos(v) / math.acos(0) * 90,)

Class 2 – Find the Torsional Angle Hacker Rank Solution in python 3

class Points(object):
    def __init__(self, x, y, z):
        self.x=x
        self.y=y
        self.z=z

    def __sub__(self, no):
        return  Points((self.x-no.x),(self.y-no.y),(self.z-no.z))

    def dot(self, no):
        return (self.x*no.x)+(self.y*no.y)+(self.z*no.z)

    def cross(self, no):
        return Points((self.y*no.z-self.z*no.y),(self.z*no.x-self.x*no.z),(self.x*no.y-self.y*no.x))
        
    def absolute(self):
        return pow((self.x ** 2 + self.y ** 2 + self.z ** 2), 0.5)

Class 2 – Find the Torsional Angle Hacker Rank Solution in pypy

class Points(object):
    def __init__(self, x, y, z):
        self.x=x
        self.y=y
        self.z=z
       
    def __sub__(self, other):
        return Points(self.x-other.x, self.y-other.y, self.z-other.z)   
         
    def dot(self, other):
        return (self.x*other.x)+ (self.y*other.y )+ (self.z*other.z)
    def cross(self, other):
        return Points( 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 absolute(self):
        return pow((self.x ** 2 + self.y ** 2 + self.z ** 2), 0.5)

Class 2 – Find the Torsional Angle Hacker Rank Solution in pypy 3

from math import acos, sqrt, degrees

class Vector:
    def __init__(self, x=0, y=0, z=0):
        self.x = x
        self.y = y
        self.z = z
    
    def __sub__(self, other):
        return Vector(self.x - other.x, self.y - other.y, self.z - other.z)
    
    def __mul__(self, other):
        return self.x * other.x + self.y * other.y + self.z * other.z
        
    def __and__(self, other):
        return Vector(self.y * other.z - other.y * self.z,
                      other.x * self.z - self.x * other.z,
                      self.x * other.y - other.x * self.y)
    
    def __abs__(self):
        return sqrt(self * self)
    
def read_vector():
    return Vector(*[float(x) for x in input().split()])

A = read_vector()
B = read_vector()
C = read_vector()
D = read_vector()

X = (B - A) & (C - B)
Y = (C - B) & (D - C)
phi = degrees(acos((X * Y)/(abs(X) * abs(Y))))
print('{:0.2f}'.format(phi))
Class 2 – Find the Torsional Angle Hacker Rank Solution Review:

In our experience, we suggest you solve this Class 2 – Find the Torsional Angle Hacker Rank Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

Class 2 – Find the Torsional Angle is available on Hacker Rank for Free, if you are stuck anywhere between compilation, just visit Queslers to get all Hacker Rank Solution

Class 2 – Find the Torsional Angle Hacker Rank Solution Conclusion:

I hope this Class 2 – Find the Torsional Angle Hacker Rank Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Hacker Rank Problem & Solutions >>

Mini-Max Sum Hacker Rank Solution

String Validators Hacker Rank Solution

Text Alignment Hacker Rank solution

String validators Hacker Rank Solution

Staircase Hacker Rank Solution

Leave a Reply

Your email address will not be published. Required fields are marked *