How to get spline offset by spline point index ?
-
hi,
How to get spline offset(0-1) by spline point index ? i want know offset between points to caculate the value points should be.
hope for your help! -
Hi Mike, thanks for writing us.
With regard to your question, if I properly understood you, you can use the SplineHelp Class and its SplineHelp::GetPosition() method to retrieve the spline's points value given a certain offset.
Something like this:
import c4d # Main function def main(): if op is None: return realSpline = op.GetRealSpline() if realSpline is None: return splineH = c4d.utils.SplineHelp() if splineH is None: return splineH.InitSpline(realSpline) samples = 10 for sample in range(0, samples): offset = float(sample) / samples print splineH.GetPosition(offset) # Execute main() if __name__=='__main__': main()
Best, Riccardo
-
Hi @r_gigante,
Thank you for replying. I'd like to know more about this topic: if I only know theControl Point Index
fromPointObject.GetPoint(id)
of a spline, how could I get theSpline Position
of this point? -
@r_gigante Thank you for your help! i have another problem that if i only know the spline point index ,how do i get the offset where point locate? just take sample like 1000 and find the nearest sample to the point position?or have faster way in SDK?
-
@eziopan For new questions please open a new thread. Thanks.
-
@mike What do you mean with "how do i get the offset where point locate?"
You want the offset for a point with a given index? The C++ version of SplineHelp has the function GetSplinePointSegment() which can be used to get the offset for a given index. Unfortunately, this function is not available in the Python API.
best wishes,
Sebastian -
@s_bach Thank you for your patient answer.
-
@s_bach thank you for your answer! I think I have the same question as mike do, so it has been solved now. Thank you again!
-
Hi,
Sorry to resurrect this old thread ...
As mentioned above GetSplinePointSegment() is not available in python
Is there no way at all to get to the (real)offset of a spline point with a given index ?spline --> point index --> offset? (in python)
index
-
nothing? ...
the only thing i can imagine is to sample the spline using splineHelp.GetPointIndex(), that would get you an initial offset range.
then you could start inserting points at certain offsets and refine the sampling down until a given offset range treshold is reached.
but thats quite complicated and slow as well, of coursemaybe somebody with a better idea how to approach this?
-
Hi nothing changed, in this regards, however I added GetSplinePointSegment on our internal Python parity list
But even when it will be available this will not be backported.Cheers,
Maxime. -
Thanks Maxime,
so GetPointIndex() is the only thing you can work with, I guess.
Already on it to create this sampling function ...
-
Hi @everyone,
as a little disclaimer, this is my private take on this topic.
Cinema does calculate the length of a spline (at least with
SplineHelp
) in a rather unpretentious fashion as the sum of the Euclidean norms of the underlyingLineObject
segments, i.e., there is no fancy arc-length calculation going on. Which makes sense in Cinema, since the discreteLineObject
is what does effectively count, and not the smoothSplineObject
. Since you can get access to theLineObject
of aSplineObject
and also convert betweenSplineObject
andLineObject
vertex indices withSplineHelp.SplineToLineIndex()
, this also means that you can both calculate the length of spline as a total and up to a specific vertex. Which then should mean that you can calculate the relative offset for a spline vertex yourself.Practically you can cut out the
SplineObject
altogether when sampling a spline and just use its associatedLineObject
. The one nice thing thatSplineHelp
does for you is though, that it implements a parallel transport for the frames of spline points for you. I.e., realizes that the normals of spline points point into a direction humans would consider "correct" (mathematically these normals are not correct, due to them being modified by parallel transport, but they will look smoother, won't flip when then curvature of the spline flips).Cheers,
Ferdinand