Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Closest Spline & control points loop in both directions
#9
Please look at the screenshot below. I cannot understand why is this happening. 
I am getting the nearest segment, and then I try to get next and previous control point. Next one is represented by green sphere, and previous is yellow sphere. 

Notice what is happening when input world position is exactly at first CP position (CP0000).

[Image: IinsYhT.gif]

Code:
public override void DrawGizmos () {

            if (GizmoContext.InSelection(this))
            {
                var nearestPointTf = spline.GetNearestPointTF(transform.position, out var output, out var nearestSegment, out var nearestPointLocalF, 0, -1, Space.World);
                Draw.WireSphere(output, 0.5f, Color.black);
           
                var nextControlPoint = spline.GetNextControlPoint(nearestSegment);
                Draw.WireSphere(nextControlPoint.transform.position, 0.4f, Color.green);
           
                var prevControlPoint = spline.GetPreviousControlPoint(nearestSegment);
                Draw.WireSphere(prevControlPoint.transform.position, 0.4f, Color.yellow);   
            }
        }

Basically i would like to traverse all the controlpoints in both directions starting from any given world position.

Also, nearestSegment is also giving me inconsistent results. 

black sphere: nearest point on a spline
blue sphere: nearest segment
yellow sphere: previous control point from closest segment
green shpehe: next control point from closest segment
transform handle: world point that I am using to calculate everything


[Image: 2tNXnQI.png]
[Image: Ymko2eR.png]
[Image: NWhHUKV.png]
Reply


Messages In This Thread
RE: Beginner's questions - Closest spline & closest point on spline - by nehvaleem - 01-29-2021, 02:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Spline Spots from 2 samples. BitBlit 8 654 06-30-2026, 11:49 AM
Last Post: _Aka_
  Best way to duplicate a spline with an offset Kapistijn 8 2,067 04-12-2026, 03:18 PM
Last Post: _Aka_
  Control Point Interpolation Overrides. rickgplus 1 739 12-11-2025, 08:52 AM
Last Post: _Aka_
Smile Constant speed along a spline? tfishell 1 867 11-13-2025, 11:32 AM
Last Post: _Aka_

Forum Jump: