AlgART Home
net.algart.arrays

## Class Matrices.Polygon2D

• Enclosing class:
Matrices

```public static final class Matrices.Polygon2D
extends Matrices.Region```

Random 2-dimensional polygon. It can be non-convex and even self-intersecting.

The points, lying precisely in the sides of the polygon (in particular, the vertices), belong to this region.

Any degenerated cases are allowed: for example, vertices can be equal.

Polygon is specified by its vertices and can be created by the following method:

All calculations while building and processing polygons are performed in strictfp mode, so the results are absolutely identical on all platforms.

This class is immutable and thread-safe: there are no ways to modify settings of the created instance.

• ### Method Summary

All Methods
Modifier and Type Method and Description
`boolean` `contains(long... coordinates)`
Returns true if and only if the point with the specified integer coordinates belongs to this region.
`boolean` `isContainsSupported()`
Indicates whether the method `Matrices.Region.contains(long...)` in this class works correctly.
`Matrices.Region[]` `sectionAtLastCoordinate(long sectionY)`
Finds the intersection of this region with the hyperplane, described by the equation x`n`−1=sectionCoordinateValue, and returns this intersection as an array of (n−1)-dimensional regions.
`java.lang.String` `toString()`
Returns a brief string description of this object.
`double` `vertexX(int index)`
Returns the x-coordinate of the vertix #index.
`double` `vertexY(int index)`
Returns the y-coordinate of the vertix #index.
`double[][]` `vertices()`
Returns the coordinates of all vertices of the polygon.
`int` `verticesCount()`
Returns the number of vertices of the polygon.
• ### Methods inherited from class net.algart.arrays.Matrices.Region

`checkSectionAtLastCoordinate, coordRange, coordRanges, getConvexHyperpolyhedron, getHyperparallelepiped, getParallelepiped3D, getPolygon2D, getRectangle2D, getSegment, getSimplex, getTetrahedron3D, getTriangle2D, isRectangular, n`
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Method Detail

• #### sectionAtLastCoordinate

`public Matrices.Region[] sectionAtLastCoordinate(long sectionY)`
Description copied from class: `Matrices.Region`
Finds the intersection of this region with the hyperplane, described by the equation x`n`−1=sectionCoordinateValue, and returns this intersection as an array of (n−1)-dimensional regions. (Here x`n`−1 is the last coordinate of the points: y-coordinate in 2-dimensional case, z-coordinate in 3-dimensional case, etc.) If the intersection is empty, this method returns an empty array ("new Region[0]"). This method never returns null.

This method must not be used if this region is 1-dimensional (`Matrices.Region.n()`==1). In this case, it throws IllegalStateException.

This default implementation is based on `Matrices.Region.contains(long...)` method, which is supposed to be correctly implemented.

Note: it is possible (in some rare exotic cases), that the regions, returned by this method, intersects with each other: some points will belong to 2 and more elements of the result. In particular, it is possible for `Matrices.Polygon2D`, if some sides of the polygon lie exactly at the horizontal y=sectionCoordinateValue.

Implementations of this method in this packages, besides the implementation in `Matrices.Polygon2D` class, never return more than 1 region in the result.

You must override this method if you prefer not to implement `Matrices.Region.contains(long...)` method (`Matrices.Region.isContainsSupported()` returns false). In this case, your implementation must not call `Matrices.Region.contains(long...)` method or super.`Matrices.Region.sectionAtLastCoordinate(long)`.

Overrides:
`sectionAtLastCoordinate` in class `Matrices.Region`
Parameters:
`sectionY` - the value of the last coordinate.
Returns:
the intersection of this region and the (n−1)-dimensional hyperplane, corresponding to the specified value of the last coordinate (0, 1 or more regions, every region is (n−1)-dimensional).
• #### verticesCount

`public int verticesCount()`
Returns the number of vertices of the polygon. It is the number of elements in the array, returned by `vertices()` method.
Returns:
the number of vertices of the polygon.
• #### vertexX

`public double vertexX(int index)`
Returns the x-coordinate of the vertix #index.
Parameters:
`index` - the index of vertex.
Returns:
the x-coordinate of the vertix #index.
Throws:
`java.lang.IndexOutOfBoundsException` - if index<0 or index≥`verticesCount()`.
• #### vertexY

`public double vertexY(int index)`
Returns the y-coordinate of the vertix #index.
Parameters:
`index` - the index of vertex.
Returns:
the y-coordinate of the vertix #index.
Throws:
`java.lang.IndexOutOfBoundsException` - if index<0 or index≥`verticesCount()`.
• #### vertices

`public double[][] vertices()`
Returns the coordinates of all vertices of the polygon. The returned arrays is identical to an array, passed to `Matrices.Region.getPolygon2D(double[][] vertices)` method.

The returned array is a deep clone of the internal array stored in this object: no references, maintained by this object, are returned.

Returns:
the coordinates of all vertices of the simplex: the element (line) #k of the returned 2-dimensional array contains 2 coordinates of the vertex #k.
• #### toString

`public java.lang.String toString()`
Returns a brief string description of this object.

The result of this method may depend on implementation.

Overrides:
`toString` in class `java.lang.Object`
Returns:
a brief string description of this object.