Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Partial curve
#1
Hello all,
 
I'm trying to build a partial curve from an existing one.Is there an easy way using your library, to get a partial spline of an original one with an offset with tf , but preserving the shape/spline to match the original shape ( but be partial ).
In other words , is there a method that can give me a new spline if i say tf is 0.5 , to return me an exact copy of the original spline but just half of it( or whatever value i pass ).

I already tried to do it manually, but faced problems recalculating the new control points of the newly inserted middle point.
 
Already checked the method SplitSpline and the InterpolateBezierHandles inside the CurvyUtility class, but I don't think they are usefull enough for me. Checked the source code of the InterpolateBezierhandles method, but it's not suiting my needs. The SplitSpline is also not exactly what i want , because if I have a segment long enough ( or a spline with huge length and only two points ), I'll never be able to split it in half with this method.
 
I know how to do this in 2d manually , but facing issues when trying to do it manually for 3d. It's fine for me to have a slight/small error that comes from converting a quadratic bezier to a cubic one( that's how I'll do it in 2d ).
 
Maybe a hidden helper method that you are using somewhere else that i can reuse or maybe i missed something in the documentation ?

Thanks ...

 
Reply
#2
The results depend on the spline type. If you use CR (the default), you should create a new curve with AutoCP disabled, so you are able to move the very first and last CP. If you set them to the positions they would have in your iroriginal spline, results should be the same. For Bezier curves it should be even easier.

Jake
Reply
#3
Hi Jake .. Thanks for replying.
I somehow tried your suggestion, but it doesn't seem to work for me. Also I couldn't find anywhere in the docs the autoCP you mentioned. Maybe I'm doing somethiing wrong.


Code:
void split(){
 
 if( lineSrc && lineSrc.Length > 0 ) Debug.Log( lineSrc.Length.ToString () );
 else return;
 
 clonePath( lineSrc , 0.7f );

}

CurvySpline clonePath( CurvySpline source , float tf ){

 CurvySpline clone = CurvySpline.Create( source );
 // clone.AutoCp = false; // can't find it in the docs

 Vector3 points = new Vector3[ source.ControlPoints.Count ];
 for (int i = 0; i < source.ControlPoints.Count; i++)
   points [i] = source.ControlPoints [i].Position;

 clone.Add( points );
 clone.RefreshImmediately();
 return clone;

}[/i][/i]
[i]By executing this code ( and if I was able to set autoCP ) I should get an exact clone according to your guidance , but I don't. See result.jpg attached.

However I'm not sure if you understood me in the first place ( also attached another schematic to make it visual ). I want to take spline AB( having just 2 points A & B ). Clone it, and then move point B to a newly interpolated position from the original spline. Can move point B or create a new one C , doesn't matter. But then I want the control points of point B ( mean the handles ), to be repositioned so that the shape stays exactly the same as the original( well.. the part we are cloning not the whole of teh original shape) . So if i set a clone with tf = 0.3 only 0.3 ( 30% ) of it will be cloned preservving the shape.

The problem lies within the position of the handles. They have to be repositioned/interpolated aswell. Both handles A-OUT & B-IN ( or C-IN ) should be repositioned in order to keep the shape the same. No problem for handle A-OUT ( Already did this one ). Only C-IN ( B-IN ) is the problem for me right now.

Can I do it easily with your lib( maybe some hidden or undocumented method ) or I should calculate it myself ?
Btw .. All of the types suit my needs ( prefer using beziers ).

Thanks again.
[/i]


Attached Files Thumbnail(s)
       
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  snap to the curve created by the curvy splines segment points ShiroeYamamoto 3 11 04-02-2024, 02:24 PM
Last Post: _Aka_
  Can Curve Spline be used for an in game level editor. Lupos 30 71 06-03-2023, 10:58 AM
Last Post: _Aka_
Bug Extrusion and scale curve issues Sacryn 3 15 04-08-2022, 12:30 PM
Last Post: _Aka_
  Autogenerate bezier curve with a given direction AnAsianPanda 3 554 08-06-2021, 09:08 AM
Last Post: _Aka_

Forum Jump: