Skip to content

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

Get polyhedron type

In case of error, method return tEdges.

Get polyhedron type

Method throw exception if polyhedron is not initialized. In case of incorrect polyhedronType, tEdges type will be set.

Examples:

>>> cube_1x1.Type
NemAll_Python_Geometry.PolyhedronType.tVolume

AppendEdge

AppendEdge(edge: GeometryEdge) -> eGeometryErrorCode

Append edge

Method throw exception if object is not initialized. Old interface: appendPolyederEdge

Parameters:

Returns:

Clear overloaded

Clear()

Clear all vertices, edges and faces

Type and vertices,edges,faces preallocation size of polyhedron will be preserved

Clear(
    verticesCount: int,
    edgesCount: int,
    facesCount: int,
    negativeOrientation: bool,
)

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:

  • p1 (Point3D) –

    lower left point

  • p2 (Point3D) –

    upper right point

Returns:

Examples:

>>> cube = Polyhedron3D.CreateCuboid(Point3D(), Point3D(1.0, 2.0, 3.0 ))
>>> CalcMass(cube)
(NemAll_Python_Geometry.eGeometryErrorCode.eOK, 6.0, 22.0, Point3D(0.5, 1, 1.5))
>>> cube.RefPoint
Point3D(0, 0, 0)
CreateCuboid(box: MinMax3D) -> Polyhedron3D

Construct a cuboid from a MinMax object

Parameters:

  • box (MinMax3D) –

    min/max box that states the cuboid's size

Returns:

Examples:

>>> cube = Polyhedron3D.CreateCuboid(MinMax3D(Point3D(), Point3D(1.0, 2.0, 3.0 )))
>>> CalcMass(cube)
(NemAll_Python_Geometry.eGeometryErrorCode.eOK, 6.0, 22.0, Point3D(0.5, 1, 1.5))
>>> cube.RefPoint
Point3D(0, 0, 0)
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:

Examples:

>>> cube = Polyhedron3D.CreateCuboid(AxisPlacement3D(), 1.0, 2.0, 3.0)
>>> CalcMass(cube)
(NemAll_Python_Geometry.eGeometryErrorCode.eOK, 6.0, 22.0, Point3D(0.5, 1, 1.5))
>>> cube.RefPoint
Point3D(0, 0, 0)
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:

Examples:

>>> cube = Polyhedron3D.CreateCuboid(1.0, 2.0, 3.0)
>>> CalcMass(cube)
(NemAll_Python_Geometry.eGeometryErrorCode.eOK, 6.0, 22.0, Point3D(0.5, 1, 1.5))
>>> cube.RefPoint
Point3D(0, 0, 0)

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:

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:

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:

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:

EqualRef

EqualRef(polyhedron: Polyhedron3D) -> bool

Test for equal reference point

Parameters:

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:

Examples:

Get the first edge

>>> cube_1x1.GetEdge(0)
(NemAll_Python_Geometry.eGeometryErrorCode.eOK, GeometryEdge(0, 1))

Get the last edge

>>> cube_1x1.GetEdge(cube_1x1.GetEdgesCount() - 1)
(NemAll_Python_Geometry.eGeometryErrorCode.eOK, GeometryEdge(6, 3))
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:

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:

Returns:

GetEdges

GetEdges() -> tuple[eGeometryErrorCode, list[GeometryEdge]]

Get a list of all edges

Returns:

Examples:

>>> cube_1x1.GetEdges()
(NemAll_Python_Geometry.eGeometryErrorCode.eOK, [GeometryEdge(0, 1), GeometryEdge(1, 2), ... GeometryEdge(6, 3)])

GetEdgesCount

GetEdgesCount() -> int

Get count of edges

Method throw exception in case of any error. Count

Returns:

  • int

    Count of edges.

Examples:

>>> cube_1x1.GetEdgesCount()
12

GetEdgesLines

GetEdgesLines() -> tuple[eGeometryErrorCode, Line3DList]

Get copy of all edges as vector of lines

Returns:

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

GetEdgesOnFaceCount(faceIndex: int) -> int

Get count of edges of the specified face

Parameters:

  • faceIndex (int) –

    Specified position of the face.

Returns:

  • int

    Count if edges.

Examples:

>>> cube_1x1.GetEdgesOnFaceCount(0)
4

Method returns 0 when index is exceeded

>>> cube_1x1.GetEdgesOnFaceCount(99)
0

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:

Examples:

>>> cube_1x1.GetFace(0)
PolyhedronFace(
   EdgesCount(4)
   OrientedEdges(
      (0, Positive)
      (1, Positive)
      (2, Positive)
      (3, Positive)))

GetFacesCount

GetFacesCount() -> int

Get count of faces

Method throw exception in case of any error.

Returns:

  • int

    Count of faces.

Examples:

>>> cube_1x1.GetFacesCount()
6

GetNormalVectorOfFace

GetNormalVectorOfFace(faceIndex: int) -> tuple[eGeometryErrorCode, Vector3D]

Get normal vector of the face

Parameters:

  • faceIndex (int) –

    face index

Returns:

Examples:

>>> cube_1x1.GetNormalVectorOfFace(0)
(NemAll_Python_Geometry.eGeometryErrorCode.eOK, Vector3D(0, 0, 1))

GetParts

GetParts() -> tuple[eGeometryErrorCode, list[Polyhedron3D]]

Get separated parts (continuos shells)

Returns:

GetPartsCount

GetPartsCount() -> int

Get number of parts in this polyhedron

Returns:

  • int

    number of parts

Examples:

>>> cube_1x1.GetPartsCount()
1

GetRefPoint

GetRefPoint() -> Point3D

Get the reference point

Returns:

  • Point3D

    Constant reference point.

Examples:

>>> cube_1x1.GetRefPoint()
Point3D(0, 0, 0)

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:

Examples:

Change the position of reference point, without moving the cube vertices

>>> cube_1x1.RefPoint = Point3D(0.5, 0.5, 0.5)

The position of vertices in global coordinate system does not change

>>> cube_1x1.GetVertex(0)
(NemAll_Python_Geometry.eGeometryErrorCode.eOK, Point3D(0, 1, 0))

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

>>> cube_1x1.RefPoint = Point3D()

GetType

GetType() -> PolyhedronType

Get polyhedron type

In case of error, method return tEdges.

Returns:

Examples:

>>> cube_1x1.GetType()
NemAll_Python_Geometry.PolyhedronType.tVolume

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:

Examples:

>>> cube_1x1.GetVertex(0)
(NemAll_Python_Geometry.eGeometryErrorCode.eOK, Point3D(0, 1, 0))

GetVertices

GetVertices() -> Point3DList

Get list of vertices in local coordinate system

Returns:

Examples:

Change the position of reference point, without moving the cube vertices

>>> cube_1x1.RefPoint = Point3D(0.5, 0.5, 0.5)

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

>>> cube_1x1.RefPoint = Point3D()

GetVerticesCount

GetVerticesCount() -> int

Get count of vertices

Method throw exception in case of any error. Count

Returns:

  • int

    Count of vertices.

Examples:

>>> cube_1x1.GetVerticesCount()
8

Heal

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:

Invert

Invert() -> eGeometryErrorCode

Invert polyhedron from positive to negative or vice versa

Returns:

Examples:

Given polyhedron is positive

>>> cube_1x1.IsNegative()
False

Invert the polyhedron

>>> cube_1x1.Invert()
NemAll_Python_Geometry.eGeometryErrorCode.eOK

This results in flag changed to negative

>>> cube_1x1.IsNegative()
True

And a negative volume

>>> round(CalcMass(cube_1x1)[1])
-1

Invert again to fix it

>>> cube_1x1.Invert()
NemAll_Python_Geometry.eGeometryErrorCode.eOK
>>> cube_1x1.IsNegative()
False
>>> round(CalcMass(cube_1x1)[1])
1

InvertWithFlagUnchanged

InvertWithFlagUnchanged() -> eGeometryErrorCode

Invert polyhedron from positive to negative or vice versa, but keep flag unchanged

Returns:

Examples:

Given polyhedron is positive

>>> cube_1x1.IsNegative()
False

Invert the polyhedron

>>> cube_1x1.InvertWithFlagUnchanged()
NemAll_Python_Geometry.eGeometryErrorCode.eOK

This results in polyhedron having a negative volume

>>> round(CalcMass(cube_1x1)[1])
-1

But the flag remains positive

>>> cube_1x1.IsNegative()
False

Invert again to fix it

>>> cube_1x1.InvertWithFlagUnchanged()
NemAll_Python_Geometry.eGeometryErrorCode.eOK
>>> round(CalcMass(cube_1x1)[1])
1

IsNegative

IsNegative() -> bool

Checking the negative orientation

Method throw exception in case of any error. Old interface: getPolyederNega

Returns:

  • bool

    True when negative orientation, otherwise false.

IsValid

IsValid() -> bool

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:

ReadFromStream

ReadFromStream(sstream_str: str) -> eGeometryErrorCode

Read a polyhedron from string stream

Parameters:

  • sstream_str (str) –

    input stream

Returns:

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:

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:

WriteToStream

WriteToStream() -> tuple[eGeometryErrorCode, str]

Stream polyhedron to a string

Returns:

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:

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:

Examples:

>>> cube_1x1[0]
Point3D(0, 1, 0)

__init__ overloaded

__init__()

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)

Copy constructor

Parameters:

  • polyhedron (Polyhedron3D) –

    Polyhedron which will be copied.

__mul__

__mul__(matrix: Matrix3D) -> Polyhedron3D

Matrix transformation of vertices only!

Reference point remains unchanged.

Parameters:

  • matrix (Matrix3D) –

    Transformation matrix.

Returns:

Examples:

Assuming a translation by 100 in all X, Y and Z direction, described like

>>> translation
Matrix3D(
   1 0 0 0
   0 1 0 0
   0 0 1 0
   100 100 100 1)

And a cube with reference point in the origin

>>> cube_1x1[0]
Point3D(0, 1, 0)
>>> cube_1x1.RefPoint
Point3D(0, 0, 0)

Applying the translation will result in vertices being translated

>>> translated_cube = cube_1x1 * translation
>>> translated_cube[0]
Point3D(100, 101, 100)

But the reference point remains unchanged!

>>> cube_1x1.RefPoint
Point3D(0, 0, 0)

__repr__

__repr__() -> str

Convert to string

Placeholder