This is kind of an embarrassing question to ask, since I *know* I learned
this in high school. But then, that was a long time ago. So here goes:
On a 2D plane, given a point (x,y) and a slope (m), how can I extend a line
with a length of (n) units along the slope, and find the endpoints (x1,y1)
of that line?
Many thanks in advance.
I am assuming that you want to find the OTHER endpoint which is N units
away from X1,Y1 at a slope M.
Two rules are helpful:
(x-x1)^2 + (y-y1)^2 = N^2 => N squared equals the X distance squared
plus the Y distance squared.
(y-y1)/(x-x1)=M => The change in Y over the change in X equals the
(y-y1)=(x-x1)*M => This can then be substituted into the first
equation to solve for X:
(x-x1)^2 * (1+m^2) = N^2
Solve for X, plug into the slope equation, and get Y.
Hope this helps.
Matt Kimmel wrote in message <75b9vk$3se$1...@winter.news.rcn.net>...
> On a 2D plane, given a point (x,y) and a slope (m), how can I extend a
> line with a length of (n) units along the slope, and find the endpoints
> (x1,y1) of that line?
If you find a unit vector ( a, b ) in the right direction, the solution
( x, y ) + n ( a, b )
in other words:
( x + n*a , y + n*b )
In fact a,b are not difficult to find if you have _any_ vector in the
right direction. For example
( 1, m ) with length sqrt(1 + m^2)
==> a = 1/(sqrt(1 + m^2)) and b = m/(sqrt(1 + m^2))
This is a vector problem. The solution is a vector of length n, at slope
m. The slope is the tangent of the angle from the x-axis, so the vector's
direction angle is arctan(m). But the problem can be solved without
Draw a little picture, which will make the next bit easier. You have a
right triangle. The x-axis is parallel to one leg; the point (x,y) is one
vertex, the desired line (the vector) is the hypotenuse, and therefore
(x1,y1) is the other end of the hypotenuse. Drop a perpendicular to where
it meets the other leg.
Now the hypotenuse measures n. The legs measure (x1-x) and (y1-y), and
you know (given the slope) that (y1-y) = m(x1-x) or y1 = m(x1-x)+y. Now
how to solve for x1? Well, you also know that (x1-x)^2+(y1-y)^2=n^2
(theorem of Pythagoras), so you can solve that way. It's a bit messy, but
that's an artifact of the way the problem was stated.
In trig terms, it's a lot easier. Using the same picture, define angle A
such that tan(A) = m. Then x1 = x+n*cos(A), y1 = y+n*sin(A).