distances
DistanceEngine
DistanceEngine()
DistanceEngine distance computation between a point and a curve in 3D space.
It uses a defined plane for the distance calculation. The plane is defined by a span frame, which is determined by two points (start and end of the span). The engine allows to add curves and span frames, and then compute the distance from a given point to the curve along the plane defined by the span frame. The result is returned as a DistanceResult object containing the distance information and projection details.
Examples:
1 2 3 4 | |
Source code in src/mechaphlowers/core/geometry/distances.py
182 183 | |
axis_points
property
axis_points: ndarray
Return the axis points as a numpy array of shape (2, 3) containing the start and end points of the span frame.
add_curves
add_curves(curve_points: ndarray)
add curves to the engine, which will be used for distance calculations. The curves are defined by their points in 3D space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
A numpy array of shape (N, 3) representing the points of one or more curves in 3D space, concatenated along the first dimension. |
required |
Source code in src/mechaphlowers/core/geometry/distances.py
185 186 187 188 189 190 191 | |
add_span_frame
add_span_frame(x_axis_start: ndarray, x_axis_end: ndarray)
Add a span frame to the engine, which will be used for distance calculations.
The span frame is defined by its X axis start and end points in 3D space. This frame will be used to define the plane for distance calculations, with the normal vector of the plane being vertical (Z direction) and the other two basis vectors defined in the XY plane along the span direction and perpendicular to it.
Warning - Z is always oriented upwards, which is important for the distance calculations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
A numpy array of shape (3,) representing the start point of the span frame. |
required |
|
ndarray
|
A numpy array of shape (3,) representing the end point of the span frame. |
required |
Source code in src/mechaphlowers/core/geometry/distances.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
define_distance_plane
Define the distance plane based on a given point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
A numpy array of shape (3,) representing the point from which the distance plane belongs. This point will be used as the origin of the plane, and the plane will be defined with a normal vector vertical to the span frame (Z direction) and two basis vectors in the XY plane. |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
A tuple containing the basis vectors of the plane (u_plane, v_plane). |
Source code in src/mechaphlowers/core/geometry/distances.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
DistanceResult
DistanceResult(
point_base: ndarray,
point_target: ndarray,
u_plane: ndarray,
v_plane: ndarray,
distance_3d: float,
distance_projection_u: float,
distance_projection_v: float,
)
Source code in src/mechaphlowers/core/geometry/distances.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
get_projection_points
get_projection_points(
origin_point: ndarray,
projection_u: float,
projection_v: float,
u_plane: ndarray,
v_plane: ndarray,
) -> tuple[ndarray, ndarray]
Calculate the projection points on the plane basis vectors from an origin point and the projections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
The original point in 3D space from which projections are calculated (numpy array of shape (3,)). |
required |
|
float
|
The scalar projection distance along the u_plane basis vector. |
required |
|
float
|
The scalar projection distance along the v_plane basis vector. |
required |
|
ndarray
|
The first basis vector of the plane (numpy array of shape (3,)). |
required |
|
ndarray
|
The second basis vector of the plane (numpy array of shape (3,)) |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
A tuple containing the projection points on the plane basis vectors (u_projection_point, v_projection_point). |
Source code in src/mechaphlowers/core/geometry/distances.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
points_distance_inside_plane
points_distance_inside_plane(
point_base: ndarray,
point_target: ndarray,
u_plane: ndarray,
v_plane: ndarray,
) -> tuple[float, float, float]
Compute the distance between two points in 3D inside a plane.
The plane is defined by its basis vectors u_plane and v_plane, which are orthogonal and normalized. The function compute 3D distance between the two points, as well as the projections of this distance onto the plane basis vectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
The first point in 3D space (numpy array of shape (3,)). |
required |
|
ndarray
|
The second point in 3D space (numpy array of shape (3,)). |
required |
|
ndarray
|
The first basis vector of the plane (numpy array of shape (3,)). |
required |
|
ndarray
|
The second basis vector of the plane (numpy array of shape (3,)). |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float, float]
|
A tuple containing the 3D distance and the projections onto the plane basis vectors (distance_3d, distance_projection_u, distance_projection_v). |
Source code in src/mechaphlowers/core/geometry/distances.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
planes
change_local_frame
change_local_frame(
local_frame_origin: ndarray,
local_frame_x_axis: ndarray,
local_point: ndarray,
) -> ndarray
change_local_frame transforms local coordinates defined by an origin and a span direction into absolute coordinates in the global frame.
The local frame is defined such that:
- The origin is the reference point in the global frame.
- The x-axis is aligned with the span direction projected onto the XY plane.
- The y-axis is perpendicular to the x-axis in the XY plane counterclockwise.
- The z-axis is vertical (same as global Z).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
Starting point of the span in global coordinates (3D). |
required |
|
ndarray
|
Ending point of the span in global coordinates (3D). |
required |
|
ndarray
|
Local coordinates of the point to transform (3D). |
required |
Returns: Absolute coordinates of the point in the global frame (3D).
Source code in src/mechaphlowers/core/geometry/planes.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
compute_plane_normal
compute_plane_normal(key_points: ndarray) -> ndarray
Compute plane normal from two key points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ndarray
|
Array of shape (2, 3) defining start and end of line. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Direction vector from first to second point. |
Source code in src/mechaphlowers/core/geometry/planes.py
101 102 103 104 105 106 107 108 109 110 | |
line_function_from_2_points
Returns a function that represents the line defined by two points p1 and p2 in 3D space.
The returned function takes a scalar parameter t and returns the point on the line corresponding to that parameter.
Source code in src/mechaphlowers/core/geometry/planes.py
86 87 88 89 90 91 92 93 94 95 96 97 98 | |
parametric_line_from_2_points
parametric_line_from_2_points(
p1: ndarray, p2: ndarray
) -> tuple[ndarray, ndarray, ndarray]
Returns the coefficients of the line defined by two points p1 and p2 in 3D space.
The line is represented in parametric form as: L(t) = p1 + t * line_direction_normalized
where t is a scalar parameter and line_direction_normalized is the normalized direction vector of the line.
Source code in src/mechaphlowers/core/geometry/planes.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |