Find point between 2 points?
Members - Reputation: 103
Posted 17 April 2011 - 05:54 PM
Crossbones+ - Reputation: 7456
Posted 17 April 2011 - 06:09 PM
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?
to find a line 1/4th of the distance between 2 points you just need:
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
p3x = p1x+dirx*0.25;
p3y = p1y+diry*0.25;
The voices in my head may not be real, but they have some good ideas!
Crossbones+ - Reputation: 9055
Posted 17 April 2011 - 06:11 PM
C = (B - A) * .25 + A
C = (<4,4> - <1,1>) * .25 + <1,1>
C = <3,3> * .25 + <1,1>
C = <.75,.75> + <1,1>
C = <1.75, 1.75>
Cx = (Bx - Ax) * .25 + Ax
Cy = (By - Ay) * .25 + Ay
gzip: H4sIAAAAAAAEAG1QTUvEMBC991e8nvaiFfYoS7yo sLCo6MnjtJ1ugmkiyWRL/72z3T1YEQIJ8z4zA2Xp yPvt1qBpGrRFIJZkk9FyRyUzHCbKIHgn4hnZOrm1 TD0mG0HCCs+QGDGWziKXI6Wm2n++GYwUVH2mrGEE PnGCVQ8K8+JYfXA6URDEQfMZh5h6g5eoAlWJdeEI bbH2qYZf7XMUfw8f/Q0oMeZYNL9/WHF0uFEshvMr XYujd9SycFb+F18QcSOvlJauZ8ejqevdnV7/d550 e0t6prmunh73Bu+vz4c/XUeOQXfJgvKNkhf95U8/ Dtgmy5IBAAA=