Aller au contenu principal

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: Sequence[Point3D], tolerance: float = 1e-06) -> bool

Check if three or more points are collinear within tolerance.

Returns: True if points are collinear.

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

create_arc_cmd()

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

Create an arc command array.

Returns: Arc command array (8 floats).

ParameterTypeDescription
endPoint3DEnd point (x, y, z).
centerPointCenter offset (dx, dy).
startPoint3DStart point (x, y, z).
Returnslist[float]

create_line_cmd()

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

Create a line command array from an end point.

Returns: Line command array (8 floats).

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

fit_circle_to_3_points()

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

Fit a circle to three points.

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

ParameterTypeDescription
p1Point2DOr3DFirst point (x, y) or (x, y, z).
p2Point2DOr3DSecond point (x, y) or (x, y, z).
p3Point2DOr3DThird point (x, y) or (x, y, z).
ReturnsOptional[tuple[Point, float]]

fit_circle_to_points()

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

Fit a circle to a set of points.

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

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

fit_points_recursive()

fit_points_recursive(points: Sequence[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
pointsSequence[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: Sequence[Point3D], tolerance: float) -> list[list[float]]

Fit a polyline of points with arc and line primitives.

Returns: List of fitted command rows.

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

flatten_to_points()

flatten_to_points(data: Sequence[Sequence[float]], tolerance: float) -> list[list[Point3D]]

Flatten curves into linear segments.

Returns: List of flattened point segments.

ParameterTypeDescription
dataSequence[Sequence[float]]Array of command data.
tolerancefloatFlattening tolerance.
Returnslist[list[Point3D]]

get_polyline_arc_deviation()

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

Get the maximum arc deviation for a set of points.

Returns: Maximum deviation from the arc.

ParameterTypeDescription
pointsSequence[Point3D]Sequence of 3D points.
centerPointArc center (x, y).
radiusfloatArc radius.
Returnsfloat

get_polyline_line_deviation()

get_polyline_line_deviation(points: Sequence[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
pointsSequence[Point3D]Sequence of 3D points.
startintStart index.
endintEnd index.
Returnstuple[float, int]

linearize_geometry()

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

Linearize geometry data into line segments.

Returns: List of linearized segment rows.

ParameterTypeDescription
dataSequence[Sequence[float]]Array of command data.
tolerancefloatLinearization tolerance.
Returnslist[list[float]]

project_circle_center_to_bisector()

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

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

Returns: Projected center point (x, y).

ParameterTypeDescription
p1Point2DOr3DFirst point (x, y) or (x, y, z).
p2Point2DOr3DSecond point (x, y) or (x, y, z).
centerPointCircle center to project.
ReturnsPoint