Class Matrices.Polygon2D

java.lang.Object
net.algart.arrays.Matrices.Region
net.algart.arrays.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:

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

  • 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 than Matrices.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 of Matrices.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) and Matrices.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 class Matrices.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 method Matrices.Region.contains(long...) in this class works correctly. You should use Matrices.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 class Matrices.Region
      Returns:
      true if Matrices.Region.contains(long...) method works correctly; otherwise Matrices.Region.contains(long...) method throws UnsupportedOperationException.
    • 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 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 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:
      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 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 String toString()
      Returns a brief string description of this object.

      The result of this method may depend on implementation.

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