Sign in to follow this  

Parametric Line Problem

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 this post

Link to post
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.




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 this post

Link to post
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).




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

Edited by Paradigm Shifter

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