point on a line
Hi all,
Is there a quick way to determine if a point P(x,y) lies on a line of Ls(x1,y1),Le(x2,y2) ? Dirty example shown below:
(x1,y1)
\
\
.P
\
\(x2,y2)
This would be true, P does lie on the line.
Kindest regards,
Steve
If it isn't working, take a bath, have a think and try again...
Yeah, there''s a really easy way. Make an equation of the line, then test the point P to see if it satisfies the equation. The best line equation to use would probably be point-slope form: y-y1=m(x-x1) where (x1,y1) is any point on the line, like your endpoint, and m is the slope, (y2-y1)/(x2-x1). Once you get that equation, input your point P for the variables x and y, then see if both sides are equal. If they are, the point is on the line. Keep in mind, if you are using floats, the sides will almost never be exactly equal, so you can just check to see how far off they are. You could use a threshold value, like 1*10^-10, and if the sides differ by less than that, you''d say the point is on the line.
Another way to do it would be to use the point-line distance equation, and see if the distance is zero. They are essentially the same technique, but maube with slightly different equations.
Another way to do it would be to use the point-line distance equation, and see if the distance is zero. They are essentially the same technique, but maube with slightly different equations.
You know what I never noticed before?
Thanks!
Steve
Steve
If it isn't working, take a bath, have a think and try again...
April 27, 2003 10:40 AM
Normalize LsLe as V
Project P on V and check if the orthogonal part is small enough
P = (P*V)*V + N
N = P - (P*V)*V
check if N*N < epsilon
If you do lots of these and the legnths of LsLe are bounded, you can avoid doing the normalization and change the epsilon accordingly
Project P on V and check if the orthogonal part is small enough
P = (P*V)*V + N
N = P - (P*V)*V
check if N*N < epsilon
If you do lots of these and the legnths of LsLe are bounded, you can avoid doing the normalization and change the epsilon accordingly

This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement