Skip to content

CenterCalculus

Canonical path: NemAll_Python_Geometry.CenterCalculus

Class to calculate the center of an object

Calculate overloaded

Calculate(line: Line2D) -> tuple

Calculates the center of a 2D line

Parameters:

  • line (Line2D) –

    Line2D on which to calculate the center

Returns:

  • tuple

    True when calculation was successful. False otherwise

  • tuple

    Center of the line

Examples:

>>> line = Line2D(0, 0, 1, 1)
>>> CenterCalculus.Calculate(line)
(True, Point3D(0.5, 0.5, 0))
Calculate(line: Line3D) -> tuple

Calculate the center of a 3D line

Parameters:

  • line (Line3D) –

    Line3D on which to calculate the center

Returns:

  • tuple

    True when calculation was successful. False otherwise

  • tuple

    Center of the line

Examples:

>>> line = Line3D(0, 0, 0, 1, 1, 1)
>>> CenterCalculus.Calculate(line)
(True, Point3D(0.5, 0.5, 0.5))
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:

>>> CenterCalculus.Calculate(polyline, 1)
(True, Point3D(0.5, 0, 0))

Calculate the center point of the last polyline segment like:

>>> CenterCalculus.Calculate(polyline, polyline.LineCount())
(True, Point3D(0, 1, 0))

Calculate the center point of the entire polyline like:

>>> CenterCalculus.Calculate(polyline, 0)
(True, Point3D(1, 1, 0))

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:

>>> CenterCalculus.Calculate(polyline, 1)
(True, Point3D(1, 0, 0))

Calculate the center point of the last polyline segment like:

>>> CenterCalculus.Calculate(polyline, polyline.LineCount())
(True, Point3D(2, 3, 2))

Calculate the point dividing the polyline in two equally long parts like:

>>> CenterCalculus.Calculate(polyline, 0)
(True, Point3D(2, 2.5, 0))
Calculate(polygon: Polygon2D, bPlaneCenter: bool, edge: int) -> tuple

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:

>>> rectangle = Polygon2D.CreateRectangle(leftBottom = Point2D(),
...                                       rightTop   = Point2D(2.0, 2.0))

Calculate the center of gravity like:

>>> CenterCalculus.Calculate(rectangle, True, 0)
(True, Point3D(1, 1, 0))

Calculate the center point of the first rectangle edge like:

>>> CenterCalculus.Calculate(rectangle, False, 1)
(True, Point3D(1, 0, 0))

Calculate the point dividing the rectangle's outline in two equally long parts like:

>>> CenterCalculus.Calculate(rectangle, False, 0)
(True, Point3D(2, 2, 0))
Calculate(polygon: Polygon3D, bPlaneCenter: bool, edge: int) -> tuple

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:

>>> CenterCalculus.Calculate(rectangle, True, 0)
(True, Point3D(1, 1, 1))

Calculate the center point of the first rectangle edge like:

>>> CenterCalculus.Calculate(rectangle, False, 1)
(True, Point3D(1, 0, 0))

Calculate the point dividing the rectangle's outline in two equally long parts like:

>>> CenterCalculus.Calculate(rectangle, False, 0)
(True, Point3D(2, 2, 2))
Calculate(arc: Arc2D, center: bool) -> tuple

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:

>>> arc = Arc2D(Point2D(), 1, 1, 0, 0, pi/2)

Calculate the middle point on the arc like:

>>> CenterCalculus.Calculate(arc, True)
(True, Point3D(0.7071067812, 0.7071067812, 0))

Calculate the arc's center point like:

>>> CenterCalculus.Calculate(arc, False)
(True, Point3D(0, 0, 0))
Calculate(arc: Arc3D, center: bool) -> tuple

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:

>>> CenterCalculus.Calculate(arc_3d, True)
(True, Point3D(0.7071067812, 0, 0.7071067812))

Calculate the arc's center point like:

>>> CenterCalculus.Calculate(arc_3d, False)
(True, Point3D(0, 0, 0))
Calculate(spline: Spline2D, eps: float) -> tuple

Calculates the center of a 2D spline.

Parameters:

  • spline (Spline2D) –

    Spline on which to calculate the center

  • eps (float) –

    Precision for calculation

Returns:

  • tuple

    True when calculation was successful. False otherwise.

  • tuple

    Center of the spline

Examples:

For a given spline

>>> spline = Spline2D([Point2D(),
...                    Point2D(2, 2),
...                    Point2D(3, 1),
...                    Point2D(4, 3)
...                    ])

Calculate the center point like

>>> CenterCalculus.Calculate(spline, 1e-11)
(True, Point3D(2.2646311587, 1.7643958968, 0))
Calculate(spline: Spline3D, eps: float) -> tuple

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:

  • tuple

    True when calculation was successful. False otherwise.

  • tuple

    Center of the spline

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

>>> CenterCalculus.Calculate(spline, 1e-11)
(True, Point3D(2.4830594929, 1.5628397978, 0.7817085792))
Calculate(spline: BSpline3D, eps: float, bAreaCenter: bool) -> tuple

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:

  • tuple

    True when calculation was successful. False otherwise.

  • tuple

    Center of the b-spline

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

>>> CenterCalculus.Calculate(bspline, 1e-11, False)
(True, Point3D(2.3184429507, 1.4774931536, 1.0691306248))
Calculate(spline: BSpline2D, eps: float) -> tuple

Calculates the center of a 2D base spline.

Parameters:

  • spline (BSpline2D) –

    B-spline on which to calculate the center

  • eps (float) –

    Precision for calculation. Set to a small number, like 1e-11

Returns:

  • tuple

    True when calculation was successful. False otherwise.

  • tuple

    Center of the b-spline

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:

  • tuple

    True when calculation was successful. False otherwise.

  • tuple

    Center of the clothoid

Calculate(path: Path2D, eps: float, bAreaCenter: bool) -> tuple

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:

  • tuple

    True when calculation was successful. False otherwise.

  • tuple

    Center of the path

Calculate(path: Path3D, eps: float, bAreaCenter: bool) -> tuple

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:

  • tuple

    True when calculation was successful. False otherwise.

  • tuple

    Center of the path

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:

  • tuple

    True when calculation was successful. False otherwise.

  • tuple

    Center of the path

Placeholder