Polyhedron3D
Canonical path: NemAll_Python_Geometry.Polyhedron3D
Representation class for 3D polyhedron.
Polyhedron3D represents a 3D solid defined by vertices, edges and faces. Polyhedron includes table of vertices, table of edges and table of faces. Each table is zero based indexed. Edge is defined via GeometryEdge as two indices into vertices table. Geometry edge is default oriented from start to end index. Face is defined via PolyhedronFace as a vector of oriented edges. Oriented edge (OrientedEdge) has EdgeHandle and orientation flag. EdgeHandle is index into polyhedron table of all edges, it mean that values of EdgeHandle can be from range [0..EdgesCount-1]. This handle can be increased and decreased in standard way. When orientation flag is true, then orientation is same as GeometryEdge (from Start to End index), if flag is false then orientation is backward (from End to Start index).
RefPoint
property
writable
RefPoint: Point3D
Get the reference point
Be aware: All vertices will be recalculated on new reference point. This operation is very slow in case of many vertices. Use constructor for better and faster initialization object.
Type
property
writable
Type: PolyhedronType
AppendEdge
AppendEdge(edge: GeometryEdge) -> eGeometryErrorCode
Append edge
Method throw exception if object is not initialized. Old interface: appendPolyederEdge
Parameters:
-
edge
(GeometryEdge
) –Appended edge.
Returns:
-
eGeometryErrorCode
–Error code.
Clear
overloaded
Clear all vertices, edges and faces
Type and vertices,edges,faces preallocation size of polyhedron will be preserved
Clear all vertices, edges and faces
The "Count" parameters have sense only for appropriate polyhedron type and specified a memory allocation size - performance optimization. In case of any error, constructor throw an exception.
Parameters:
-
verticesCount
(int
) –Count of expected vertices.
-
edgesCount
(int
) –Count of expected edges.
-
facesCount
(int
) –Count of expected faces.
-
negativeOrientation
(bool
) –True for negative orientation.
CreateCuboid
overloaded
CreateCuboid(p1: Point3D, p2: Point3D) -> Polyhedron3D
Construct a cuboid from lower left and upper right point
Parameters:
Returns:
-
Polyhedron3D
–polyhedron with a cuboid geometry
Examples:
CreateCuboid(box: MinMax3D) -> Polyhedron3D
Construct a cuboid from a MinMax object
Parameters:
-
box
(MinMax3D
) –min/max box that states the cuboid's size
Returns:
-
Polyhedron3D
–polyhedron with a cuboid geometry
Examples:
CreateCuboid(
placement: AxisPlacement3D, length: float, width: float, height: float
) -> Polyhedron3D
Construct a cuboid from an axis placement and dimensions - length, width and height
Parameters:
-
placement
(AxisPlacement3D
) –cuboid origin
-
length
(float
) –length in its x axis
-
width
(float
) –width in its y axis
-
height
(float
) –height in its z axis
Returns:
-
Polyhedron3D
–polyhedron with a cuboid geometry
Examples:
CreateCuboid(length: float, width: float, height: float) -> Polyhedron3D
Construct a cuboid from length, width and height.
The reference point is set to origin.
Parameters:
-
length
(float
) –Length
-
width
(float
) –Width
-
height
(float
) –Height
Returns:
-
Polyhedron3D
–polyhedron with a cuboid geometry
Examples:
CreateFace
CreateFace(expectedEdges: int) -> PolyhedronFace
Create face and append it to polyhedron
Method throw exception if object is not initialized. Old interface: appendPolyederFace
Parameters:
-
expectedEdges
(int
) –Appended face.
Returns:
-
PolyhedronFace
–Created face.
DeleteEdge
DeleteEdge(edgeHandle: int) -> eGeometryErrorCode
Delete edge
Method throw exception if object is not initialized. Old interface: deletePolyederEdge
Parameters:
-
edgeHandle
(int
) –Edge to delete
Returns:
-
eGeometryErrorCode
–Error code.
DeleteFace
DeleteFace(faceIndex: int) -> eGeometryErrorCode
Delete face at specified position
Method throw exception in case of any error. Old interface: deleteFace
Parameters:
-
faceIndex
(int
) –Position of the deleted face. Zero based.
Returns:
-
eGeometryErrorCode
–Error code.
DeleteFaces
DeleteFaces(faceIndices: VecSizeTList) -> eGeometryErrorCode
Delete faces at specified positions
Method throw exception in case of any error. Old interface: deleteFace
Parameters:
-
faceIndices
(VecSizeTList
) –Positions of the deleted faces. Zero based.
Returns:
-
eGeometryErrorCode
–Error code.
EqualRef
EqualRef(polyhedron: Polyhedron3D) -> bool
Test for equal reference point
Parameters:
-
polyhedron
(Polyhedron3D
) –Tested polyhedron.
Returns:
-
bool
–True when both polyhedrons has the same reference point.
GetEdge
overloaded
GetEdge(edgeHandle: int) -> tuple[eGeometryErrorCode, GeometryEdge]
Get edge at the specified position
Parameters:
-
edgeHandle
(int
) –Specified position of the edge.
Returns:
-
eGeometryErrorCode
–error code
-
GeometryEdge
–edge
Examples:
Get the first edge
Get the last edge
GetEdge(orientedEdge: OrientedEdge) -> tuple[eGeometryErrorCode, GeometryEdge]
Get edge at the specified position with orientation
Parameters:
-
orientedEdge
(OrientedEdge
) –Specified position and orientation of the edge.
Returns:
-
eGeometryErrorCode
–error code
-
GeometryEdge
–edge
GetEdgeVertices
GetEdgeVertices(
orientedEdge: OrientedEdge,
) -> tuple[eGeometryErrorCode, Point3D, Point3D]
Get points on specified edge from specified face
Method throw exception in case of any error.
Parameters:
-
orientedEdge
(OrientedEdge
) –Oriented edge.
Returns:
-
tuple[eGeometryErrorCode, Point3D, Point3D]
–tuple(Error code., StartVertex, EndVertex)
GetEdges
GetEdges() -> tuple[eGeometryErrorCode, list[GeometryEdge]]
Get a list of all edges
Returns:
-
eGeometryErrorCode
–error code
-
list[GeometryEdge]
–list of edges
Examples:
GetEdgesCount
GetEdgesLines
GetEdgesLines() -> tuple[eGeometryErrorCode, Line3DList]
Get copy of all edges as vector of lines
Returns:
-
eGeometryErrorCode
–error code
-
Line3DList
–list with all edges as 3d lines
Examples:
>>> cube_1x1.GetEdgesLines()
(NemAll_Python_Geometry.eGeometryErrorCode.eOK, Line3D(0, 1, 0, 0, 0, 0)
Line3D(0, 0, 0, 1, 0, 0)
Line3D(1, 0, 0, 1, 1, 0)
Line3D(1, 1, 0, 0, 1, 0)
Line3D(0, 0, 1, 0, 1, 1)
Line3D(0, 1, 1, 1, 1, 1)
Line3D(1, 1, 1, 1, 0, 1)
Line3D(1, 0, 1, 0, 0, 1)
Line3D(0, 1, 0, 0, 1, 1)
Line3D(0, 0, 1, 0, 0, 0)
Line3D(1, 0, 1, 1, 0, 0)
Line3D(1, 1, 1, 1, 1, 0)
)
GetEdgesOnFaceCount
GetFace
GetFace(faceIndex: int) -> PolyhedronFace
Get face at the specified position
In case of error, method throw an exception.
Parameters:
-
faceIndex
(int
) –Specified position of the face.
Returns:
-
PolyhedronFace
–Face.
Examples:
GetFacesCount
GetNormalVectorOfFace
GetNormalVectorOfFace(faceIndex: int) -> tuple[eGeometryErrorCode, Vector3D]
Get normal vector of the face
Parameters:
-
faceIndex
(int
) –face index
Returns:
-
tuple[eGeometryErrorCode, Vector3D]
–tuple(error code, result normal vector)
Examples:
GetParts
GetParts() -> tuple[eGeometryErrorCode, list[Polyhedron3D]]
Get separated parts (continuos shells)
Returns:
-
eGeometryErrorCode
–error code
-
list[Polyhedron3D]
–list with individual polyhedrons
GetPartsCount
GetRefPoint
GetRefPoint() -> Point3D
GetRelVertex
GetRelVertex(index: int) -> tuple[eGeometryErrorCode, Point3D]
Get relative vertex at specified position
Method throw exception in case of any error. (usually out of range)
Parameters:
-
index
(int
) –Specified position.
Returns:
-
eGeometryErrorCode
–error code
-
Point3D
–vertex in local coordinate system - reference point is the origin
Examples:
Change the position of reference point, without moving the cube vertices
The position of vertices in global coordinate system does not change
But the position in local coordinate system changed
>>> cube_1x1.GetRelVertex(0)
(NemAll_Python_Geometry.eGeometryErrorCode.eOK, Point3D(-0.5, 0.5, -0.5))
Move the reference point back to original position
GetType
GetType() -> PolyhedronType
Get polyhedron type
In case of error, method return tEdges.
Returns:
-
PolyhedronType
–Type.
Examples:
GetVertex
GetVertex(vertexIndex: int) -> tuple[eGeometryErrorCode, Point3D]
Get vertex at specified position
Method throw exception in case of any error.
Parameters:
-
vertexIndex
(int
) –Specified position of vertex.
Returns:
-
eGeometryErrorCode
–error code
-
Point3D
–vertex in global coordinate system
Examples:
GetVertices
GetVertices() -> Point3DList
Get list of vertices in local coordinate system
Returns:
-
Point3DList
–List with all vertices
Examples:
Change the position of reference point, without moving the cube vertices
Points are returned in local coordinate system
>>> cube_1x1.GetVertices()
Point3D(-0.5, 0.5, -0.5)
Point3D(-0.5, -0.5, -0.5)
Point3D(0.5, -0.5, -0.5)
Point3D(0.5, 0.5, -0.5)
Point3D(-0.5, -0.5, 0.5)
Point3D(-0.5, 0.5, 0.5)
Point3D(0.5, 0.5, 0.5)
Point3D(0.5, -0.5, 0.5)
Move the reference point back to original position
GetVerticesCount
Heal
Heal() -> eGeometryErrorCode
Heal polyhedron
Healing is a process of fixing non-planar faces. Either by moving the vertices a little to make them planar, or by triangulating the faces around the "fixed" vertices.
Only works with small perturbances - no topological changes are made.
Returns:
-
eGeometryErrorCode
–error code
Invert
Invert() -> eGeometryErrorCode
Invert polyhedron from positive to negative or vice versa
Returns:
-
eGeometryErrorCode
–error code
Examples:
Given polyhedron is positive
Invert the polyhedron
This results in flag changed to negative
And a negative volume
Invert again to fix it
InvertWithFlagUnchanged
InvertWithFlagUnchanged() -> eGeometryErrorCode
Invert polyhedron from positive to negative or vice versa, but keep flag unchanged
Returns:
-
eGeometryErrorCode
–error code
Examples:
Given polyhedron is positive
Invert the polyhedron
This results in polyhedron having a negative volume
But the flag remains positive
Invert again to fix it
IsNegative
Checking the negative orientation
Method throw exception in case of any error. Old interface: getPolyederNega
Returns:
-
bool
–True when negative orientation, otherwise false.
IsValid
Checking validity
Depends on polyhedron type
Returns:
-
bool
–True when valid, otherwise false.
Normalize
Normalize(normType: int) -> eGeometryErrorCode
Normalize polyhedron
Normalization is a process ensuring that the polyhedron have the correct type (line/face/volume), no overlapping edges, all faces are closed and all faces are planar.
Parameters:
-
normType
(int
) –Normalization type.
- 0 - no normalization - 1 - polyhedron consists of only edges - 2 - polyhedron consists of edges building closed faces, but no closed volume - 3 - polyhedron consists of edges building closed faces building closed volume
Returns:
-
eGeometryErrorCode
–Error code.
ReadFromStream
ReadFromStream(sstream_str: str) -> eGeometryErrorCode
Read a polyhedron from string stream
Parameters:
-
sstream_str
(str
) –input stream
Returns:
-
eGeometryErrorCode
–error code
Examples:
>>> new_polyhedron = Polyhedron3D()
>>> new_polyhedron.ReadFromStream("00000000000000000000000000000000000000000000000003000000080000000c000000060000000000000000000000000000000000f03f0000000000000000000000000000000000000000000000000000000000000000000000000000f03f00000000000000000000000000000000000000000000f03f000000000000f03f000000000000000000000000000000000000000000000000000000000000f03f0000000000000000000000000000f03f000000000000f03f000000000000f03f000000000000f03f000000000000f03f000000000000f03f0000000000000000000000000000f03f0100000002000000020000000300000003000000040000000400000001000000050000000600000006000000070000000700000008000000080000000500000001000000060000000500000002000000080000000300000007000000040000000400000001000000020000000300000004000000040000000500000006000000070000000800000004000000ffffffff09000000fbffffff0a00000004000000fefffffff6fffffff8ffffff0b00000004000000fdfffffff5fffffff9ffffff0c00000004000000fcfffffff4fffffffafffffff7ffffff")
NemAll_Python_Geometry.eGeometryErrorCode.eOK
>>> new_polyhedron
Polyhedron3D(
Type(3)
IsNegative(0)
PartsCount(1)
EdgeCount(12)
FaceCount(6)
VertexCount(8)
Vertices(
(0, 1, 0)
(0, 0, 0)
(1, 0, 0)
(1, 1, 0)
(0, 0, 1)
(0, 1, 1)
(1, 1, 1)
(1, 0, 1)))
RemapVertices
RemapVertices(source: Polyhedron3D) -> bool
set vertex order as in source polyhedron
Parameters:
-
source
(Polyhedron3D
) –- original cuboid
Returns:
-
bool
–success
Set
Set(refPoint: Point3D, polyhedronWorld: Polyhedron3D)
Set polyhedron on reference point. Polyhedron is in world coordinate system
Parameters:
-
refPoint
(Point3D
) –Reference point.
-
polyhedronWorld
(Polyhedron3D
) –Polyhedron with vertices in World coordinate system.
SetRefPoint
SetRefPoint(refPoint: Point3D)
Set the reference point
Be aware: All vertices will be recalculated on new reference point. This operation is very slow in case of many vertices. Use constructor for better and faster initialization object.
Parameters:
-
refPoint
(Point3D
) –New reference point.
SetType
SetType(polyheronType: PolyhedronType)
Get polyhedron type
Method throw exception if polyhedron is not initialized. In case of incorrect polyhedronType, tEdges type will be set.
Parameters:
-
polyheronType
(PolyhedronType
) –Type of polyhedron.
WriteToStream
WriteToStream() -> tuple[eGeometryErrorCode, str]
Stream polyhedron to a string
Returns:
-
tuple[eGeometryErrorCode, str]
–tuple(error code, output stream)
Examples:
>>> cube_1x1.WriteToStream()
(NemAll_Python_Geometry.eGeometryErrorCode.eOK, '00000000000000000000000000000000000000000000000003000000080000000c000000060000000000000000000000000000000000f03f0000000000000000000000000000000000000000000000000000000000000000000000000000f03f00000000000000000000000000000000000000000000f03f000000000000f03f000000000000000000000000000000000000000000000000000000000000f03f0000000000000000000000000000f03f000000000000f03f000000000000f03f000000000000f03f000000000000f03f000000000000f03f0000000000000000000000000000f03f0100000002000000020000000300000003000000040000000400000001000000050000000600000006000000070000000700000008000000080000000500000001000000060000000500000002000000080000000300000007000000040000000400000001000000020000000300000004000000040000000500000006000000070000000800000004000000ffffffff09000000fbffffff0a00000004000000fefffffff6fffffff8ffffff0b00000004000000fdfffffff5fffffff9ffffff0c00000004000000fcfffffff4fffffffafffffff7ffffff')
__eq__
__eq__(polyhedron: Polyhedron3D) -> object
Comparison of polyhedrons without tolerance.
Be careful, this method work without tolerance!
Parameters:
-
polyhedron
(Polyhedron3D
) –Compared polyhedron.
Returns:
-
object
–True when polyhedrons are equal, otherwise false.
__getitem__
__getitem__(index: int) -> Point3D
Get vertex at the specified position from index. Used world coordinates
Operator throw exception in case of any error.
Parameters:
-
index
(int
) –Specified position
Returns:
-
Point3D
–Vertex
Examples:
__init__
overloaded
Initialize
__init__(
polyhedronType: PolyhedronType,
verticesCount: int,
edgesCount: int,
facesCount: int,
negativeOrientation: bool,
)
Constructor
The "Count" parameters have sense only for appropriate polyhedron type and specified a memory allocation size - performance optimization. In case of any error, constructor throw an exception.
Parameters:
-
polyhedronType
(PolyhedronType
) –Polyhedron type - edges, faces or volume.
-
verticesCount
(int
) –Count of expected vertices.
-
edgesCount
(int
) –Count of expected edges.
-
facesCount
(int
) –Count of expected faces.
-
negativeOrientation
(bool
) –True for negative orientation.
__init__(polyhedron: Polyhedron3D)
__mul__
__mul__(matrix: Matrix3D) -> Polyhedron3D
Matrix transformation of vertices only!
Reference point remains unchanged.
Parameters:
-
matrix
(Matrix3D
) –Transformation matrix.
Returns:
-
Polyhedron3D
–Transformed polyhedron.
Examples:
Assuming a translation by 100 in all X, Y and Z direction, described like
And a cube with reference point in the origin
Applying the translation will result in vertices being translated
But the reference point remains unchanged!