Jump to content
  • Advertisement
Sign in to follow this  
dnatapov

Find point on a line, given distance?

This topic is 3792 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!