开发者

Constraining the drawing of a line to 45 degree angles

开发者 https://www.devze.com 2022-12-18 07:59 出处:网络
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.

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 ca开发者_运维知识库n I use the start point, length and angle to determine the end point(x2, y2)?


x2 = x1 + lengthcos(angle)
y2 = y1 + length
sin(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.


For a screen:

For W = 0, N = 90, E = 180, S = 270:

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

For E = 0, N = 90, W = 180, S = 270:

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

Note that you need to make sure your implementation of cos works in degrees not radians otherwise you will get lines at strange angles.

0

精彩评论

暂无评论...
验证码 换一张
取 消