spline position in meters

On 25/10/2013 at 10:18, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   r14
Platform:
Language(s) :     C++  ;

---------
Hi,
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

cheers,
Ello

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()

or

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();

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) :