Curve3D sample/samplef giving unexpected results

Godot Version

Godot 4.5.1.stable.mono

Question

I’m working with a Curve3D and I’m getting strange results from the sample() method. I made a test curve that’s just a straight line from (0,0,0) to (100,0,0), and tried evaluating several samples from that. As you can see, the sampling distance doesn’t correspond directly to the point I would expect (e.g. I would think sampling 0.33 should give the point (33,0,0), but instead it gives (25.483,0,0).

Am I misunderstanding something about how this method should work? sample_baked returns results as I would expect, i.e. sample_baked(45) gives the point (45,0,0).

For parametric cubic beziers, the parameter is not in linear relation with the length of arc. There will always be some mismatch. If the parameter goes from 0 to 1, and you sample at parameter 1/3, the length of arc at the sample won’t be 1/3 of total length. That’s one of the main weaknesses of bezier curves.

1 Like

Ahh I see, thanks for the clarification. So if I want to, say, get the point that is 33% of the distance along the curve, my best bet would be to do sample_baked(get_baked_length() / 3)?

Yes. sample_baked() takes actual length as an argument but is samples the curve tessellated into linear segments. So if you need precision, make sure your bake_interval is sufficiently small. For a straight segment like in your example it wouldn’t make much of a difference though.

1 Like