Actually you are calculating with 3 points P, P1 and P2 with P=($x,$y)
Is your intention to check if the path P1-P2 and P-P1 are on the same straight line or what?
One approach:
A path is "straight" iff the two vectors are identical after normalization (i.e. shortened to length 1 and with same orientation)
To normalize them divide each component by the length of the vector.
In 2 dimensional space you get the length simply by applying Pythagoras...in higher dimension use the scalar product.
Another (easier)approach:
Calculate the normal vector n of P1-P2 (a normalized vector orthogonal to the line).
The scalar product (aka dot product) of n · (P-P1) == 0 iff P,P1 and P2 are collinear.
Don't wanna go deeper into details thats all school stuff...
Cheers Rolf
In reply to Re: Check if line is straight
by LanX
in thread Check if line is straight
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |