User Information:

Cinema 4D Version: R14 Stud

Platform: Mac OSX ;

Language(s) : C++ ;

---------

I need to calculate the distance from a point to the closest point on a spline. This process must be performed repeatedly so I was wondering about the SplineHelper which, after initial setup, is quite quick I understand.

Does anyone have any suggestions how to go about this? I could iterate along the spline checking the distance to my original point but that seems somewhat inefficient as a technique. The answer needs to be reasonably accurate however some margin of error is acceptable for the planned usage.

I suspect that there are methods in the SDK which would help. I'm having trouble knowing where to look...

]]>Thanks for your respective responses.

In case anyone else is searching in future for similar information, here's some extra information which has since come to light...

I also located another thread on a similar theme. You can find that here:

https://plugincafe.maxon.net/topic/4151/3694_get-nearest-point-on-spline

Kuroyume0161's code sample gives a way of iterating the spline segments and testing each in turn for its distance to a point. Looking at the documentation on PointLineDistance() it would seem to be possible to replace Robert's DistanceSegmentSphere() function, however that function does not return the nearest point along the line as well as the closest distance. It therefore comes down to what information you need.

In my case the distance alone is enough but for others I suggest reading Robert's code.

]]>PointLineDistance()

]]>in the xpresso node presets is a coffee preset to calculate the closest point on a spline. i am not

aware of any built in methods in the sdk that can do that, but i am not very comfortable with the

cpp sdk, so i might be wrong. you can find the coffee node in the xpresso presets down in the

advanced group.

if you really have speed up the process you could calculate the two closest control points and then

get between those control points a predefined set of subdivision steps. like taking for example two

subdivisions per 100 world units between these points, take the two closest points out of that list

and calculate the closest point on that line (c4d_utils offers a method for that). then you have just

to calculate the length of the subdivision segments to that point and get the the vector for that

spline offset. that would decrease the number of needed iterations drastically compared to the

coffee node approach.