math.geom2d.polygon
Class Polygons2D
- java.lang.Object
-
- math.geom2d.polygon.Polygons2D
-
public final class Polygons2D extends java.lang.ObjectSeveral utility functions for working on polygons, including polygon creation, and basic computations such as polygon area or centroid.
-
-
Constructor Summary
Constructors Constructor and Description Polygons2D()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static Polygon2DclipPolygon(Polygon2D polygon, Box2D box)Clips a polygon by a box.static doublecomputeArea(LinearRing2D ring)Computes the signed area of the linear ring.static doublecomputeArea(Polygon2D polygon)Computes the signed area of the polygon.static Point2DcomputeCentroid(LinearRing2D ring)Computes the centroid of the given linear ring.static Point2DcomputeCentroid(Polygon2D polygon)Computes the centroid of the given polygon.static Polygon2DconvexHull(java.util.Collection<? extends Point2D> points)Returns the convex hull of the given set of points.static CirculinearDomain2DcreateBuffer(Polygon2D polygon, double dist)Computes the buffer at a distance d of the input polygon.static SimplePolygon2DcreateCenteredRectangle(Point2D center, double length, double width)Creates a new polygon representing a rectangle centered around a point.static SimplePolygon2DcreateOrientedRectangle(Point2D center, double length, double width, double theta)Creates a new polygon representing an oriented rectangle centered around a point.static SimplePolygon2DcreateRectangle(double x1, double y1, double x2, double y2)Creates a new polygon representing a rectangle with edges parallel to the main directions, and having the two specified opposite corners.static SimplePolygon2DcreateRectangle(Point2D p1, Point2D p2)Creates a new polygon representing a rectangle with edges parallel to the main directions, and having the two specified opposite corners.static intwindingNumber(java.util.Collection<Point2D> vertices, Point2D point)Computes the winding number of the polygon.
-
-
-
Method Detail
-
createRectangle
public static final SimplePolygon2D createRectangle(Point2D p1, Point2D p2)
Creates a new polygon representing a rectangle with edges parallel to the main directions, and having the two specified opposite corners.- Since:
- 0.10.3
-
createRectangle
public static final SimplePolygon2D createRectangle(double x1, double y1, double x2, double y2)
Creates a new polygon representing a rectangle with edges parallel to the main directions, and having the two specified opposite corners.- Since:
- 0.10.3
-
createCenteredRectangle
public static final SimplePolygon2D createCenteredRectangle(Point2D center, double length, double width)
Creates a new polygon representing a rectangle centered around a point. Rectangle sides are parallel to the main axes. The function returns an instance of SimplePolygon2D.- Since:
- 0.9.1
-
createOrientedRectangle
public static final SimplePolygon2D createOrientedRectangle(Point2D center, double length, double width, double theta)
Creates a new polygon representing an oriented rectangle centered around a point. The function returns an instance of SimplePolygon2D.- Since:
- 0.9.1
-
computeCentroid
public static final Point2D computeCentroid(Polygon2D polygon)
Computes the centroid of the given polygon.- Since:
- 0.9.1
-
computeCentroid
public static final Point2D computeCentroid(LinearRing2D ring)
Computes the centroid of the given linear ring.- Since:
- 0.9.1
-
computeArea
public static final double computeArea(Polygon2D polygon)
Computes the signed area of the polygon. Algorithm is taken from page: http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/. Signed area is positive if polygon is oriented counter-clockwise, and negative otherwise. Result is wrong if polygon is self-intersecting.- Returns:
- the signed area of the polygon.
- Since:
- 0.9.1
-
computeArea
public static final double computeArea(LinearRing2D ring)
Computes the signed area of the linear ring. Algorithm is taken from page: http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/. Signed area is positive if linear ring is oriented counter-clockwise, and negative otherwise. Result is wrong if linear ring is self-intersecting.- Returns:
- the signed area of the polygon.
- Since:
- 0.9.1
-
windingNumber
public static final int windingNumber(java.util.Collection<Point2D> vertices, Point2D point)
Computes the winding number of the polygon. Algorithm adapted from http://www.geometryalgorithms.com/Archive/algorithm_0103/algorithm_0103.htm http://softsurfer.com/Archive/algorithm_0103/algorithm_0103.htm- Parameters:
vertices- the vertices of a polygonpoint- the reference point- Returns:
- the number of windings of the curve around the point
-
convexHull
public static final Polygon2D convexHull(java.util.Collection<? extends Point2D> points)
Returns the convex hull of the given set of points. Uses the Jarvis March algorithm.- Parameters:
points- a collection of points- Returns:
- the convex hull of the set of points
-
createBuffer
public static final CirculinearDomain2D createBuffer(Polygon2D polygon, double dist)
Computes the buffer at a distance d of the input polygon. The result is a domain whose boundary is composed of line segments and circle arcs.- See Also:
CirculinearShape2D.buffer(double)
-
clipPolygon
public static final Polygon2D clipPolygon(Polygon2D polygon, Box2D box)
Clips a polygon by a box. The result is a new polygon, that can be multiple.- See Also:
Polygon2D.clip(Box2D)
-
-
DMelt 3.0 © DataMelt by jWork.ORG