Skip to main content
GameDev.net gamedev.net
🔒 Locked

Find point on a line, given distance?

Started by dnatapov Apr 1, 2008 at 2:06 PM 4 replies 19.3k views
Original Post
dnatapov
dnatapov
Hi, I've been frustratingly stuck with the math for this, and was hoping someone could help out. I have two points: A,B in 3D space (and therefore a line between them). I'm looking for a third point, C, along this line, a specific distance away from point B. But in the direction of point C. How do I find this point? I've tried using similar triangles, and parametric line equations but I'm getting strange results, and I'm not sure if it's borked code or borked math... Trying to verify the math, or find a better way of doing this. Thanks in advance!
Bob Janova
Bob Janova
Use vectors. C = B - k(A - B). k = (the distance you want) / (distance from A to B), or k = proportion of distance to place C (0: place at B; 1: place at A).

e: bad bold tag polarity
alvaro
alvaro
Part of the description of what you want made no sense ("in the direction of point C"?).

There are two points that are in that line whose distance to C is d:
C = B + (A-B)*d/distance(A,B)C = B - (A-B)*d/distance(A,B)
Bob Janova
Bob Janova
I'm pretty sure that by 'on this line' he means between A and B.
dnatapov
dnatapov
Quote:
Original post by Bob Janova
Use vectors. C = B - k(A - B). k = (the distance you want) / (distance from A to B), or k = proportion of distance to place C (0: place at B; 1: place at A).

e: bad bold tag polarity



Ah there it is!
I was doing C = A + k(A - B);

It seems to work now. Thanks a lot for the help! :D
shurcool
shurcool
Quote:
Original post by dnatapov
Quote:
Original post by Bob Janova
Use vectors. C = B - k(A - B). k = (the distance you want) / (distance from A to B), or k = proportion of distance to place C (0: place at B; 1: place at A).

e: bad bold tag polarity



Ah there it is!
I was doing C = A + k(A - B);

It seems to work now. Thanks a lot for the help! :D

That's how I would've done it, except it's C = A + k(B - A). A is the starting point, (B - A) is the vector pointing in the direction of B if you take A as the origin.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.