简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM