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.
| Parameter | Type | Description |
|---|---|---|
points | Sequence[Point3D] | Sequence of 3D points. |
tolerance | float = 1e-06 | Collinearity tolerance. |
| Returns | bool |
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).
| Parameter | Type | Description |
|---|---|---|
end | Point3D | End point (x, y, z). |
center | Point | Center offset (dx, dy). |
start | Point3D | Start point (x, y, z). |
| Returns | list[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).
| Parameter | Type | Description |
|---|---|---|
end_point | Point3D | End point (x, y, z). |
| Returns | list[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.
| Parameter | Type | Description |
|---|---|---|
p1 | Point2DOr3D | First point (x, y) or (x, y, z). |
p2 | Point2DOr3D | Second point (x, y) or (x, y, z). |
p3 | Point2DOr3D | Third point (x, y) or (x, y, z). |
| Returns | Optional[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.
| Parameter | Type | Description |
|---|---|---|
points | Sequence[Point3D] | Sequence of 3D points to fit. |
| Returns | Optional[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.
| Parameter | Type | Description |
|---|---|---|
points | Sequence[Point3D] | Sequence of 3D points to fit. |
tolerance | float | Fitting tolerance. |
start_idx | int | Start index in the points array. |
end_idx | int | End index in the points array. |
| Returns | list[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.
| Parameter | Type | Description |
|---|---|---|
points | Sequence[Point3D] | Sequence of 3D points to fit. |
tolerance | float | Fitting tolerance. |
| Returns | list[list[float]] |