Skip to content

Polygon3D

Canonical path: NemAll_Python_Geometry.Polygon3D

Bases: PolyPoints3D

Representation of a plane polygon in a three dimensional space

To construct a valid 3D polygon from a bunch of points, the following rules must be fulfilled:

  • First and last point must coincide. This class does not 'auto-close' polygons! A quadratic shape with '4' edges has to be defined by passing 5 points to a constructor. For such an object, the Count() method will return 5 accordingly.
  • The orientation of the points must be monotonous. It can be either clockwise or counter-clockwise.
  • All the points must be coplanar.
  • The polygon must not self-intersect itself. You can create polygons that self-intersect or have alternating orientation, but in those cases some methods will raise errors or return wrong calculation results.

Each polygon consists of one or more components. A component is a closed loop, representing either a solid or a cut-out, depending on the orientation of the loop (if counter-clockwise is solid element, then clockwise is a cut-out). Each component must be closed (first and last point coincide).

GetLines

GetLines() -> Line3DList

Get edge lines of polygon

Returns:

Examples:

For a polygon representing a 1x1 square in the XY plane, the result is 4 lines

>>> square_1x1_xy.GetLines()
Line3D(0, 0, 0, 1, 0, 0)
Line3D(1, 0, 0, 1, 1, 0)
Line3D(1, 1, 0, 0, 1, 0)
Line3D(0, 1, 0, 0, 0, 0)

GetPlane

Calculate plane

Returns:

Examples:

Assume a polygon representing a 1x1 square in the XY plane

>>> square_1x1_xy.GetPlane()
(NemAll_Python_Geometry.eGeometryErrorCode.eOK, Plane3D(
   Point(0.4, 0.4, 0)
   Normal(0, 0, -1)))

GetVertices

GetVertices() -> object

Get polygon vertices

Returns:

  • object

    polygon vertices

InsertPolygon

InsertPolygon(polygon: Polygon3D, position: int = -1) -> bool

Insert a polygon into current one

Parameters:

  • polygon (Polygon3D) –

    Polygon which will be inserted

  • position (int, default: -1 ) –

    Position where the polygon will be inserted

Returns:

  • bool

    true if insert was successful

IsValid

IsValid() -> bool

Check polygon validity

Returns:

  • bool

    true = valid, false = not valid

IsValidStatus

IsValidStatus() -> tuple

Check polygon validity

Returns:

  • tuple

    true = valid, false = not valid,

  • tuple

    If polygon is invalid, here is the reason.

Examples:

Polygon with colinear points

>>> colinear_polygon = Polygon3D([Point3D(0,0,0),
...                               Point3D(1,0,0),
...                               Point3D(2,0,0),
...                               Point3D(0,0,0)])
>>> colinear_polygon.IsValidStatus()
(False, NemAll_Python_Geometry.eValidationStatusPolygon3D.VS_COLINEAR)

Polygon with non-planar points

>>> non_planar_polygon = Polygon3D([Point3D(0,0,0),
...                                 Point3D(1,0,0),
...                                 Point3D(1,1,1),
...                                 Point3D(0,1,0),
...                                 Point3D(0,0,0)])
>>> non_planar_polygon.IsValidStatus()
(False, NemAll_Python_Geometry.eValidationStatusPolygon3D.VS_NOT_COPLANAR)

Valid polygon

>>> valid_polygon = Polygon3D([Point3D(0,0,0),
...                            Point3D(1,0,0),
...                            Point3D(1,1,0),
...                            Point3D(0,1,0),
...                            Point3D(0,0,0)])
>>> valid_polygon.IsValidStatus()
(True, NemAll_Python_Geometry.eValidationStatusPolygon3D.VS_NOT_COPLANAR)

Normalize

Normalize(
    normalizeType: ePolygonNormalizeType = ePolygonNormalizeType.DEFAULT_NORM_TYPE,
    extra_smooth: bool = False,
)

Normalize a polygon.

Normalization involves moving the vertices of a non-planar polygon to make it planar, uniting duplicated points or resolving crossed loops.

Parameters:

Examples:

Normalize non-planar polygon

>>> non_planar_polygon = Polygon3D([Point3D(0,0,0),
...                                 Point3D(1,0,0),
...                                 Point3D(1,1,1),
...                                 Point3D(0,1,0),
...                                 Point3D(0,0,0)])
>>> non_planar_polygon.Normalize()
>>> non_planar_polygon.GetPlane()
(NemAll_Python_Geometry.eGeometryErrorCode.eOK, Plane3D(
   Point(0.4, 0.4, 0.2)
   Normal(0, 0.70710678118654746, -0.70710678118654746)))

Resolve crossed-loop polygon

>>> crossed_loop_polygon = Polygon3D([Point3D(0,0,0),
...                                   Point3D(1,0,0),
...                                   Point3D(0,1,0),
...                                   Point3D(1,1,0),
...                                   Point3D(0,0,0)])
>>> crossed_loop_polygon.Normalize()
>>> crossed_loop_polygon
Polygon3D(
   Count(4)
   Points(
      (0.5, 0.5, 0)
      (0, 1, 0)
      (1, 1, 0)
      (0.5, 0.5, 0)))

NormalizeNoThrow

NormalizeNoThrow(
    normalizeType: ePolygonNormalizeType = ePolygonNormalizeType.DEFAULT_NORM_TYPE,
    extra_smooth: bool = False,
) -> eGeometryErrorCode

Normalize Polygon3D.

Same as Normalize, but method doesn't throw exception, just return error code

Parameters:

Returns:

Reverse

Reverse()

Reverse the point order in polygon, separately for every sub-polygon

__eq__

__eq__(polygon2: Polygon3D) -> bool

Equal operator

Parameters:

Returns:

  • bool

    Polyline3D are equal

__iadd__ overloaded

__iadd__(polygon: Polygon3D) -> Polygon3D

Addition assignment operator

Parameters:

  • polygon (Polygon3D) –

    Polygon which will be copied

Returns:

Examples:

Add two triangles

>>> first_triangle = Polygon3D([Point3D(0,0,0),
...                             Point3D(1,0,0),
...                             Point3D(1,1,0),
...                             Point3D(0,0,0)])
>>> second_triangle = Polygon3D([Point3D(0,0,0),
...                              Point3D(1,1,0),
...                              Point3D(0,1,0),
...                              Point3D(0,0,0)])
>>> first_triangle += second_triangle
>>> first_triangle.Normalize()

Result is a square

>>> first_triangle
Polygon3D(
   Count(5)
   Points(
      (0, 0, 0)
      (1, 0, 0)
      (1, 1, 0)
      (0, 1, 0)
      (0, 0, 0)))
__iadd__(point: Point3D) -> Polygon3D

Addition assignment operator

Parameters:

  • point (Point3D) –

    New Point3D which will be added to the polygon

Returns:

Examples:

Initialize an empty polygon

>>> square = Polygon3D()
>>> square.IsValid()
False

Add points with in-place addition operator to get a valid polygon representing a square

>>> square += Point3D(0,0,0)
>>> square += Point3D(1,0,0)
>>> square += Point3D(1,1,0)
>>> square += Point3D(0,1,0)
>>> square += Point3D(0,0,0)
>>> square.IsValid()
True

__init__ overloaded

__init__()

Initialize

__init__(pntList: list[Point3D])

Constructor with an initializer list

Parameters:

  • pntList (list[Point3D]) –

    Point list

__init__(polygon: Polygon3D)

Copy constructor.

Parameters:

  • polygon (Polygon3D) –

    Polygon which will be copied

__mul__

__mul__(matrix: Matrix3D) -> Polygon3D

Matrix transformation

Parameters:

  • matrix (Matrix3D) –

    Transformation matrix

Returns:

Examples:

Rotating a square located in XY plane around X axis results in relocating it to the XZ plane

>>> square_1x1_xy * rotation_by_90_deg_around_x
Polygon3D(
   Count(5)
   Points(
      (0, 0, 0)
      (1, 0, 0)
      (1, 0, 1)
      (0, 0, 1)
      (0, 0, 0)))

__ne__

__ne__(polygon2: Polygon3D) -> bool

Not equal operator

Parameters:

Returns:

  • bool

    Polyline3D are equal

__repr__

__repr__() -> str

Convert to string

Placeholder