Skip to main content

raygeo.geo.algo.fitting

Curve and primitive fitting algorithms.

Provides functions for fitting arcs, lines, circles, and beziers to point sequences. Includes recursive fitting with primitives, polyline linearization, and evaluating fitting quality (line and arc deviation).

Functions

are_points_collinear()

are_points_collinear(points: collections.abc.Sequence[types.Point3D], tolerance: float = 1e-06) -> bool

Check if three or more points are collinear within tolerance.

Returns: True if points are collinear.

ParameterTypeDescription
pointscollections.abc.Sequence[types.Point3D]Sequence of 3D points.
tolerancefloat = 1e-06Collinearity tolerance.
Returnsbool

create_arc_cmd()

create_arc_cmd(end: types.Point3D, center: types.Point, start: types.Point3D) -> list[float]

Create an arc command array.

Returns: Arc command array (8 floats).

ParameterTypeDescription
endtypes.Point3DEnd point (x, y, z).
centertypes.PointCenter offset (dx, dy).
starttypes.Point3DStart point (x, y, z).
Returnslist[float]

create_line_cmd()

create_line_cmd(end_point: types.Point3D) -> list[float]

Create a line command array from an end point.

Returns: Line command array (8 floats).

ParameterTypeDescription
end_pointtypes.Point3DEnd point (x, y, z).
Returnslist[float]

fit_circle_to_3_points()

fit_circle_to_3_points(p1: types.Point2DOr3D, p2: types.Point2DOr3D, p3: types.Point2DOr3D) -> Optional[tuple[types.Point, float]]

Fit a circle to three points.

Returns: Tuple of (center, radius) or None.

ParameterTypeDescription
p1types.Point2DOr3DFirst point (x, y) or (x, y, z).
p2types.Point2DOr3DSecond point (x, y) or (x, y, z).
p3types.Point2DOr3DThird point (x, y) or (x, y, z).
ReturnsOptional[tuple[types.Point, float]]

fit_circle_to_points()

fit_circle_to_points(points: collections.abc.Sequence[types.Point3D]) -> Optional[tuple[types.Point, float, float]]

Fit a circle to a set of points.

Returns: Tuple of (center, radius, error) or None.

ParameterTypeDescription
pointscollections.abc.Sequence[types.Point3D]Sequence of 3D points to fit.
ReturnsOptional[tuple[types.Point, float, float]]

fit_points_recursive()

fit_points_recursive(points: collections.abc.Sequence[types.Point3D], tolerance: float, start_idx: int, end_idx: int) -> list[list[float]]

Recursively fit points with line and arc primitives.

Returns: List of fitted command rows.

ParameterTypeDescription
pointscollections.abc.Sequence[types.Point3D]Sequence of 3D points to fit.
tolerancefloatFitting tolerance.
start_idxintStart index in the points array.
end_idxintEnd index in the points array.
Returnslist[list[float]]

fit_points_with_primitives()

fit_points_with_primitives(points: collections.abc.Sequence[types.Point3D], tolerance: float) -> list[list[float]]

Fit a polyline of points with arc and line primitives.

Returns: List of fitted command rows.

ParameterTypeDescription
pointscollections.abc.Sequence[types.Point3D]Sequence of 3D points to fit.
tolerancefloatFitting tolerance.
Returnslist[list[float]]

flatten_to_points()

flatten_to_points(data: collections.abc.Sequence[collections.abc.Sequence[float]], tolerance: float) -> list[list[types.Point3D]]

Flatten curves into linear segments.

Returns: List of flattened point segments.

ParameterTypeDescription
datacollections.abc.Sequence[collections.abc.Sequence[float]]Array of command data.
tolerancefloatFlattening tolerance.
Returnslist[list[types.Point3D]]

get_polyline_arc_deviation()

get_polyline_arc_deviation(points: collections.abc.Sequence[types.Point3D], center: types.Point, radius: float) -> float

Get the maximum arc deviation for a set of points.

Returns: Maximum deviation from the arc.

ParameterTypeDescription
pointscollections.abc.Sequence[types.Point3D]Sequence of 3D points.
centertypes.PointArc center (x, y).
radiusfloatArc radius.
Returnsfloat

get_polyline_line_deviation()

get_polyline_line_deviation(points: collections.abc.Sequence[types.Point3D], start: int, end: int) -> tuple[float, int]

Get the maximum line deviation for a segment of a polyline.

Returns: Tuple of (max_deviation, index_of_max).

ParameterTypeDescription
pointscollections.abc.Sequence[types.Point3D]Sequence of 3D points.
startintStart index.
endintEnd index.
Returnstuple[float, int]

linearize_geometry()

linearize_geometry(data: collections.abc.Sequence[collections.abc.Sequence[float]], tolerance: float) -> list[list[float]]

Linearize geometry data into line segments.

Returns: List of linearized segment rows.

ParameterTypeDescription
datacollections.abc.Sequence[collections.abc.Sequence[float]]Array of command data.
tolerancefloatLinearization tolerance.
Returnslist[list[float]]

project_circle_center_to_bisector()

project_circle_center_to_bisector(p1: types.Point2DOr3D, p2: types.Point2DOr3D, center: types.Point) -> types.Point

Project a circle center onto the perpendicular bisector of two points.

Returns: Projected center point (x, y).

ParameterTypeDescription
p1types.Point2DOr3DFirst point (x, y) or (x, y, z).
p2types.Point2DOr3DSecond point (x, y) or (x, y, z).
centertypes.PointCircle center to project.
Returnstypes.Point