Class Polygon
Polyline
class. This class provides additional methods such as area calculation, point
inclusion test, and polygons intersection.
A polygon is defined by a sequence of points where the first and last points are equal to ensure closure.
- Author:
- Andrey Malykhanov
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsPoints(List<Point> points) Checks whether all points in the given list are on the boundary of the polygon .booleandoublegetArea()Returns the area of the polygon.Returns the center point of the polygon.getExclusionPolygons(Polygon other) Returns a list of closed polygons without self-intersections each having non-zero area, that fully cover the area of this polygon with the specified other polygon excluded from this one.getIntersectionPolygon(Polygon other) Deprecated.getIntersectionPolygons(Polygon other) Returns a list of closed polygons without self-intersections each having non-zero area, that fully cover the area of intersection of this polygon and the specified other polygon.Returns a list of closed polygons without self-intersections each having non-zero area, that fully cover the area of this polygon.booleanisEquivalent(Polygon other) Checks whether this polygon is equivalent to the other polygon, meaning they contain the same points in the same order but possibly with a different starting point.booleanisOtherPolygonInside(Polygon other) Checks whether the other polygon is completely inside this polygon.booleanisPointInside(Point point) Checks whether a given point is inside the polygon or on its boundary.Methods inherited from class com.amalgamasimulation.geometry.Polyline
add, boundsIntersect, containsPoint, containsPoint, distanceToPoint, getAllIntersectionPoints, getAllIntersectionPoints, getAllIntersectionPoints, getAllIntersectionPoints, getAllIntersections, getAllIntersections, getAllIntersections, getAllIntersections, getClosestPointAbsOffset, getClosestPointTo, getConnectingSegment, getCopy, getEquidistantPolyline, getFirstIntersection, getFirstIntersection, getFirstIntersection, getFirstIntersection, getFirstIntersectionPoint, getFirstIntersectionPoint, getFirstIntersectionPoint, getFirstIntersectionPoint, getFirstPoint, getFirstSegment, getIntersection, getIntersection, getLastPoint, getLastSegment, getLength, getMaxRectPoint, getMinRectPoint, getParallelPolyline, getParallelPolyline, getPointAndSegmentIndexByAbsoluteOffset, getPointAndSegmentIndexByAbsoluteOffset, getPointByAbsoluteOffset, getPointByRelativeOffset, getPoints, getPointsOfSubPolylineByAbsoluteOffsets, getPointsOfSubPolylineByAbsoluteOffsets, getPointsOfSubPolylineByRelativeOffsets, getPolylineWithoutSelfIntersections, getReversed, getRotated, getSegments, getSimplified, getSmoothed, getSmoothed, getSubPolylineByAbsoluteOffsets, getSubPolylineByAbsoluteOffsets, getSubPolylineByRelativeOffsets, hashCode, hasSelfIntersections, intersectsWith, intersectsWith, intersectsWith, intersectsWith, isEmpty, minus, multiply, plus, toCodeString, toString
-
Constructor Details
-
Polygon
Constructs a Polygon from a givenPolyline. Ensures that the polygon is closed by appending the first point if necessary.If the specified polyline has less than 2 points or all its points lie on the same line, a polygon instance with zero area is still created.
- Parameters:
polyline- the polyline used to construct the polygon
-
Polygon
Constructs a Polygon from a given list ofPoints. Ensures that the polygon is closed by appending the first point if necessary.If there are less than 2 points in the specified list, or all its points lie on the same, a polygon instance with zero area is still created.
- Parameters:
points- the list of points used to construct the polygon
-
-
Method Details
-
getArea
public double getArea()Returns the area of the polygon. Area of an empty polygon is considered zero.- Returns:
- the area of the polygon
-
getCenterPoint
Returns the center point of the polygon. -
isPointInside
Checks whether a given point is inside the polygon or on its boundary.A point lying exactly on the polygon's boundary is considered inside.
To check if the point is strictly lying on the polygon's boundary, use
Polyline.containsPoint(Point, boolean)method.- Parameters:
point- the point to be checked- Returns:
trueif the point is inside the polygon or on its boundary,falseotherwise- See Also:
-
getSimplePolygons
Returns a list of closed polygons without self-intersections each having non-zero area, that fully cover the area of this polygon. For empty polygons or polygons with zero area, returns an empty list.If this polygon has a non-zero area and does not have self-intersections or zero-area fragments, returns a list containing single element - a copy of this polygon.
The order of the returned polygons is not guaranteed but is always the same for the same arguments.

- Returns:
- list of closed polygons without self-intersections each having non-zero area
- See Also:
-
getIntersectionPolygons
Returns a list of closed polygons without self-intersections each having non-zero area, that fully cover the area of intersection of this polygon and the specified other polygon.If the two polygons do not intersect, or their intersection has zero area, an empty list is returned.
The order of the returned polygons is not guaranteed but is always the same for the same arguments.

- Parameters:
other- the other polygon to compute the intersection with- Returns:
- list of closed polygons without self-intersections each having non-zero area
- See Also:
-
getExclusionPolygons
Returns a list of closed polygons without self-intersections each having non-zero area, that fully cover the area of this polygon with the specified other polygon excluded from this one.If the specified other polygon does not intersect with this one, the result of this call is identical to the result of
getSimplePolygons()call on this polygon.
- Parameters:
other- the other polygon to be excluded from the this one- Returns:
- list of closed polygons without self-intersections each having non-zero area
- See Also:
-
getIntersectionPolygon
Deprecated.usegetIntersectionPolygons(Polygon)insteadReturns the intersection polygon between this polygon and another. If the two polygons do not intersect or their boundaries just touch each other, an empty polygon is returned. In other words, if the intersection of the two polygons is a polygon with zero area, an empty polygon is returned.- Parameters:
other- the other polygon to compute the intersection with- Returns:
- a new Polygon representing the intersection of the two polygons
- See Also:
-
isEquivalent
Checks whether this polygon is equivalent to the other polygon, meaning they contain the same points in the same order but possibly with a different starting point.Two polygons are considered equivalent if they have the same number of points, are closed (first and last points are the same), and their point sequences can be cyclically shifted to match each other.
Special cases:
- Two empty polygons are considered equivalent.
- Two polygons with a single identical point are considered equivalent.
- Parameters:
other- the polygon to compare with- Returns:
trueif the polygons are equivalent,falseotherwise
-
containsPoints
Checks whether all points in the given list are on the boundary of the polygon .- Parameters:
points- the list of points to check (may be empty, but must not benull)- Returns:
trueif all points in the list are contained on the boundary of the polygon,falseif at least one point is outside or inside or if the input list isnull- See Also:
-
isOtherPolygonInside
Checks whether the other polygon is completely inside this polygon.- Returns:
trueif all points of the other polygon are inside this polygon,falseotherwise
-
equals
-
getIntersectionPolygons(Polygon)instead