Howdy everybody!
I’m utilizing Cocos Creator model 3.8.6.
Let’s take a curve like this:
Within the code we are going to designate the factors:
let p1 = new Vec2(0, 0);
let p2 = new Vec2(0.2, 0.9);
let p3 = new Vec2(-0.3, 1.1);
let p4 = new Vec2(1, 1);
I want to seek out the worth on the Y axis alongside the X axis. It appeared to me that the bezierByTime operate is only for this. Let’s attempt:
let print = (time: quantity): void => {
let x = bezierByTime([p1.x, p2.x, p3.x, p4.x], time);
let y = bezierByTime([p1.y, p2.y, p3.y, p4.y], time);
console.log(`Information: time = ${time}, x = ${x}, y = ${y}`);
}
print(0);
print(0.5);
print(1);
Outcome:
Information: time = 0, x = 0.5392914419011516, y = 1.0008218952905403
Information: time = 0.5, x = 0.9466027294712621, y = 0.8171128492397636
Information: time = 1, x = 1, y = 1
At the least for 1 the whole lot matched. What am I doing fallacious?
We will assume that t is returned, then write:
let print = (time: quantity): void => {
let tx = bezierByTime([p1.x, p2.x, p3.x, p4.x], time);
let ty = bezierByTime([p1.y, p2.y, p3.y, p4.y], time);
let x = bezier(p1.x, p2.x, p3.x, p4.x, tx);
let y = bezier(p1.y, p2.y, p3.y, p4.y, ty);
console.log(`Information: time = ${time}, x = ${x}, y = ${y}`);
}
Outcome:
Information: time = 0, x = 0.10493323646379052, y = 0.9997528236742361
Information: time = 0.5, x = 0.8067668699488855, y = 1.0223163437600014
Information: time = 1, x = 1, y = 1
And right here too the outcome isn’t right.