etomica.math.geometry

Class Polytope

• java.lang.Object
• etomica.math.geometry.Polytope
• All Implemented Interfaces:
Shape, java.io.Serializable
Direct Known Subclasses:
LineSegment, Point, Polygon, Polyhedron

public abstract class Polytope
extends java.lang.Object
implements Shape, java.io.Serializable
Representation of a mathematical polytope, which is a finite region of space enclosed by a finite number of hyperplanes. Subclasses include LineSegment (a 1-D polytope), Polygon (a 2-D polytope), and Polyhedron (a 3-D polytope). Note that the polytope may be embedded in a space of higher dimension than its geometric dimension (e.g., a square -- a 2-D polytope -- by be used in a three-dimensional space. A primary feature of these classes is the set of points representing the vertices of the polytope. These points have the dimension of the embedded space. Subclasses usually have their own internal representation of the polytope that is used to calculate the vertices. It restricts access to this representation to restrict the shape of the polytope (e.g., a square polytope can be modified only by setting the common length of its sides). A polytope can be positioned to any point in space and (to be developed) given a rigid-body rotation.
Serialized Form
• Constructor Summary

Constructors
Modifier Constructor and Description
protected Polytope(Polytope[] hyperPlanes)
Constructs a polytope of dimension D from the D-1 finite "planes" that constitute it.
• Method Summary

All Methods
Modifier and Type Method and Description
protected void applyTranslationRotation()
Calculate transformed vertices from current values of vertices, position, and orientation.
abstract boolean contains(IVector v)
Returns true if the given vector lies inside the polytope, false otherwise.
int D()
The dimension of this polytope, which is not necessarily the dimension of the space it is embedded in.
abstract LineSegment[] getEdges()
ISpace getEmbeddedSpace()
The space defining the vectors used to represent the vertices.
IVector getPosition()
Returns the geometric center of the polytope.
int getVertexCount()
Number of vertices in the polytrope.
IVector[] getVertices()
Returns an array of all vertices of the polytrope.
abstract double getVolume()
Returns the (hyper)volume enclosed by the polytope.
void setPosition(IVector r)
Sets the position of the geometric center of the polytope.
java.lang.String toString()
abstract void updateVertices()
This method should be defined by the subclass to calculate the vertices in accordance with the internal representation of the polytope.
• Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
• Field Detail

• embeddedSpace

protected final ISpace embeddedSpace
• D

protected final int D
• vertices

protected final IVectorMutable[] vertices
These vertices are used in all external representations of the polygon. Changes to them do not necessarily change the state of the polygon.
• hyperPlanes

protected final Polytope[] hyperPlanes
• Constructor Detail

• Polytope

protected Polytope(Polytope[] hyperPlanes)
Constructs a polytope of dimension D from the D-1 finite "planes" that constitute it. Constructor does not find the vertices by calculating plane intersections; instead the given planes should be configured with vertices that form the polytope.
• Method Detail

• updateVertices

public abstract void updateVertices()
This method should be defined by the subclass to calculate the vertices in accordance with the internal representation of the polytope. If the internal representation is kept by the vertices themselves, then this method need do nothing; if this method applies another internal representation to the vertices (for example, it might represent a square by keeping the edge length), it should then invoke applyTranslationRotation() before returning. Subclass methods allowing mutation of the internal representation should invoke updateVertices to ensure the vertices reflect the internal state. Vertices may be changed directly, but these changes will overridden by updateVertices if it is called afterwards.
• applyTranslationRotation

protected void applyTranslationRotation()
Calculate transformed vertices from current values of vertices, position, and orientation. Does not invoke updateVertices before transforming, and so should be called only by subclass and only at the end of the updateVertices method. Otherwise translation and rotation will be performed from current value of vertices, compounding previous application of translation/rotation. NOTE: Rotation is not yet implemented.
• getVertices

public IVector[] getVertices()
Returns an array of all vertices of the polytrope. For most subclasses this array will not provide the direct representation of the polytope. Instead polytope will be defined in another internal representation, which is used to calculate the vertices via the updateVertices method. In a few subclasses the vertices are the representation, so alteration of the returned array will change the polytope.
• setPosition

public void setPosition(IVector r)
Sets the position of the geometric center of the polytope.
Specified by:
setPosition in interface Shape
• getPosition

public IVector getPosition()
Returns the geometric center of the polytope. The returned vector is used to define the position internally, so changes to it will affect the logical position of the polytope, without immediately changing the vertices. Use setPosition to change the polytope position.
• getVolume

public abstract double getVolume()
Returns the (hyper)volume enclosed by the polytope. So for a LineSegment instance, this is its length; for a polygon, it is the area; for a polyhedron, it is the volume.
Specified by:
getVolume in interface Shape
• contains

public abstract boolean contains(IVector v)
Returns true if the given vector lies inside the polytope, false otherwise.
Specified by:
contains in interface Shape
• getVertexCount

public final int getVertexCount()
Number of vertices in the polytrope. A vertex is a point where D edges meet.
• getEmbeddedSpace

public ISpace getEmbeddedSpace()
The space defining the vectors used to represent the vertices.
• D

public int D()
The dimension of this polytope, which is not necessarily the dimension of the space it is embedded in. For example, for a cube D = 3, and for a square D = 2.
Specified by:
D in interface Shape
• getEdges

public abstract LineSegment[] getEdges()
• toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object