Open In App

Python | Sympy Line.angle_between method

In Sympy, the function angle_between() is used to return the non-reflex angle formed by rays emanating from the origin with directions the same as the direction vectors of the linear entities.
Syntax: Line.angle_between(l2)

 Parameters: 
  l1: LinearEntity
  l2: LinearEntity

Returns:
 angle: angle in radians

Notes: From the dot product of vectors v1 and v2 it is known that: dot(v1, v2) = |v1|*|v2|*cos(A)
where A is the angle formed between the two vectors. We can get the directional vectors of the two lines and readily find the angle between the two using the above formula.



Example #1:




# import sympy and Point, Line, pi
from sympy import Point, Line, pi
  
# using Line() method
l1 = Line((0, 0), (1, 0))
l2 = Line((0, 0), (1, 1))
  
# using angle_between() method
rad = l1.angle_between(l2)
  
print(rad)

Output:

pi/4

Example #2:




# import sympy and Point, Line, pi
from sympy import Point, Line, pi
  
# using Line() method
l1 = Line((0, 0), (1, 0))
l3 = Line((1, 1), (0, 0))
  
# using angle_between() method
rad = l1.angle_between(l3)
  
print(rad)

Output:



3*pi/4
Article Tags :