A line can be defined just through the points P1, P2, so how do I solve for k and P in the equation?
Forget the point-in-line test for the moment. Given a known P1, P2, what do I set P equal to to solve for k? can P just be equal to P1 or P2? If this is the case, don’t i get different results for k depending on whether or not P = P1 or P2?
Like, if we have P = P1 + k(P2-P1),
can I then say P1 = P1 +k(P2-P1)?
rearranging, that seems like it just becomes P1 - P1/(P2-P1) = k = 0.
alternatively, if i put P = P2, i get the equation P2 = P1 + k(P2-P1), which is equal to (P2-P1)/(P2-P1) = k = 1.
So given that I can define my line with only P1 and P2, what value should i substitute for P to solve for K?
In most cases, you want to find k, such that the P on the line is closest to the P’ you input. A tolerance can be used to determine whether the point is on the line.
Try searching thru google by keywords:
“Point line distance”
I don’t see the need to find k, but here is what would be the answer.
We need only solve for one axis:
k = (P.x - P1.x)/(P2.x - P1.x)
Normally we use k for movement between two points on our vector.
ship starts at vector P1 and will end at P2.
k = 0 ship starting point.
k = 1 ship ending point.
k = 0;
loop_start
k +=0.01; Rate of movement.
P = P1 + k * ( P2 -P1 );
draw_ship_at( P );
keep looping until k = 1 ending point.
Originally posted by Coconut:
[b]In most cases, you want to find k, such that the P on the line is closest to the P’ you input. A tolerance can be used to determine whether the point is on the line.
Try searching thru google by keywords:
“Point line distance”
[/b]
[This message has been edited by nexusone (edited 11-14-2002).]