Package org.locationtech.jts.algorithm
Class Orientation
java.lang.Object
org.locationtech.jts.algorithm.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).
Determining triangle 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.
- Author:
- Martin Davis
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
A value that indicates an orientation of clockwise, or a right turn.static final int
A value that indicates an orientation of collinear, or no turn (straight).static final int
A value that indicates an orientation of counterclockwise, or a left turn.static final int
A value that indicates an orientation of counterclockwise, or a left turn.static final int
A value that indicates an orientation of clockwise, or a right turn.static final int
A value that indicates an orientation of collinear, or no turn (straight). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
index
(Coordinate p1, Coordinate p2, Coordinate q) Returns the orientation index of the direction of the pointq
relative to a directed infinite line specified byp1-p2
.static boolean
isCCW
(Coordinate[] ring) Tests if a ring defined by an array ofCoordinate
s is oriented counter-clockwise.static boolean
isCCW
(CoordinateSequence ring) Tests if a ring defined by aCoordinateSequence
is oriented counter-clockwise.static boolean
isCCWArea
(Coordinate[] ring) Tests if a ring defined by an array ofCoordinate
s is oriented counter-clockwise, using the signed area of the ring.
-
Field Details
-
CLOCKWISE
public static final int CLOCKWISEA value that indicates an orientation of clockwise, or a right turn.- See Also:
-
RIGHT
public static final int RIGHTA value that indicates an orientation of clockwise, or a right turn.- See Also:
-
COUNTERCLOCKWISE
public static final int COUNTERCLOCKWISEA value that indicates an orientation of counterclockwise, or a left turn.- See Also:
-
LEFT
public static final int LEFTA value that indicates an orientation of counterclockwise, or a left turn.- See Also:
-
COLLINEAR
public static final int COLLINEARA value that indicates an orientation of collinear, or no turn (straight).- See Also:
-
STRAIGHT
public static final int STRAIGHTA value that indicates an orientation of collinear, or no turn (straight).- See Also:
-
-
Constructor Details
-
Orientation
public Orientation()
-
-
Method Details
-
index
Returns the orientation index of the direction of the pointq
relative to a directed infinite line specified byp1-p2
. The index indicates whether the point lies to theLEFT
orRIGHT
of the line, or lies on itCOLLINEAR
. The index also indicates the orientation of the triangle formed by the three points (COUNTERCLOCKWISE
,CLOCKWISE
, orSTRAIGHT
)- Parameters:
p1
- the origin point of the line vectorp2
- the final point of the line vectorq
- the point to compute the direction to- Returns:
- -1 (
CLOCKWISE
orRIGHT
) if q is clockwise (right) from p1-p2; 1 (COUNTERCLOCKWISE
orLEFT
) if q is counter-clockwise (left) from p1-p2; 0 (COLLINEAR
orSTRAIGHT
) if q is collinear with p1-p2
-
isCCW
Tests if a ring defined by an array ofCoordinate
s is oriented counter-clockwise.- The list of points is assumed to have the first and last points equal.
- This handles coordinate lists which contain repeated points.
- This handles rings which contain collapsed segments (in particular, along the top of the ring).
- Parameters:
ring
- an array of Coordinates forming a ring (with first and last point identical)- Returns:
- true if the ring is oriented counter-clockwise.
- Throws:
IllegalArgumentException
- if there are too few points to determine orientation (< 4)
-
isCCW
Tests if a ring defined by aCoordinateSequence
is oriented counter-clockwise.- The list of points is assumed to have the first and last points equal.
- This handles coordinate lists which contain repeated points.
- This handles rings which contain collapsed segments (in particular, along the top of the ring).
- Parameters:
ring
- a CoordinateSequence forming a ring (with first and last point identical)- Returns:
- true if the ring is oriented counter-clockwise.
-
isCCWArea
Tests if a ring defined by an array ofCoordinate
s is oriented counter-clockwise, using the signed area of the ring.- The list of points is assumed to have the first and last points equal.
- This handles coordinate lists which contain repeated points.
- This handles rings which contain collapsed segments (in particular, along the top of the ring).
- This handles rings which are invalid due to self-intersection
However, this approach may be less accurate in the case of rings with almost zero area. (Note that the orientation of rings with zero area is essentially undefined, and hence non-deterministic.)
- Parameters:
ring
- an array of Coordinates forming a ring (with first and last point identical)- Returns:
- true if the ring is oriented counter-clockwise.
-