CenterCalculus
Canonical path: NemAll_Python_Geometry.CenterCalculus
Class to calculate the center of an object
Calculate
overloaded
Calculates the center of a 2D line
Parameters:
-
line
(Line2D
) –Line2D on which to calculate the center
Returns:
Examples:
Calculate the center of a 3D line
Parameters:
-
line
(Line3D
) –Line3D on which to calculate the center
Returns:
Examples:
Calculate(polyline: Polyline2D, edge: int) -> tuple
Calculate the center of a 2D polyline
Parameters:
-
polyline
(Polyline2D
) –Polyline on which to calculate the center.
-
edge
(int
) –Index of the segment to calculate the center on. Set to 0 to calculate the center of the entire polyline.
Returns:
-
tuple
–True when calculation was successful. False otherwise
-
tuple
–Center of the polyline or its segment
Examples:
For a given polyline:
>>> polyline = Polyline2D([Point2D(0, 0),
... Point2D(1, 0),
... Point2D(1, 1),
... Point2D(-1, 1),
... ])
Calculate the center point of the first polyline segment like:
Calculate the center point of the last polyline segment like:
Calculate the center point of the entire polyline like:
Note, that the center point is not the center of gravity. It`s the point dividing the polyline into two parts of the same lengths!
Calculate(polyline: Polyline3D, edge: int) -> tuple
Calculates the center of a 3D polyline
Parameters:
-
polyline
(Polyline3D
) –Polyline on which to calculate the center.
-
edge
(int
) –Index of the segment to calculate the center on. Set to 0 to calculate the center of the entire polyline.
Returns:
-
tuple
–True when calculation was successful. False otherwise
-
tuple
–Center of the polyline or its segment
Examples:
>>> polyline = Polyline3D([Point3D(0, 0, 0),
... Point3D(2, 0, 0),
... Point3D(2, 3, 0),
... Point3D(2, 3, 4),
... ])
Calculate the center point of the first polyline segment like:
Calculate the center point of the last polyline segment like:
Calculate the point dividing the polyline in two equally long parts like:
Calculates the center of a 2D polygon.
Parameters:
-
polygon
(Polygon2D
) –Polygon on which to calculate the center
-
bPlaneCenter
(bool
) –Whether to calculate the center of gravity of the area bounded by the polygon (True) or the center of the outline polyline (False)
-
edge
(int
) –When bPlaneCenter is set to False, this is the index of the segment of the outline polyline to calculate the center on. Set to 0 to calculate the center of the entire outline polyline.
Returns:
-
tuple
–True when calculation was successful. False otherwise.
-
tuple
–Center of the polygon or its outline
Examples:
For a given 2 x 2 rectangle:
Calculate the center of gravity like:
Calculate the center point of the first rectangle edge like:
Calculate the point dividing the rectangle's outline in two equally long parts like:
Calculates the center of a 3D polygon.
Parameters:
-
polygon
(Polygon3D
) –Polygon on which to calculate the center
-
bPlaneCenter
(bool
) –Whether to calculate the center of the area bounded by the polygon (True) or the center of the outline polyline (False)
-
edge
(int
) –When bPlaneCenter is set to False, this is the index of the segment of the outline polyline to calculate the center on. Set to 0 to calculate the center of the entire outline polyline.
Returns:
-
tuple
–True when calculation was successful. False otherwise.
-
tuple
–Center of the polygon or its outline
Examples:
For a rectangle defined like:
>>> rectangle = Polygon3D([Point3D(),
... Point3D(2.0, 0.0, 0.0),
... Point3D(2.0, 2.0, 2.0),
... Point3D(0.0, 2.0, 2.0),
... Point3D(),
... ])
Calculate the center of gravity like:
Calculate the center point of the first rectangle edge like:
Calculate the point dividing the rectangle's outline in two equally long parts like:
Calculates the center of a 2D arc.
Parameters:
-
arc
(Arc2D
) –arc on which to calculate the center
-
center
(bool
) –True to calculate the point on the arc dividing it into two equal parts. False to calculate the arc's center.
Returns:
-
tuple
–True when calculation was successful. False otherwise.
-
tuple
–Center or midpoint of the arc
Examples:
For a given 90° arc with a radius of 1 and center in the origin, like:
Calculate the middle point on the arc like:
Calculate the arc's center point like:
Calculates the center of a 3D arc.
Parameters:
-
arc
(Arc3D
) –arc on which to calculate the center
-
center
(bool
) –True to calculate the point on the arc dividing it into two equal parts. False to calculate the arc's center.
Returns:
-
tuple
–True when calculation was successful. False otherwise.
-
tuple
–Center or midpoint of the arc
Examples:
For a given 90° arc with a radius of 1, center in the origin, positioned in the XZ plane, like:
>>> arc_3d = Transform( arc = Arc3D(Point3D(), 1, 1, 0, pi/2),
... matrix = rotation_by_90_deg_around_x)
Calculate the middle point on the arc like:
Calculate the arc's center point like:
Calculates the center of a 2D spline.
Parameters:
-
spline
(Spline2D
) –Spline on which to calculate the center
-
eps
(float
) –Precision for calculation
Returns:
Examples:
For a given spline
Calculate the center point like
Calculates the center of a 3D spline.
Parameters:
-
spline
(Spline3D
) –Spline on which to calculate the center
-
eps
(float
) –Precision for calculation. Set to a small number, like 1e-11
Returns:
Examples:
For a given spline
>>> spline = Spline3D([Point3D(),
... Point3D(2, 2, 0),
... Point3D(3, 1, 2),
... Point3D(4, 3, 3)
... ])
Calculate the center point like
Calculates the center of a 3D base spline.
Parameters:
-
spline
(BSpline3D
) –B-spline on which to calculate the center
-
eps
(float
) –Precision for calculation. Set to a small number, like 1e-11
-
bAreaCenter
(bool
) –In case of a closed b-spline, whether to calculate the center of the area bounded by the B-spline (True) or the center of the b-spline curve (False)
Returns:
Examples:
For a given non-periodic, uniform and non-rational 3-dimensional base spline of 3rd degree, defined like
>>> points = Point3DList([Point3D(),
... Point3D(2, 2, 0),
... Point3D(3, 1, 2),
... Point3D(4, 3, 3)
... ])
>>> bspline = BSpline3D.CreateBSpline(points, 3, False)
Calculate the center point like
Calculate(clothoid: Clothoid2D, eps: float) -> tuple
Calculates the center of a 2D clothoid.
Parameters:
-
clothoid
(Clothoid2D
) –clothoid on which to calculate the center
-
eps
(float
) –Precision for calculation. Set to a small number, like 1e-11
Returns:
Calculates the center of a 2D path.
Parameters:
-
path
(Path2D
) –Path on which to calculate the center
-
eps
(float
) –Precision for calculation. Set to a small number, like 1e-11
-
bAreaCenter
(bool
) –In case of a closed path, whether to calculate the center of the area bounded by the path (True) or the center of the path itself (False)
Returns:
Calculates the center of a 3D path.
Parameters:
-
path
(Path3D
) –Path on which to calculate the center
-
eps
(float
) –Precision for calculation
-
bAreaCenter
(bool
) –In case of a closed path, whether to calculate the center of the area bounded by the path (True) or the center of the path itself (False)
Returns:
Calculate(geoObject: object, eps: float, bArcCenter: bool, edge: int) -> tuple
Calculates the center of any curve.
Parameters:
-
geoObject
(object
) –curve on which to calculate the center
-
eps
(float
) –Precision for calculation
-
bArcCenter
(bool
) –Whether to calculate the arc's midpoint, that divides the arc into two halves (True) or the arc's center (False)
-
edge
(int
) –For polyline and polygon, index of the segment to calculate the center on. Set to 0 to calculate the center of the entire polyline/polygon.
Returns: