Class Matrices.ConvexHyperpolyhedron
- Direct Known Subclasses:
Matrices.Simplex
- Enclosing class:
Matrices
Convex hyperpolyhedron: an intersection of several hyperparallelepiped
.
While creating regions of this class, it is always necessary to specify some containing
hyperparallelepiped. The coordinate ranges, returned by Matrices.Region.coordRanges()
method of this class,
are the corresponding ranges of the specified containing hyperparallelepiped.
More precisely, the region, specified by this class, consists of all such points
a00x0 + a01x1 + ... + a0,n−1xn−1 ≤ b0,
a10x0 + a11x1 + ... + a1,n−1xn−1 ≤ b1,
...,
am−1,0x0 + am−1,1x1 + ... + am−1,n−1xn−1 ≤ bm−1,
and also this point belongs to the specified containinghyperparallelepiped
:
coordRange
(k).min()
≤ xk ≤coordRange
(k).max()
for all k=0,1,...,n−1.
The number of inequations m can be any non-negative integer 0,1,2,... (the degenerated case m=0 is equivalent to the hyperparallelepiped).
Convex hyperpolyhedrons can be created by the following methods:
Matrices.Region.getConvexHyperpolyhedron(double[] a, double[] b, IRange...coordRanges)
,Matrices.Region.getSimplex(double[][] vertices)
,Matrices.Region.getTriangle2D(double x1, double y1, double x2, double y2, double x3, double y3)
,Matrices.Region.getTetrahedron3D(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, double x4, double y4, double z4)
.
In first method, you must directly specify the matrix A of coefficients aij,
the vector b of coefficients bi and the containing hyperparallelepiped.
(The containing hyperparallelepiped will be identical to the hyperparallelepiped, constructed
by Matrices.Region.getHyperparallelepiped(IRange...coordRanges)
method with the same coordRanges.)
Other 3 methods build a simplex
— a particular case of the convex hyperpolyhedron.
In these cases you need to specify its vertices only; necessary matrix A and vector b
are calculated automatically.
This class is immutable and thread-safe: there are no ways to modify settings of the created instance.
-
Method Summary
Modifier and TypeMethodDescriptiondouble[]
a()
Returns the matrix A: coefficients of the left side of inequations, defining the half-spaces (see thecomments to this class
).double[]
b()
Returns the vector b: right sides of inequations, defining the half-spaces (see thecomments to this class
).boolean
contains
(long... coordinates) Returns true if and only if the point with the specified integer coordinates belongs to this region.sectionAtLastCoordinate
(long sectionCoordinateValue) 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.Methods inherited from class net.algart.arrays.Matrices.Region
checkSectionAtLastCoordinate, coordRange, coordRanges, getConvexHyperpolyhedron, getHyperparallelepiped, getParallelepiped3D, getPolygon2D, getRectangle2D, getSegment, getSimplex, getTetrahedron3D, getTriangle2D, isContainsSupported, 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.
-
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:
sectionCoordinateValue
- 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 ).
-
toString
Returns a brief string description of this object.The result of this method may depend on implementation.
-
a
public double[] a()Returns the matrix A: coefficients of the left side of inequations, defining the half-spaces (see thecomments to this class
). The elements of the matrix A will be listed in the returned array row by row: aij=a[i*n+j], i is the index of the row (0..m-1), j is the index of the column (0..n-1), a is the result of this method with length a.length=nm.The returned array is a clone of the internal array stored in this object.
- Returns:
- the matrix A: coefficients of the left side of inequations, defining the half-spaces.
-
b
public double[] b()Returns the vector b: right sides of inequations, defining the half-spaces (see thecomments to this class
). The elements of the vector b will be listed in the returned array. The length of the returned array is the number of half-spaces.The returned array is a clone of the internal array stored in this object.
- Returns:
- the vector b: right sides of inequations, defining the half-spaces.
-