Sign in to follow this  
tuphdc

Find point between 2 points?

Recommended Posts

I am having a problem finding a point at a specific distance between 2 points. Suppose I have point A(1,1) and point B(4,4). I know the distance between these 2 points is 4.24. However, I do not know how to find point C, which is 1/4 the distance from point A to point B. How do I find point C?

Share this post


Link to post
Share on other sites
[quote name='tuphdc' timestamp='1303084498' post='4799658']
I am having a problem finding a point at a specific distance between 2 points. Suppose I have point A(1,1) and point B(4,4). I know the distance between these 2 points is 4.24. However, I do not know how to find point C, which is 1/4 the distance from point A to point B. How do I find point C?
[/quote]

to find a line 1/4th of the distance between 2 points you just need:

Vector2D p1(1,1);
Vector2D p2(4,4);

Vector2D direction = p2-p1

Vector2D p3 = p1+ direction* 0.25; (assuming your vector library supports scalar multiplication, if not its simply p3.x = p1.x + direction.x*0.25 and same for y)

If you don't have a vector library you can simply do

p1x=1;
p1y=1;
p2x=4;
p2y=4;

dirx=p2x-p1x;
diry=p2y-p1y;

p3x = p1x+dirx*0.25;
p3y = p1y+diry*0.25;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this