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:
-
Line3DList
–Edge lines of polygon
Examples:
For a polygon representing a 1x1 square in the XY plane, the result is 4 lines
GetPlane
GetPlane() -> tuple[eGeometryErrorCode, Plane3D]
Calculate plane
Returns:
-
tuple[eGeometryErrorCode, Plane3D]
–Plane where polygon is
Examples:
Assume a polygon representing a 1x1 square in the XY plane
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
IsValidStatus
IsValidStatus() -> tuple
Check polygon validity
Returns:
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
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:
-
normalizeType
(ePolygonNormalizeType
, default:DEFAULT_NORM_TYPE
) –Normalization type
-
extra_smooth
(bool
, default:False
) –Increase level of details
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
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:
-
normalizeType
(ePolygonNormalizeType
, default:DEFAULT_NORM_TYPE
) –type of Polygon2D normalization
-
extra_smooth
(bool
, default:False
) –Including extra smooth: true/false
Returns:
-
eGeometryErrorCode
–Error code (eOK, eAllocError, eStructuralError, eWrongShape)
__eq__
__eq__(polygon2: Polygon3D) -> bool
Equal operator
Parameters:
-
polygon2
(Polygon3D
) –Second polygon
Returns:
-
bool
–Polyline3D are equal
__iadd__
overloaded
Addition assignment operator
Parameters:
-
polygon
(Polygon3D
) –Polygon which will be copied
Returns:
-
Polygon3D
–Reference to polygon
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