Jump to content

  • Log In with Google      Sign In   
  • Create Account

Getting P3 from P1, P2. Dist P3-P1 > Dist P1-P2 & P3 on line P1-P2


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 homer_3   Members   -  Reputation: 173

Like
0Likes
Like

Posted 07 April 2011 - 07:12 PM

I'm trying to get point 3 from points 1 and 2 such that point 3 is on the same line that points 1 and 2 form, the distance between P1 and P3 is greater than P1 and P2, and the vector direction from P1 to P3 is the same as P1 to P2. This is what I have, but it doesn't work at all. Can anyone point out where I went wrong?


Origin is top left. +X is right. +Y is down.

lv_destPos = OrderGetTargetPoint(EventUnitOrder());
lv_destX = PointGetX(lv_destPos);
lv_destY = PointGetY(lv_destPos);

lv_curX = PointGetX(lv_curPos);
lv_curY = PointGetY(lv_curPos);

//get slope
lv_m = (lv_curY-lv_destY)/(lv_curX-lv_destX);

//get y intercept
lv_b = lv_y - (lv_m * lv_x);

//clicked to right
if(lv_destX > lv_curX)
{
    lv_destX = lv_destX + 50.0;
    lv_destY  = (lv_m * lv_destX) + lv_b;
}else
{
    //clicked to left
    if(lv_destX < lv_curX)
    {
        lv_destX = lv_destX - 50.0;
        lv_destY  = (lv_m * lv_destX) + lv_b;
    }else
    {
        //clicked below
        if(lv_destY > lv_curY)
        {
            lv_destY = lv_destY+50;
            lv_destX = (lv_destY - lv_b)/lv_m;
        }else
        {
            //clicked above
            lv_destY = lv_destY-50;
            lv_destX = (lv_destY - lv_b)/lv_m;
        }
    }
}

lv_destPos = Point(lv_destX, lv_destY);


Sponsor:

#2 Emergent   Members   -  Reputation: 971

Like
0Likes
Like

Posted 07 April 2011 - 08:57 PM

Any point on the line containing points p1 and p2 can be written as,

p = (1 - t) p1 + t p2

for some real number t. When t=0, you get p1. When t=1, you get p2. When 0 < t < 1, you get a point in-between (e.g., when t=1/2, you get the midpoint). When t is negative, or when it is greater than 1, you get a point beyond p1 or p2 on the line, respectively.

#3 Álvaro   Crossbones+   -  Reputation: 13368

Like
0Likes
Like

Posted 08 April 2011 - 06:33 AM

What Emergent said. Maybe you'll find it easier to think of that formula as
P3 = P1 + t*(P2-P1)

Plugging in t=2 will give you a P3 that satisfies everything you asked for.

#4 homer_3   Members   -  Reputation: 173

Like
0Likes
Like

Posted 08 April 2011 - 05:10 PM

P3 = P1 + t*(P2-P1)




I remember doing this before and I thought it was P1 * t*(P2-P1). But that didn't work for me so I tried just getting the line formula and going from there. I'll try this out though, thanks. Just to be clear


P3.X = P1.X + t*(P2.X-P1.X)
P3.Y = P1.Y + t*(P2.Y-P1.Y)


correct?

#5 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 08 April 2011 - 07:57 PM

[P3.X = P1.X + t*(P2.X-P1.X)
P3.Y = P1.Y + t*(P2.Y-P1.Y)

correct?

As far as the parametric line form goes, yes, that looks correct.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS