org.apache.commons.math3.geometry.euclidean.twod
Class PolygonsSet

java.lang.Object
  extended by org.apache.commons.math3.geometry.partitioning.AbstractRegion<Euclidean2D,Euclidean1D>
      extended by org.apache.commons.math3.geometry.euclidean.twod.PolygonsSet
All Implemented Interfaces:
Region<Euclidean2D>

public class PolygonsSet
extends AbstractRegion<Euclidean2D,Euclidean1D>

This class represents a 2D region: a set of polygons.

Since:
3.0
Version:
$Id: PolygonsSet.java 15941 2016-04-20 14:02:40Z galpin $

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.commons.math3.geometry.partitioning.Region
Region.Location
 
Field Summary
static int MIN_POINT_NB
          Minimum number of points to build a polygon.
 
Constructor Summary
PolygonsSet()
          Build a polygons set representing the whole real line.
PolygonsSet(BSPTree<Euclidean2D> tree)
          Build a polygons set from a BSP tree.
PolygonsSet(Collection<SubHyperplane<Euclidean2D>> boundary)
          Build a polygons set from a Boundary REPresentation (B-rep).
PolygonsSet(double xMin, double xMax, double yMin, double yMax)
          Build a parallellepipedic box.
PolygonsSet(double hyperplaneThickness, Vector2D... vertices)
          Build a polygon from a simple list of vertices.
PolygonsSet(Vector2D[][] vertices)
          Build a polygons set from a two dimensional array of vertices.
 
Method Summary
 PolygonsSet buildNew(BSPTree<Euclidean2D> tree)
          Build a region using the instance as a prototype.
 boolean checkPolygonSet()
          Method to check PolygonSet based on three criteria (three checks) : Classification of polygons must not be CROSSING_BORDERS or DEGENERATED Size of polygon must be different from Double.POSITIVE_INFINITY (open-loop polygon) Remarks : If both criteria are satisfied, polygon will have at least three points If constructor PolygonsSet(Vector2D[][]) is used, second exception cannot be reached (vertices are automatically sorted in TRIGO sense, which prevent crossing borders) If constructor PolygonsSet(Vector2D[][]) is used, third exception cannot be reached (the first will be reached before)
protected  void computeGeometricalProperties()
          Compute some geometrical properties.
 double getBiggerLength()
          Get the polygon's bigger length, i.e.
 EnumPolygon getClassification()
           
 double getMaxX()
           
 double getMaxY()
           
 double getMinX()
           
 double getMinY()
           
 Vector2D[][] getVertices()
          Get the vertices of the polygon.
static Vector2D[][] sortVerticies(Vector2D[][] v, boolean trigo)
          Method to sort vertices according to a specific sense : (trigonometric or clockwise)
 
Methods inherited from class org.apache.commons.math3.geometry.partitioning.AbstractRegion
applyTransform, checkPoint, checkPoint, contains, copySelf, getBarycenter, getBoundarySize, getSize, getTree, intersection, isEmpty, isEmpty, setBarycenter, setSize, side
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_POINT_NB

public static final int MIN_POINT_NB
Minimum number of points to build a polygon.

See Also:
Constant Field Values
Constructor Detail

PolygonsSet

public PolygonsSet()
Build a polygons set representing the whole real line.


PolygonsSet

public PolygonsSet(BSPTree<Euclidean2D> tree)
Build a polygons set from a BSP tree.

The leaf nodes of the BSP tree must have a Boolean attribute representing the inside status of the corresponding cell (true for inside cells, false for outside cells). In order to avoid building too many small objects, it is recommended to use the predefined constants Boolean.TRUE and Boolean.FALSE

Parameters:
tree - inside/outside BSP tree representing the region

PolygonsSet

public PolygonsSet(Collection<SubHyperplane<Euclidean2D>> boundary)
Build a polygons set from a Boundary REPresentation (B-rep).

The boundary is provided as a collection of sub-hyperplanes. Each sub-hyperplane has the interior part of the region on its minus side and the exterior on its plus side.

The boundary elements can be in any order, and can form several non-connected sets (like for example polygons with holes or a set of disjoint polyhedrons considered as a whole). In fact, the elements do not even need to be connected together (their topological connections are not used here). However, if the boundary does not really separate an inside open from an outside open (open having here its topological meaning), then subsequent calls to the checkPoint method will not be meaningful anymore.

If the boundary is empty, the region will represent the whole space.

Parameters:
boundary - collection of boundary elements, as a collection of SubHyperplane objects

PolygonsSet

public PolygonsSet(double xMin,
                   double xMax,
                   double yMin,
                   double yMax)
Build a parallellepipedic box.

Parameters:
xMin - low bound along the x direction
xMax - high bound along the x direction
yMin - low bound along the y direction
yMax - high bound along the y direction

PolygonsSet

public PolygonsSet(double hyperplaneThickness,
                   Vector2D... vertices)
Build a polygon from a simple list of vertices.

The boundary is provided as a list of points considering to represent the vertices of a simple loop. The interior part of the region is on the left side of this path and the exterior is on its right side.

This constructor does not handle polygons with a boundary forming several disconnected paths (such as polygons with holes).

For cases where this simple constructor applies, it is expected to be numerically more robust than the general constructor using subhyperplanes.

If the list is empty, the region will represent the whole space.

Polygons with thin pikes or dents are inherently difficult to handle because they involve lines with almost opposite directions at some vertices. Polygons whose vertices come from some physical measurement with noise are also difficult because an edge that should be straight may be broken in lots of different pieces with almost equal directions. In both cases, computing the lines intersections is not numerically robust due to the almost 0 or almost π angle. Such cases need to carefully adjust the hyperplaneThickness parameter. A too small value would often lead to completely wrong polygons with large area wrongly identified as inside or outside. Large values are often much safer. As a rule of thumb, a value slightly below the size of the most accurate detail needed is a good value for the hyperplaneThickness parameter.

Parameters:
hyperplaneThickness - tolerance below which points are considered to belong to the hyperplane (which is therefore more a slab)
vertices - vertices of the simple loop boundary
Since:
3.1

PolygonsSet

public PolygonsSet(Vector2D[][] vertices)
Build a polygons set from a two dimensional array of vertices.

Vertices are firstly sorted in trigonometric sense so that :

After sorting, super constructor AbstractRegion is called with a list of edges. NB : the method buildSet(Vector2D[][]) insure that consecutive duplicated points are removed

Parameters:
vertices - array of vertices
Since:
3.2
Method Detail

buildNew

public PolygonsSet buildNew(BSPTree<Euclidean2D> tree)
Build a region using the instance as a prototype.

This method allow to create new instances without knowing exactly the type of the region. It is an application of the prototype design pattern.

The leaf nodes of the BSP tree must have a Boolean attribute representing the inside status of the corresponding cell (true for inside cells, false for outside cells). In order to avoid building too many small objects, it is recommended to use the predefined constants Boolean.TRUE and Boolean.FALSE. The tree also must have either null internal nodes or internal nodes representing the boundary as specified in the getTree method).

Specified by:
buildNew in interface Region<Euclidean2D>
Specified by:
buildNew in class AbstractRegion<Euclidean2D,Euclidean1D>
Parameters:
tree - inside/outside BSP tree representing the new region
Returns:
the built region

computeGeometricalProperties

protected void computeGeometricalProperties()
Compute some geometrical properties.

The properties to compute are the barycenter and the size.

Specified by:
computeGeometricalProperties in class AbstractRegion<Euclidean2D,Euclidean1D>

getVertices

public Vector2D[][] getVertices()
Get the vertices of the polygon.

The polygon boundary can be represented as an array of loops, each loop being itself an array of vertices.

In order to identify open loops which start and end by infinite edges, the open loops arrays start with a null point. In this case, the first non null point and the last point of the array do not represent real vertices, they are dummy points intended only to get the direction of the first and last edge. An open loop consisting of a single infinite line will therefore be represented by a three elements array with one null point followed by two dummy points. The open loops are always the first ones in the loops array.

If the polygon has no boundary at all, a zero length loop array will be returned.

All line segments in the various loops have the inside of the region on their left side and the outside on their right side when moving in the underlying line direction. This means that closed loops surrounding finite areas obey the direct trigonometric orientation.

Returns:
vertices of the polygon, organized as oriented boundary loops with the open loops first (the returned value is guaranteed to be non-null)

checkPolygonSet

public boolean checkPolygonSet()
Method to check PolygonSet based on three criteria (three checks) : Remarks :

Returns:
true if previous criteria are satisfied

sortVerticies

public static Vector2D[][] sortVerticies(Vector2D[][] v,
                                         boolean trigo)
Method to sort vertices according to a specific sense : (trigonometric or clockwise)

Parameters:
v - array of vertices
trigo - true if trigonometric sense
Returns:
the sorted polygons

getMinX

public double getMinX()
Returns:
the minX

getMinY

public double getMinY()
Returns:
the minY

getMaxX

public double getMaxX()
Returns:
the maxX

getMaxY

public double getMaxY()
Returns:
the maxY

getClassification

public EnumPolygon getClassification()
Returns:
the classification

getBiggerLength

public double getBiggerLength()
Get the polygon's bigger length, i.e. the largest size among its points.

Returns:
the polygon's bigger length


Copyright © 2017 CNES. All Rights Reserved.