tags:

views:

530

answers:

4

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

+1  A: 

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.

Peter
But the resulting line will not have length x_length.
GvS
This doesn't work for +- 90 degrees (+- pi/2 radians) and will have variable accuracy dependant on the angle (closer to +- 90 the more inaccurate).
Skizz
if you're given a 'length along the x-axis' (in the original question), then you don't have a +/- case. that's also what `x_length` means. the question has since changed dramatically...
Peter
+6  A: 

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.

Artelius
+3  A: 

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.

morechilli
+1  A: 

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

H2O
Your second equation is wrong, it should be startPoint_Y - (tan ( angle) * startPoint_X ), but even then, the answer is far more complex than necessary.
Skizz
i agree that this is more complex.i just wanna show how to do it without trigonometric functions. i'd like not to use tan(), but i don't want to extend my answer more...:)By the way, i edited. thanks...
H2O