kjerandp / curve-interpolator

Interpolate values over a cubic Cardinal/Catmull-Rom curve
https://kjerandp.github.io/curve-interpolator/
MIT License
49 stars 6 forks source link

Get position of control points #22

Closed marcoqu closed 1 year ago

marcoqu commented 2 years ago

Hi Kjerand, very nice library. Thank you. I was wondering if there is any way to get the position (T, or U) of the control points used to create the curve itself. If I create a curve new CurveInterpolator([[0,0], [2,3], [7,9], [8,12]]) can I get the position on curve (0 - 1) of point [2,3]?

Thanks!

marcoqu commented 2 years ago

Wait, maybe I got it. Can I do it like this?

var ctrlPoints = [[0,0], [2,3], [7,9], [8,12]]
var c = new CurveInterpolator(ctrlPoints)

var Ts = ctrlPoints.map((_, i) => i / (ctrlPoints.length - 1));
var Us = Ts.map(t => getTtoUmapping(t, c.arcLengths));
kjerandp commented 1 year ago

Your assumption is correct - closing this.

kjerandp commented 1 year ago

In version 3.1.0 there's now a convenience method for getting the position (u) or time (u) given the index of a control point.

.getPositionAtKnot(u) .getTimeAtKnot(t)