Home > Mobile >  Calculate coordinates of end point of a line by having the angle and the length
Calculate coordinates of end point of a line by having the angle and the length

Time:07-01

I have the coordinates of the start point of a line and also i have the angle and length of that line and i want to get the coordinates of the endpoint.

I am using the script:

X_B = X_A   (length * round(abs(math.cos(Angle))))
Y_B = Y_A   (length * round(abs(math.sin(Angle))))

But in many cases it doesnt work!

CodePudding user response:

Make sure the angle is in radians, not in degrees:

import math 

length = 1
Angle = 3.14/3
X_A = 0
Y_A = 0

X_B = X_A   round(length * math.cos(Angle), 3)
Y_B = Y_A   round(length * math.sin(Angle), 3)

print(X_B, Y_B)

Output: Also, don't round sin or cos. Perform the round on the resulting value.

0.5 0.866
  • Related