math.geom2d.polygon
Class Polygons2D

java.lang.Object
  extended by math.geom2d.polygon.Polygons2D

public final class Polygons2D
extends java.lang.Object

Several utility functions for working on polygons, including polygon creation, and basic computations. I

Author:
dlegland

Constructor Summary
Polygons2D()
           
 
Method Summary
static Polygon2D clipPolygon(Polygon2D polygon, Box2D box)
          Clips a polygon by a box.
static double computeArea(LinearRing2D ring)
          Computes the signed area of the linear ring.
static double computeArea(Polygon2D polygon)
          Computes the signed area of the polygon.
static Point2D computeCentroid(LinearRing2D ring)
          Computes the centroid of the given linear ring.
static Point2D computeCentroid(Polygon2D polygon)
          Computes the centroid of the given polygon.
static CirculinearDomain2D createBuffer(Polygon2D polygon, double dist)
          Computes the buffer at a distance d of the input polygon.
static SimplePolygon2D createCenteredRectangle(Point2D center, double length, double width)
          Creates a new polygon representing a rectangle centered around a point.
static SimplePolygon2D createOrientedRectangle(Point2D center, double length, double width, double theta)
          Creates a new polygon representing an oriented rectangle centered around a point.
static 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.
static 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.
static Polygon2D difference(Polygon2D polygon1, Polygon2D polygon2)
          Computes the Difference of the two polygons.
static Polygon2D exclusiveOr(Polygon2D polygon1, Polygon2D polygon2)
          Computes the exclusive XOR of the two polygons.
static Polygon2D intersection(Polygon2D polygon1, Polygon2D polygon2)
          Computes the intersection of the two polygons.
static Polygon2D union(Polygon2D polygon1, Polygon2D polygon2)
          Computes the union of the two polygons.
static int windingNumber(java.util.Collection<Point2D> vertices, Point2D point)
          Computes the winding number of the polygon.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Polygons2D

public Polygons2D()
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 polygon
point - the reference point
Returns:
the number of windings of the curve around the point

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)

union

public static final Polygon2D union(Polygon2D polygon1,
                                    Polygon2D polygon2)
Computes the union of the two polygons. Uses the GPCJ library, developed by Solution Engineering, Inc.


intersection

public static final Polygon2D intersection(Polygon2D polygon1,
                                           Polygon2D polygon2)
Computes the intersection of the two polygons. Uses the GPCJ library, developed by Solution Engineering, Inc.


exclusiveOr

public static final Polygon2D exclusiveOr(Polygon2D polygon1,
                                          Polygon2D polygon2)
Computes the exclusive XOR of the two polygons. Uses the GPCJ library, developed by Solution Engineering, Inc.


difference

public static final Polygon2D difference(Polygon2D polygon1,
                                         Polygon2D polygon2)
Computes the Difference of the two polygons. Uses the modified GPCJ library, developed by Solution Engineering, Inc.

Since:
0.9.1