I have met some funny code, and some result has let me muddled.
let p1 = new THREE.Vector3(20, 0, 0);
let p2 = new THREE.Vector3(0, 0, 0);
let curve = new THREE.CatmullRomCurve3([p1, p2]);
let progress = curve.getUtoTmapping(0, 2);
let half = curve.getPoint(0.5);
let half_2 = curve.getPointAt(0.5);
console.log(progress, half, half_2)
I think the log will show progress = 0.1, half and half_2 will be {x=10, y=0, z=0} before I run the code. But the log show progress = 0.23823764849028212, half = {x: 12.5, y: 0, z: 0}, half_2={x: 10.000024823603106, y: 0, z: 0}
So I have change the code below
let p1 = new THREE.Vector3(20, 0, 0);
let p2 = new THREE.Vector3(0, 0, 0);
let line = new THREE.LineCurve3(p1, p2);
let curve = new THREE.CurvePath();
curve.curves.push(line);
let progress = curve.getUtoTmapping(0, 2);
let half = curve.getPoint(0.5);
let half_2 = curve.getPointAt(0.5);
console.log(progress, half, half_2)
The result is printed the same as my expectation. progress = 0.1, half = half_2 = {x=10,y=0,z=0}.
Why the CatmullRomCurve3 getUtoTmapping
is not return the correct progress?
And what’s the difference between getPoint
and getPointAt