I am currently on vacation, so for simplicity, I will explain with a curve example:
How to Describe a Curve?
To describe a curve in physical space, you discretize your parametric space, which ranges from 0 to 1. These points are saved in X_{t}. Then you map these points X_{t} to physical space, and you can visualize your curve in physical space with coordinates X_{g}. (For simplicity, I didn’t draw the control points X_{c}.)
If the resolution is low (i.e., the number of discrete points in parametric space X_{t} is small), your curve will have a low resolution and appear as a set of lines. If you increase the resolution (i.e., increase the number of discrete points in parametric space \hat{X}_{t}), you can draw your curve with more points, resulting in a better resolution \hat{X}_{g}.
(Both curves X_{g} and \hat{X}_{g} are the same but drawn with different resolutions.)
The Idea Behind nearest_point()
:
Now, let’s say you have a point P and you want to find the closest point on the curve. The nearest_point()
function compares the coordinates of point P with the coordinates of X_{gi} and finds the closest point on the curve. If your resolution is low, the accuracy of finding the closest point is reduced. If you increase the resolution, the accuracy will improve.
To call the function:
call curve%nearest_point(P, nearest_Xg, nearest_Xt, id)
Here, you provide the coordinates of point P. Depending on the resolution of your curve, the nearest_point()
subroutine finds the nearest X_{gi} on the curve and gives the corresponding parametric coordinates X_{ti} and the id of this point (i). For instance, in this example, for the finest curve, the id of the closest point on the curve is 2.
This is an approximated solution that depends on the discretization. It is also possible to find the exact point, but this feature is not yet implemented in ForCAD.