Compute the relative orientation of 3 points.
CCW = isCounterClockwise(P1, P2, P3);
Computes the orientation of the 3 points. The returns is:
+1 if the path P1->P2->P3 turns Counter-Clockwise (i.e., the point P3
is located "on the left" of the line P1-P2)
-1 if the path turns Clockwise (i.e., the point P3 lies "on the right"
of the line P1-P2)
0 if the point P3 is located on the line segment [P1 P2].
This function can be used in more complicated algorithms: detection of
line segment intersections, convex hulls, point in triangle...
CCW = isCounterClockwise(P1, P2, P3, EPS);
Specifies the threshold used for detecting colinearity of the 3 points.
Default value is 1e-12 (absolute).
Example
isCounterClockwise([0 0], [10 0], [10 10])
ans =
1
isCounterClockwise([0 0], [0 10], [10 10])
ans =
-1
isCounterClockwise([0 0], [10 0], [5 0])
ans =
0
See also
points2d, isPointOnLine, isPointInTriangle, polygonArea
References
Algorithm adapated from Sedgewick's book.
Package: matgeom