Line Equation with angle

geometry, math

Solution

An equation of a line is like:

m*x + n = y 

m can be calculated by angle; `m = tan(angle)` And if you know a start point then you can find n.

tan(angle) * startPoint_X + n = startPoint_Y

So `n = startPoint_Y - (tan ( angle) * startPoint_X )`

If you want to draw a line-segment and you know the length, the start point and the angle, there will be two equations.

The first is `m*x + n = y` (we solved it).

And this means `m*(endPoint_X) + n = endPoint_Y`

The second is to find the endPoint.

length^2 = (endPoint_X - startPoint_X)^2 + (endPoint_Y - startPoint_Y)^2

There are only two things that still we don't know: endPoint_x & endPoint_Y If we rewrite the equation:

length^2 = (endPoint_X - startPoint_X)^2 + ( m*(endPoint_X) + n - startPoint_Y)^2

now we know everything except endPoint_X. This equation will give us two solutions for endPoint_X. Then you can find two different ednPoint_Y.

Problem

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)?

Original source