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]] |
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.
| Parameter | Type | Description |
|---|---|---|
data | Sequence[Sequence[float]] | Array of command data. |
tolerance | float | Flattening tolerance. |
| Returns | list[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.
| Parameter | Type | Description |
|---|---|---|
points | Sequence[Point3D] | Sequence of 3D points. |
center | Point | Arc center (x, y). |
radius | float | Arc radius. |
| Returns | float |
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).
| Parameter | Type | Description |
|---|---|---|
points | Sequence[Point3D] | Sequence of 3D points. |
start | int | Start index. |
end | int | End index. |
| Returns | tuple[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.
| Parameter | Type | Description |
|---|---|---|
data | Sequence[Sequence[float]] | Array of command data. |
tolerance | float | Linearization tolerance. |
| Returns | list[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).
| Parameter | Type | Description |
|---|---|---|
p1 | Point2DOr3D | First point (x, y) or (x, y, z). |
p2 | Point2DOr3D | Second point (x, y) or (x, y, z). |
center | Point | Circle center to project. |
| Returns | Point |