Class CGAlgorithms

Hierarchy: Object , CGAlgorithms
public class CGAlgorithms
Specifies and implements various fundamental Computational Geometric algorithms. The algorithms supplied in this class are robust for double-precision floating point.
Deprecation:
See Length, Area, Distance, Orientation, PointLocation

Other

  • version: 1.7
public CGAlgorithms()
public static int orientationIndex(Coordinate p1, Coordinate p2, Coordinate q)
Returns the index of the direction of the point q relative to a vector specified by p1-p2.
Parameters:
p1 - p1 the origin point of the vector
p2 - p2 the final point of the vector
q - q the point to compute the direction to
Returns:
1 if q is counter-clockwise (left) from p1-p2
-1 if q is clockwise (right) from p1-p2
0 if q is collinear with p1-p2
Deprecation:
Use Orientation.index(Coordinate, Coordinate, Coordinate) instead.
public static boolean isPointInRing(Coordinate p, Coordinate[] ring)
Tests whether a point lies inside or on a ring. The ring may be oriented in either direction. A point lying exactly on the ring boundary is considered to be inside the ring.

This method does not first check the point against the envelope of the ring.

Parameters:
p - p point to check for ring inclusion
ring - ring an array of coordinates representing the ring (which must have first point identical to last point)
See also:
locatePointInRing
Returns:
true if p is inside ring
Deprecation:
Use PointLocation.isInRing(Coordinate, Coordinate[]) instead.
public static int locatePointInRing(Coordinate p, Coordinate[] ring)
Determines whether a point lies in the interior, on the boundary, or in the exterior of a ring. The ring may be oriented in either direction.

This method does not first check the point against the envelope of the ring.

Parameters:
p - p point to check for ring inclusion
ring - ring an array of coordinates representing the ring (which must have first point identical to last point)
Returns:
the Location of p relative to the ring
Deprecation:
Use PointLocation.locateInRing(Coordinate, Coordinate[]) instead.
public static boolean isOnLine(Coordinate p, Coordinate[] pt)
Tests whether a point lies on the line segments defined by a list of coordinates.
Returns:
true if the point is a vertex of the line or lies in the interior of a line segment in the linestring
Deprecation:
Use PointLocation.isOnLine(Coordinate, Coordinate[]) instead.
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)
Deprecation:
Use Orientation.isCCW(Coordinate[]) instead.
public static int computeOrientation(Coordinate p1, Coordinate p2, Coordinate q)
Computes the orientation of a point q to the directed line segment p1-p2. The orientation of a point relative to a directed line segment indicates which way you turn to get to q after travelling from p1 to p2.
Parameters:
p1 - p1 the first vertex of the line segment
p2 - p2 the second vertex of the line segment
q - q the point to compute the relative orientation of
Returns:
1 if q is counter-clockwise from p1-p2, or -1 if q is clockwise from p1-p2, or 0 if q is collinear with p1-p2
Deprecation:
Use Orientation.index(Coordinate, Coordinate, Coordinate) instead.
public static double distancePointLine(Coordinate p, Coordinate A, Coordinate B)
Computes the distance from a point p to a line segment AB Note: NON-ROBUST!
Parameters:
p - p the point to compute the distance for
A - A one point of the line
B - B another point of the line (must be different to A)
Returns:
the distance from p to line segment AB
Deprecation:
Use Distance.pointToSegment(Coordinate, Coordinate, Coordinate) instead.
public static double distancePointLinePerpendicular(Coordinate p, Coordinate A, Coordinate B)
Computes the perpendicular distance from a point p to the (infinite) line containing the points AB
Parameters:
p - p the point to compute the distance for
A - A one point of the line
B - B another point of the line (must be different to A)
Returns:
the distance from p to line AB
Deprecation:
Use Distance.pointToLinePerpendicular(Coordinate, Coordinate, Coordinate) instead.
public static double distancePointLine(Coordinate p, Coordinate[] line)
Computes the distance from a point to a sequence of line segments.
Parameters:
p - p a point
line - line a sequence of contiguous line segments defined by their vertices
Returns:
the minimum distance between the point and the line segments
Deprecation:
Use Distance.pointToSegmentString(Coordinate, Coordinate[]) instead.
public static double distanceLineLine(Coordinate A, Coordinate B, Coordinate C, Coordinate D)
Computes the distance from a line segment AB to a line segment CD Note: NON-ROBUST!
Parameters:
A - A a point of one line
B - B the second point of (must be different to A)
C - C one point of the line
D - D another point of the line (must be different to A)
Deprecation:
Use Distance.segmentToSegment(Coordinate, Coordinate, Coordinate, Coordinate) instead.
public static double signedArea(Coordinate[] ring)
Computes the signed area for a ring. The signed area is positive if the ring is oriented CW, negative if the ring is oriented CCW, and zero if the ring is degenerate or flat.
Parameters:
ring - ring the coordinates forming the ring
Returns:
the signed area of the ring
Deprecation:
Use Area.ofRing(Coordinate[]) or Area.ofRingSigned(Coordinate[]) instead.
public static double signedArea(CoordinateSequence ring)
Computes the signed area for a ring. The signed area is:
  • positive if the ring is oriented CW
  • negative if the ring is oriented CCW
  • zero if the ring is degenerate or flat
Parameters:
ring - ring the coordinates forming the ring
Returns:
the signed area of the ring
Deprecation:
Use Area.ofRing(CoordinateSequence) or Area.ofRingSigned(CoordinateSequence) instead.
public static double length(CoordinateSequence pts)
Computes the length of a linestring specified by a sequence of points.
Parameters:
pts - pts the points specifying the linestring
Returns:
the length of the linestring
Deprecation:
Use Length.ofLine(CoordinateSequence) instead.