Class Orientation

Hierarchy: Object , Orientation
public class Orientation
Functions to compute the orientation of basic geometric structures including point triplets (triangles) and rings. Orientation is a fundamental property of planar geometries (and more generally geometry on two-dimensional manifolds).

Orientation is notoriously subject to numerical precision errors in the case of collinear or nearly collinear points. JTS uses extended-precision arithmetic to increase the robustness of the computation.

Authors:
Martin Davis
public static int index(Coordinate p1, Coordinate p2, Coordinate q)
Returns the orientation index of the direction of the point q relative to a directed infinite line specified by p1-p2. The index indicates whether the point lies to the LEFT or RIGHT of the line, or lies on it COLLINEAR. The index also indicates the orientation of the triangle formed by the three points ( COUNTERCLOCKWISE, CLOCKWISE, or STRAIGHT )
Parameters:
p1 - p1 the origin point of the line vector
p2 - p2 the final point of the line vector
q - q the point to compute the direction to
Returns:
-1 ( CLOCKWISE or RIGHT ) if q is clockwise (right) from p1-p2; 1 ( COUNTERCLOCKWISE or LEFT ) if q is counter-clockwise (left) from p1-p2; 0 ( COLLINEAR or STRAIGHT ) if q is collinear with p1-p2
public static boolean isCCW(Coordinate[] ring)
Computes whether a ring defined by an array of Coordinates is oriented counter-clockwise.
  • The list of points is assumed to have the first and last points equal.
  • This will handle coordinate lists which contain repeated points.
This algorithm is only guaranteed to work with valid rings. If the ring is invalid (e.g. self-crosses or touches), the computed result may not be correct.
Parameters:
ring - ring an array of Coordinates forming a ring
Returns:
true if the ring is oriented counter-clockwise.
Throws:
IllegalArgumentException - IllegalArgumentException if there are too few points to determine orientation (< 4)
public static boolean isCCW(CoordinateSequence ring)
Computes whether a ring defined by an CoordinateSequence is oriented counter-clockwise.
  • The list of points is assumed to have the first and last points equal.
  • This will handle coordinate lists which contain repeated points.
This algorithm is only guaranteed to work with valid rings. If the ring is invalid (e.g. self-crosses or touches), the computed result may not be correct.
Parameters:
ring - ring a CoordinateSequence forming a ring
Returns:
true if the ring is oriented counter-clockwise.
Throws:
IllegalArgumentException - IllegalArgumentException if there are too few points to determine orientation (< 4)