# Question CurveUtility Documentation

Discussion in 'Documentation' started by axelstewart, Aug 24, 2023.

1. ### axelstewart

Joined:
May 17, 2018
Posts:
8
Hi!
I'm looking to do some pretty specific stuff with splines, and part of that is getting the closest point to a spline very rapidly. I have a few other options than this, but the main function that I'm looking at using is CurveUtility.GetNearestPoint().

Unfortunately, I can't find any documentation on this function, and instead of using a float3 or Vector3 for the point, it uses a Ray. Maybe I'm feeble of imagination, but I can't understand why a Ray is used, and which way - is the direction of the ray used, or just the location?

In any case, I would love to see any documentation of this function, or an explanation of its behavior, and that failing, I would appreciate any guesses as to why it uses a Ray and how that information is processed.

JonathanMeaney likes this.
2. ### Baste

Joined:
Jan 24, 2013
Posts:
6,224
I'm pretty sure that's the function used to decide which spline part is closest to your mouse, to implement clicking on the spline. It uses a ray instead of a point in order to (I assume) support clicking on a spline that's not drawn orthogonally to the screen. So the direction is very much used.

### Unity Technologies

Joined:
Jun 8, 2020
Posts:
144
Hi @axelstewart,

It seems the function you are looking for is SplineUtility.GetNearestPoint and not the one from CurveUtility:
https://docs.unity3d.com/Packages/c...t3__System_Single__System_Int32_System_Int32_

As @Baste was saying the methods using a ray are mainly to facilitate ray tracing and spline selection using a mouse.
You were looking at CurveUtility, a curve is only one segment of the spline (between 2 consecutive knots) and not the entire spline itself. That's why SplineUtility would be a better place to look for you

Moreover, you can have a look at the sample scene called "Extrude Spline and Nearest Point" in the package examples.
This sample is using that utility method and shows how to do it via the provided scripts.

Hope this help! Have a good day.

JonathanMeaney likes this.
4. ### axelstewart

Joined:
May 17, 2018
Posts:
8
Hi @Baste & @ThomasLopez, sorry that I missed your responses, which I appreciate.

I was specifically looking at the curve utility one because I knew which Bezier curves I needed to compare to and there were curves that I specifically did not want to compare to - close in space but far in spline traversal. This is in addition to the performance concerns - I was working with a procedurally-generated spline that could have arbitrarily high numbers of knots, and making MANY calls.

It makes sense that the method would be for clicking on it or raytracing, but again the lack of documentation meant that I wasn't able to use it.

I've since abandoned splines entirely and designed a solution using circle arcs and straight lines - not the same thing, but better for my purposes anyway, and very fast to find the closest point on.