Archived

This topic is now archived and is closed to further replies.

leiavoia

Vectors: point on a line (math doesn't work?)

Recommended Posts

From this website:
quote:
The origin/direction method (also known as the parametric representation) is particularly handy when you need to find the coordinates of a given point on a line. The equation to do this is: (x,y) = (xo, yo) + k * (xd, yd) where k is some scalar value. Setting k to 0 will return the first endpoint, setting it to 1 will return the second endpoint. If you want to find a point halfway along the line then simply set k to 0.5, similarly setting k to 2 will return a point on the line that is twice as far from P1 as P2 is. In computer graphics you often have to find intersections between lines and other objects (such as other lines, planes, cubes etc). These intersection equations often return a k value for the point of intersection, and you have to plug this value into the above equation to get the actual 3D coordinates for the point of intersection. If these functions return a k value where 0 <= k <= 1 then you know the intersection occurred on the line somewhere between the endpoints P1 and P2 (or on them).
So this formula should give me a point on an origin-to-end vector, right? Well, it doesn't work for a straight-up/down line. I'm not sure it's right or that i'm applying it right. Example: start: 5,2 end: 5,10 problem: i want a point half way in between (should be 5,6) math: x = 5 + (0.5 * 5) = 7.5 y = 2 + (0.5 * 10) = 7 am i doing this wrong or what? I'd really like to understand how to get a point on a line! thanks in advance [edited by - leiavoia on April 5, 2004 1:50:19 AM]

Share this post


Link to post
Share on other sites
for P1 = (P1x,P1y) and P2 = (P2x,P2y) it´s xo = P1x, yo = P1y, xd = P2x-P1x and yd = P2y-P1y. The equation will be correct, then.

thus your example would be:
x = 5 + [.5 * (5-5)] = 5
y = 2 + [.5 * (10-2)]= 6

Share this post


Link to post
Share on other sites
The symbol d, read for delta, often implies difference. In this case, the difference between the first and last points.


blah blah blah.

Share this post


Link to post
Share on other sites
oh.... i thought it meant D estination. Thanks :-) That makes a lot more sense.

[edited by - leiavoia on April 5, 2004 11:37:27 AM]

Share this post


Link to post
Share on other sites
Well, b/c you''re varying k from [0...1] meaning at 0, you get (x0, y0) and at 1 you get (x1, y1), then you know that (xd, yd) must have the length of the distance btw p0 and p1, and must be coincident w/ both because you''re adding a vector to an initial position. You can do this (and consequently vary k any way you''d like to):

(x, y) = (x1, y1) = (x0, y0) + (k=1)*(xd, yd)
so (xd, yd) = (x1-x0, y1-y0)

or if you want (x,y) to be (x1, y1) when k = |(x1-x0, y1-y0)|
then (xd, yd) must equal (x1-x0, y1-y0)/|(x0->x1)|, in other words (xd, yd) would be a unit vector. Cool, eh?

Share this post


Link to post
Share on other sites