# Parametric Line Problem

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

## Recommended Posts

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.

##### Share on other sites

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)) ?)

Edited by Waterlimon

##### Share on other sites

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

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).

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
633714
• Total Posts
3013490
×