com.mizar.geometry
Class Polygon

java.lang.Object
  extended by com.mizar.geometry.Geometry
      extended by com.mizar.geometry.Polyline
          extended by com.mizar.geometry.Polygon
All Implemented Interfaces:
OneCell, TwoCell
Direct Known Subclasses:
OrthoPolygon

public class Polygon
extends Polyline
implements TwoCell


Nested Class Summary
 
Nested classes/interfaces inherited from class com.mizar.geometry.Geometry
Geometry.Results
 
Field Summary
 
Fields inherited from class com.mizar.geometry.Polyline
equiangular, equilateral, orthogonal
 
Fields inherited from class com.mizar.geometry.Geometry
defaultOrdinates, dimensions, geographic, LEFTSIDE, maximumCoordinates, mbr, minimumCoordinates, ONLINE, ordinates, precision, results, RIGHTSIDE, SIDE, toStringDecimals
 
Constructor Summary
Polygon()
           
Polygon(double[] ordinates)
           
Polygon(double[] ordinates, double precision)
           
 
Method Summary
static double[] closeArea(double[] ordinates, double tolerance)
          The method assumes 2D ordinates The method will return a closed polygon.
static double computePolygonArea(double[] x, double[] y)
           
static double[] computePolygonCentroid(double[] x, double[] y)
           
 double getArea()
           
 double getAreaAbsolute()
           
 double[] getCentroid()
          Note that the centroid can fall outside of the polygon
static boolean isPointInsideMBR(double[] mbr, double[] point)
           
 boolean isPointInsidePolygon(double[] point)
          This method may be significantly faster than the static method Polygon.isPointInsidePolygon because it first checks that the point is inside the mean bounding rectangle.
static boolean isPointInsidePolygon(double[] polygonOrdinates, double[] point)
           
static boolean isPointInsidePolygon(double[] mbr, double[] polygonOrdinates, double[] point)
           
static boolean isPointInsidePolygon(double[] x, double[] y, double pointX, double pointY)
          Check if a given point is inside a given (complex) polygon.
static boolean isPointInsidePolygonX(double[] polygonOrdinates, double[] point)
          Inspired by no.geosoft.cc.geometry.Geometry developed by Jacob Dreyer GNU (c) 2004
static void main(java.lang.String[] args)
           
static double polygonArea(double[] xy)
           
static double polygonAreaAbsolute(double[] xy)
           
static double[] polygonCentroid(double[] xy)
          Inspired by no.geosoft.cc.geometry.Geometry developed by Jacob Dreyer GNU (c) 2004
 
Methods inherited from class com.mizar.geometry.Polyline
addCoordinate, addCoordinate, addPoint, breakAtCoordinateIndex, changeDimensionality, clone, conflateTo, contains, contains, contains, getClosestPoint, getClosestSegment, getCoordinateOnLine, getDistanceTo, getDistanceTo, getEndPoint, getEndPointXY, getLength, getLength3D, getLine, getLine, getLineOrdinates, getOrdinatesBetween, getPointAsCrowFlies, getPointAsCrowFlies, getPointAtDistance, getPointAtDistance, getRemainingOrdinates, getSegmentAtDistance, getSegmentAtDistance, getSegments, getSelfIntersections, getShortestDistance, getStartPoint, getStartPointXY, getWkt, hasIntersections, hasNonconnectingIntersections, intersect, intersect, isEquiangular, isEquilateral, isOrthogonal, isPointOnLine, isSame, isSelfIntersecting, join, length, length, lengthAlong, lengthAlong, lengthBetween, lengthBetween, patch, patch, removeCoordinate, reverse, reverse, setEquiangular, setEquilateral, setOrthogonal, shiftParallel, shiftParallel, shiftParallel, shiftParallel, snap, snap, snap, snap, split, split, thin, thin, thin, thinSimple, thinSimple
 
Methods inherited from class com.mizar.geometry.Geometry
adjustEndPoints, adjustEndPoints, adjustEndPoints, adjustEndPoints, changeDimensions, computeMbr, computeMbr, computeMbr, computeNearestDistance, computeNearestDistance, connectsTo, connectsTo, connectsTo, connectsTo, constructDefaultPoint, equals, expandMbr, getCoordinate, getCoordinates, getCoordinates, getCoordinates, getCoordinates, getDefaultOrdinates, getDimensions, getEndCoordinateIndex, getFirstPoint, getFirstPoint, getLastPoint, getLastPoint, getLeastDimension, getLeastPrecise, getLength, getMaximumCoordinates, getMbr, getMbrCorner, getMbrCorner, getMinimumCoordinates, getMostPrecise, getNumberOfCoordiates, getOrdinates, getPoints, getPointWithMatchingDimensions, getPrecision, getRange, getRange, getResults, getSegment, getToStringDecimals, getXYCoordinates, getXYCoordinates, hashCode, isCoveredByMbr, isEqualOrBetween, isGeographic, isInsideMbr, isSame, mbrIntersect, mbrOverlap, mbrOverlap, mbrOverlapRatio, mbrValid, polygonizeMbr, quadrant, seedMbr, setCoordinate, setCoordinates, setCoordinates, setDefaultOrdinates, setDimensions, setFirstPoint, setGeographic, setLastPoint, setMaximumCoordinates, setMinimumCoordinates, setOrdinates, setPrecision, setSegment, setToStringDecimals, toString, updateMbr
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.mizar.geometry.TwoCell
getDimensions
 
Methods inherited from interface com.mizar.geometry.OneCell
getDimensions, getFirstPoint, getLastPoint, setFirstPoint, setLastPoint
 

Constructor Detail

Polygon

public Polygon()

Polygon

public Polygon(double[] ordinates)
        throws GeometryException
Throws:
GeometryException

Polygon

public Polygon(double[] ordinates,
               double precision)
        throws GeometryException
Parameters:
ordinates - an array of ordinates assumed to close (i.e. the first coordinate should be the same as the last coordinate)
precision -
Throws:
GeometryException
Method Detail

getArea

public double getArea()
               throws GeometryException
Specified by:
getArea in interface TwoCell
Returns:
Throws:
GeometryException

getAreaAbsolute

public double getAreaAbsolute()
                       throws GeometryException
Returns:
Throws:
GeometryException

closeArea

public static double[] closeArea(double[] ordinates,
                                 double tolerance)
The method assumes 2D ordinates The method will return a closed polygon. If the beginning and ending 2D coordinates are within tolerance the method will force the endpoints to be identical. If the beginning and ending 2D coordinates are not within tolerance the method will add the beginning point as a new end point.

Parameters:
ordinates -
tolerance -
Returns:
ordinates of a closed polygon

polygonArea

public static double polygonArea(double[] xy)

polygonAreaAbsolute

public static double polygonAreaAbsolute(double[] xy)
Parameters:
xy - the first and last coordinates must match
Returns:
the area of the polygon described by xy

main

public static void main(java.lang.String[] args)

computePolygonCentroid

public static double[] computePolygonCentroid(double[] x,
                                              double[] y)

computePolygonArea

public static double computePolygonArea(double[] x,
                                        double[] y)

polygonCentroid

public static double[] polygonCentroid(double[] xy)
Inspired by no.geosoft.cc.geometry.Geometry developed by Jacob Dreyer GNU (c) 2004

Parameters:
xy -
Returns:

getCentroid

public double[] getCentroid()
                     throws GeometryException
Note that the centroid can fall outside of the polygon

Specified by:
getCentroid in interface TwoCell
Returns:
the centroid of the polygon
Throws:
GeometryException
See Also:
isPointInsidePolygon(double[])

isPointInsidePolygon

public boolean isPointInsidePolygon(double[] point)
                             throws GeometryException
This method may be significantly faster than the static method Polygon.isPointInsidePolygon because it first checks that the point is inside the mean bounding rectangle.

Parameters:
point -
Returns:
true if point is inside the polygon
Throws:
GeometryException

isPointInsidePolygonX

public static boolean isPointInsidePolygonX(double[] polygonOrdinates,
                                            double[] point)
Inspired by no.geosoft.cc.geometry.Geometry developed by Jacob Dreyer GNU (c) 2004

Parameters:
polygonOrdinates - a double[] describing a closed polygon. The first pair of ordinates must match the last pair of ordinates
point - a double[2] array describing a point
Returns:
See Also:
isPointInsidePolygon(double[])

isPointInsideMBR

public static boolean isPointInsideMBR(double[] mbr,
                                       double[] point)

isPointInsidePolygon

public static boolean isPointInsidePolygon(double[] mbr,
                                           double[] polygonOrdinates,
                                           double[] point)

isPointInsidePolygon

public static boolean isPointInsidePolygon(double[] polygonOrdinates,
                                           double[] point)

isPointInsidePolygon

public static boolean isPointInsidePolygon(double[] x,
                                           double[] y,
                                           double pointX,
                                           double pointY)
Check if a given point is inside a given (complex) polygon.

Parameters:
x, - y Polygon.
pointX, - pointY Point to check.
Returns:
True if the given point is inside the polygon, false otherwise.