将线条的绘制限制为 45 度角
我有起点 (x1,y1) 以及所需的线长度和角度。
如果角度是方向,0 度是 W,90 度是 N,180 度是 E,270 度是 S。如果需要,我可以修改它。
如何使用起点、长度和角度来确定终点(x2,y2)?
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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
x2 = x1 + 长度cos(角度)
y2 = y1 + 长度sin(角度)
在这种情况下,角度逆时针增加,0 指向正 x。 x 轴向右增加,y 轴向上增加。
x2 = x1 + lengthcos(angle)
y2 = y1 + lengthsin(angle)
In this case angle is counter-clockwise increasing with 0 pointing towards positive x. The x axis is increasing to the right, and the y axis up.
对于屏幕:
对于 W = 0、N = 90、E = 180、S = 270:
对于 E = 0、N = 90、W = 180、S = 270:
请注意,您需要确保 cos 的实现有效以度而不是弧度为单位,否则你会得到奇怪角度的线。
For a screen:
For W = 0, N = 90, E = 180, S = 270:
For E = 0, N = 90, W = 180, S = 270:
Note that you need to make sure your implementation of cos works in degrees not radians otherwise you will get lines at strange angles.