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

Parametric Line Problem

Started by Endemoniada Mar 30, 2013 at 8:55 PM 1 replies 1.2k views
Original Post
Endemoniada
Endemoniada

Hi guys, I have three 2D points P1, P2, P3 on a line, I want to see if P3 is before P1, between P1 and P2, or after P2. I'm pretty sure I can use the parametric line formula but I don't know how to set it up to compute the t for P3.

P1 would be at t=0

P2 would be at t=1

...then all I need is the t for P3. Thanks.

Waterlimon
Waterlimon

Make one of the points the origin.

t (from that origin point) of point = magnitude of point = sqrt(x^2 + y^2)

I guess you can skip the sqrt part to do the comparisons for a speedup.

EDIT:

you need one of the end points though for that to work though...

another way:

1.Get direction of line (normalize P2 - P1)

2.Use dot product on (Point - P1) (=sum of each component of (direction * (Point - P1)) ?)

o3o
Paradigm Shifter
Paradigm Shifter

You just need to solve

P1 + t(P2 - P1) = P3

Since you know P3 is on the line (it is, right?), you only need to solve for one of the components (i.e. solve for one of x or y; you can use the one with the highest t term which will always work).

Example:

P1 = (1, 1)

P2 = (5, 0)

P3 = (0, 1.25)

Solve (1, 1) + t(5-1, 0-1) = (0, 1.25)

In x:

1 + 4t = 0 => t = -0.25

In y:

1 - t = 1.25 => t = -0.25

Bob == Your Uncle

EDIT: Use the highest t term since sometimes t will vanish in 1 of the axes (e.g. line through the y axis will vanish in t when solving for x).

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Topic Locked

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

Sign in to reply to this topic.