Distances computation
Definition
In the context of mechaphlowers, distances between a point and a curve do NOT refer to the measurement of the shortest path between a point and a line (span or section) in 3D space.
In order to compute distances, we first define a plane containing the point. This plane is defined by the point and a normal vector.
We take the normal vector as the direction of 2 foot points "sea level" to keep a vertical Z-axis.
Computation steps
The process of computing distances is then as follows:
- Define the plane based on the point and the normal vector.
- Compute the intersection of the plane with the curve (span or section).
- Compute the distance from the point to the intersection point on the curve in the plane.
- Compute the projection of the distance vector onto the plane basis vectors to get the distance components in the plane.
Intersection of plane and curve
The intersection of the plane and the curve is computed using the intersection_curve_plane function, which takes the curve points, plane point, and plane normal as inputs and returns the intersection point on the curve.
The function calculates the 2 nearest points on the curve. Then it uses a linear interpolation to find the intersection point on the curve.
How to use it
Distance engine
The simplest way to compute distances is to use the DistanceEngine class, which encapsulates all the steps of the distance computation process.
You can create an instance of the DistanceEngine class by providing the axis start and end points, add a curve and get the distance with an input point.
1 2 3 4 5 6 7 8 9 10 | |
You can also visualize your setup and the distance result using the plot_distance_engine function from mechaphlowers.plotting.plot_distances:
1 2 3 4 | |
Distance result
The DistanceResult class is used to store the results of the distance computation. It contains the following attributes:
point_base: The input point from which the distance is computed.point_target: The intersection point on the curve.u_plane: The u-axis of the plane.v_plane: The v-axis of the plane.distance_3d: The 3D distance from the point to the curve.distance_projection_u: The distance from the point to the curve projected onto the u-axisdistance_projection_v: The distance from the point to the curve projected onto the v-axis
Plot engine
The PlotEngine class contains also method to compute and visualize distances.
This more complete object gives access to point_distance method to compute distances and visualize the setup upon the plot of a section for example.
1 2 3 4 5 6 7 8 9 10 | |