0

I have the start point (x1,y1) and the desired length and angle of the line.

If the angles were directions, 0 degrees is W, 90 is N, 180 is E and 270 is S. I can modify this if needed.

How can I use the start point, length and angle to determine the end point(x2, y2)?

4

2 回答 2

7

x2 = x1 + 长度cos(角度)
y2 = y1 + 长度
sin(角度)

在这种情况下,角度逆时针增加,0 指向正 x。x 轴向右增加,y 轴向上。

于 2010-01-29T22:35:23.273 回答
4

对于屏幕:

对于 W = 0、N = 90、E = 180、S = 270:

x2 = x1 - length * cos(angle)
y2 = y1 - length * sin(angle)

对于 E = 0、N = 90、W = 180、S = 270:

x2 = x1 + length * cos(angle)
y2 = y1 - length * sin(angle)

请注意,您需要确保 cos 的实现以度而不是弧度工作,否则您会得到奇怪角度的线条。

于 2010-01-29T22:39:06.320 回答