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)?
You'll want to draw it from (0, 0)
to (x_length, tan(angle)*x_length)
. The gradient will be tan(angle)
. You can adjust this for a different starting point by subtracting everything from that starting point.
Starting point you know (x1, x2)
, end point is (x1 + l * cos(ang), y1 + l * sin(ang))
where l
is the length and ang
is the angle.
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.
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 wanna draw a line-segment an you know length, start point and angle, there will be two equation.
first is m*x + n = y (we solved it)
And this mean m*(endPoint_X) + n = endPoint_Y
second is to find the endPoint
length^2 = (endPoint_X - startPoint_X)^2 + (endPoint_Y - startPoint_Y)^2
There is only two thing 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 solution for endPoint_X. And then u can find tow different ednPoint_Y