Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GetNearestPointTf
#1
Hi there. I have a problem with GetNearestPointTf. The point is that i have object with 2 child, between them i create a spline (lets name it A). After that, i need to check every spline crossing my A spline. I found the method GetNearestPointTf, but i cant find what i need. In addition, i can say that i have many of those objects. Can u please give me some hint, or maybe say what im doing wrong.
Code:
GameObject spline = new GameObject("CurveLine", typeof(CurvySpline), typeof(LineRenderer), typeof(CurvyLineRenderer));
                spline.GetComponent<>(CurvySpline).Add(firstObject.transform.position, secondObject.transform.position);
                float step = 2f;
                Vector3 position = firstObject.transform.position;
                while (position.z < secondObject.transform.position)
                {
                    Vector3 inversePositionOnSpline = spline.transform.InverseTransformPoint(position);
                    float nearestTf = spline.GetComponent<CurvySpline>().GetNearestPointTF(inversePositionOnSpline);
                   
                    Vector3 positionForSphere = spline.transform.TransformPoint(spline.GetComponent<CurvySpline>().Interpolate(nearestTf));
                    GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    sphere.transform.position = positionForSphere;
                    position.z += step;
                }
Reply
#2
Hi,
What version of Curvy Splines are you using?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
In the following line:
spline.GetComponent<>(CurvySpline).Add(firstObject.transform.position, secondObject.transform.position);
the Add method takes local positions, and you are feeding it with global positions.

I would recommend you to use Curvy 7 or newer, and use the methods (Add, GetNearestPointTF, ...) that have an additional parameter called space and that allows you to define whether the input/output is in the local space or global one.

Also, instead of writing:
float nearestTf = spline.GetComponent<CurvySpline>().GetNearestPointTF(inversePositionOnSpline);
Vector3 positionForSphere = spline.transform.TransformPoint(spline.GetComponent<CurvySpline>().Interpolate(nearestTf));
You can write
float nearestTf = spline.GetComponent<CurvySpline>().GetNearestPointTF(inversePositionOnSpline, out Vector3 positionForSphere);
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#4
The previous post was just a correction of your code. About the actual solution for your problem:
1- is your spline A a simple line?
2- are all splines in the same plane?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
(09-27-2020, 05:32 PM)_Aka_ Wrote: The previous post was just a correction of your code. About the actual solution for your problem:
1- is your spline A a simple line?
2- are all splines in the same plane?

1 - Yes, spline A a simple line
2 - All splines in same plane. 
The main what i need is find cross of splines and how i read in documentation, its not possible with GetNearestPointTf. Or i am wrong with it?
Reply
#6
GetNearestPointTf gets you the nearest point on a spline from a specific point. There is no implementation of splines' intersection algorithms in Curvy Splines for now. Those algorithms can be more or less complex depending on the type of splines. This can be a good starting point
https://stackoverflow.com/questions/4039229/checking-if-two-cubic-b%c3%a9zier-curves-intersect#4041286
Did this help?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#7
(09-27-2020, 11:11 PM)_Aka_ Wrote: GetNearestPointTf gets you the nearest point on a spline from a specific point. There is no implementation of splines' intersection algorithms in Curvy Splines for now. Those algorithms can be more or less complex depending on the type of splines. This can be a good starting point
https://stackoverflow.com/questions/4039229/checking-if-two-cubic-b%c3%a9zier-curves-intersect#4041286
Did this help?

Yea, it will help. Thank you for help!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Looping splines and GetNearestPointTF Sacryn 1 209 10-13-2021, 02:07 PM
Last Post: _Aka_

Forum Jump: