Class Matrices.Polygon2D
- Enclosing class:
Matrices
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:
This class is immutable and thread-safe: there are no ways to modify settings of the created instance.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
contains
(long... coordinates) Returns true if and only if the point with the specified integer coordinates belongs to this region.boolean
Indicates whether the methodMatrices.Region.contains(long...)
in this class works correctly.sectionAtLastCoordinate
(long sectionY) Finds the intersection of this region with the hyperplane, described by the equation xn
−1=sectionCoordinateValue, and returns this intersection as an array of(n−1)-dimensional regions.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
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
-
Method Details
-
contains
public boolean contains(long... coordinates) Description copied from class:Matrices.Region
Returns true if and only if the point with the specified integer coordinates belongs to this region.The coordinates must contain at least
Matrices.Region.n()
elements. It can contain more thanMatrices.Region.n()
elements; then the extra elements will be ignored.Warning! Some inheritors of this class does not provide correct implementation of this method. In this case,
Matrices.Region.isContainsSupported()
method returns false and this method throws UnsupportedOperationException. So, you must always check the result ofMatrices.Region.isContainsSupported()
method before calling this one.However, this method must be correctly implemented, if this region is a
1-dimensional (Matrices.Region.n()
==1) andMatrices.Region.isRectangular()
method returns false.Note: even if the inheritor does not provide correct implementation of this method, it must always provide correct implementation of
Matrices.Region.sectionAtLastCoordinate(long)
method.- Specified by:
contains
in classMatrices.Region
- Parameters:
coordinates
- the coordinates of the point: the first element is x, the second is y, ...- Returns:
- true if and only if the point with the specified coordinates belongs to this region.
-
isContainsSupported
public boolean isContainsSupported()Description copied from class:Matrices.Region
Indicates whether the methodMatrices.Region.contains(long...)
in this class works correctly. You should useMatrices.Region.contains(long...)
method only if this method returns true; in other case,Matrices.Region.contains(long...)
throws UnsupportedOperationException.This default implementation returns true. So, if you prefer not to implement
Matrices.Region.contains(long...)
method, you must override this method and return false. This method must return true if .Matrices.Region.n()
==1 && !Matrices.Region.isRectangular()
- Overrides:
isContainsSupported
in classMatrices.Region
- Returns:
- true if
Matrices.Region.contains(long...)
method works correctly; otherwiseMatrices.Region.contains(long...)
method throws UnsupportedOperationException.
-
sectionAtLastCoordinate
Description copied from class:Matrices.Region
Finds the intersection of this region with the hyperplane, described by the equation xn
−1=sectionCoordinateValue, and returns this intersection as an array of(n−1)-dimensional regions. (Here xn
−1 is the last coordinate of the points:y-coordinate in2-dimensional case,z-coordinate in3-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 callMatrices.Region.contains(long...)
method orsuper. .Matrices.Region.sectionAtLastCoordinate(long)
- Overrides:
sectionAtLastCoordinate
in classMatrices.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 byvertices()
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:
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:
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 toMatrices.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
Returns a brief string description of this object.The result of this method may depend on implementation.
-