spline position in meters
On 25/10/2013 at 10:18, xxxxxxxx wrote:
Cinema 4D Version: r14
Language(s) : C++ ;
i am trying to get real unit distances along a spline. this is what i've tried so far, in various combinations. but until now with no luck. i want to find a point on a spline which is for example 20meters from the start of the spline.
SplineLengthData* splLengthData = SplineLengthData::Alloc(); splLengthData->Init(baseSpline,0,NULL); if (!splLengthData) return false; SplineHelp* splHelp = SplineHelp::Alloc(); if (!splHelp) return false; splHelp->InitSpline(railSpline,Vector(0),0,false,true,false,true); Real rp0 = splHelp->GetOffsetFromReal(myOffset,0); //Vector p0=splHelp->GetPosition(rp0,0,true,true); Vector p0=splHelp->GetPosition(splLengthData->UniformToNatural(rp0),0,true,true);
hope someone can point me into the right direction.
PS: interesting thing is, that it seems to work with an arc-spline but not with a completely free defined spline
On 25/10/2013 at 11:13, xxxxxxxx wrote:
another thing i don't find is how to get the position (
0.0<=t<=1.0)of a spline point
On 25/10/2013 at 13:43, xxxxxxxx wrote:
offset = SplineHelp.GetOffsetFromUnit()
offset = myUnitOffset / SplineHelp.GetSplineLength()
for the last question you have to calculate the length of the spline up to that point in a linear
fashion (l = p0 + ... + pn , where p is a spline control point vector). and then operate with the
natural offset. feels a bit clumsy, but is at least the only way i do know.
On 28/10/2013 at 13:52, xxxxxxxx wrote:
ok, it's me again. i have now created a testplugin for just this purposes. and am getting strange values which i cannot handle.
SplineObject* spl = spline->GetRealSpline(); if (!spl) return false; SplineHelp* splHelp = SplineHelp::Alloc(); if (!splHelp) return false; splHelp->InitSpline(spl,Vector(0),NULL,false,true,false,true); SplineLengthData* splLengthData = SplineLengthData::Alloc(); Vector* padr = spl->GetPointW(); splLengthData->Init(spl,0,padr); Real length = splLengthData->GetLength(); GePrint("Length: "+RealToString(length)); Real targetLength = (length-offsetS-offsetE); GePrint("Target Length: "+RealToString(targetLength)); LONG count = 1; if (dist>0) count = int(targetLength/dist); GePrint("Number: "+LongToString(count));
for example if i draw a spline with points at (-300,0);(0,0);(0,300) this gives me proper values when the spline is type linear and no interpolation. if i change the type to bezier or whatever, the length changes (also the editor still displays the same spline) when i change interpolation, the length varies of course. but what bothers me is that different types (at interpolation none) give different length also they look absolutely the same in cinema.
any help is really appreciated as this is giving me quite some headache...
On 29/10/2013 at 02:03, xxxxxxxx wrote:
an example :
and as an example file (python tag rig on a spline object) :
On 29/10/2013 at 02:38, xxxxxxxx wrote:
i guess it is all right with my "strange" values, since cinemas project info panel (structure) gives me the same results. for example i have a spline (three points at -200,0 0,0 and 0,200) the length is 400 if type is linear. when i change to bezier, the length changes to 414.041 but the spline in the editor remains visually unchanged. i don't get this behaviour.
On 06/12/2013 at 23:19, xxxxxxxx wrote:
anyone ever found a working solution for all types off splines? for example to place an object exactly 5meters from the spline start, no matter if the spline is linear, bezier or whatever and no matter if some lines of it go straight and others are curved??