Line Equation with angle

前端 未结 5 1771
逝去的感伤
逝去的感伤 2020-12-13 06:36

How can I find equation of a line or draw a line, given a starting point, length of line and angle of line (relative to x-axis)?

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 06:56

    Let's call the start point (x1, y1) the other end of the line (x2, y2).

    Then if you are given a length [L] and an angle from the x-axis [a]:

    x2 = x1 + (L * cos(a))
    
    y2 = y1 + (L * sin(a))
    

    If the angle is from the y-axis - swap the cos and the sin.

    Draw your line from (x1,y1) to (x2, y2).

    You may find an ambiguity as to which direction you want the line to go, you need to be careful how you define your angle.

提交回复
热议问题