kipe.measurements.plane module
Fit sampled 3D coordinates to z = a*x + b*y + c for the plane measurement model.
fit_from_coordinates() performs an orthogonal least-squares fit using SVD;
orient_normal() selects the sign of its unit normal.
These utilities use NumPy arrays and do not require a finite element backend.
PlaneModel fits complete coordinate arrays and compares coefficients by subtraction.
Orientation tracking belongs to the plane model and is independent of coefficient values.
- class kipe.measurements.plane.Plane(coefficients: NDArray_f64, normal: NDArray_f64, centroid: NDArray_f64)[source]
Bases:
objectGeometry of an orthogonal least-squares plane fit.
All arrays have shape
(3,)and use the input coordinate system. Changing the normal’s sign does not change the coefficients or the geometric plane.- coefficients: NDArray_f64
[a, b, c]forz = a*x + b*y + c; slopes are dimensionless and c is a length.
- normal: NDArray_f64
Unit normal perpendicular to the fitted plane, with the selected orientation.
- centroid: NDArray_f64
Mean of the fitted vertices; the fitted plane passes through this point.
- kipe.measurements.plane.orient_normal(normal: NDArray_f64, centroid: NDArray_f64, *, normal_toward: tuple[float, float, float] | None = None, reference_normal: NDArray_f64 | None = None) NDArray_f64[source]
Select a normal’s sign without changing the plane or the input arrays.
With
reference_normal, choose the sign giving a positive dot product with that reference. Otherwise, ifnormal_towardis supplied, choose the side containing that point. With neither option, keep the fitted sign. No orientation history is stored.- Parameters:
normal – fitted unit normal, shape
(3,)centroid – fitted plane’s centroid, shape
(3,)normal_toward – optional point in the same coordinates and units as the centroid
reference_normal – finite nonzero normal, shape
(3,); takes precedence over the point, which is then ignored
- Returns:
a copy of
normal, multiplied by -1 if required; its magnitude is unchanged- Raises:
ValueError – if the reference normal or point has invalid dimensions or nonfinite entries, the reference normal is zero or perpendicular to the fitted normal, or the reference point lies on the plane, up to numerical tolerance
- kipe.measurements.plane.fit_from_coordinates(vertices: NDArray_f64, *, normal_toward: tuple[float, float, float] | None = None, reference_normal: NDArray_f64 | None = None) Plane[source]
Fit
z = a*x + b*y + cby minimizing squared perpendicular distances.Center the vertices at their centroid and use the least varying SVD direction as the plane normal. The fit treats all three coordinate directions equally; it does not minimize only vertical z residuals. Convert the normal and centroid to
[a, b, c]after selecting the normal’s sign withorient_normal().- Parameters:
vertices – finite 3D coordinates, shape
(n_vertices, 3); at least three noncollinear verticesnormal_toward – optional point on the desired side of the fitted plane, in the same coordinates and units as the vertices; must not lie on the fitted plane
reference_normal – normal with which to align the fitted normal; overrides the point
- Returns:
coefficients
[a, b, c], centroid and unit normal. Without a reference or point, the normal retains the SVD sign.- Raises:
ValueError – if the coordinates have the wrong shape, are nonfinite or collinear, do not determine a unique best-fit plane, or SVD fails. Also raised for vertical or nearly vertical planes that cannot be represented reliably by this equation, and for invalid or ambiguous orientation references (see
orient_normal()).
- class kipe.measurements.plane.PlaneOrientation(toward: tuple[float, float, float] | None = None)[source]
Bases:
objectOrientation history for one plane model, independent of other model instances.
- Parameters:
toward – optional reference point used only to orient the first fitted normal
- toward: tuple[float, float, float] | None = None
- reference: NDArray_f64 | None = None
- latest: NDArray_f64 | None = None
- record(plane: Plane) None[source]
Store the oriented normal and retain the first normal as the reference.
Use the optional point only when establishing the reference. Later normals align with that reference. The supplied plane is unchanged.
- Parameters:
plane – fitted geometry, before applying this history’s orientation reference
- Raises:
ValueError – if the reference point or first normal cannot determine an orientation
- class kipe.measurements.plane.PlaneModel[source]
Bases:
MeasurementModelPredict three plane coefficients from a complete array of sampled coordinates.
The first successful fit establishes an orientation reference, optionally directed toward a point. Subsequent normals align with that first normal. Orientation does not change the coefficients used for prediction or innovation.
- gather_input: ClassVar[bool] = True
Request a complete globally ordered input and prediction on root only.
False selects rank-local input and prediction.
- orientation: PlaneOrientation | None = None
Optional reference and latest oriented normal.
- property normal: NDArray_f64 | None
Copy of the latest oriented normal, or None before prediction or after failure.
None is also returned when orientation tracking is not configured. The first reference is not modified through this copy.
- clear_prediction() None[source]
Clear the latest normal without discarding the first orientation reference.
- layout(sampler: SpatialSampler) tuple[int, NDArray_i64][source]
Return size 3 and indices
[0, 1, 2], independently of the sampler.- Parameters:
sampler – accepted for the model interface; the output always has three entries
- Returns:
size 3 and indices
[0, 1, 2]
- predict(y: NDArray_f64) NDArray_f64[source]
Fit the complete coordinate array and return
[a, b, c].Clear the latest normal before fitting and record the fitted normal when orientation tracking is configured.
- Parameters:
y – flattened coordinates in vertex order,
x0, y0, z0, x1, y1, z1, ...- Returns:
three plane coefficients, independently of vertex count
- Raises:
ValueError – if the input cannot be reshaped to 3D points, cannot define a supported plane, or the orientation reference is ambiguous