Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if I want to get x by y? #38

Closed
luther-nwpu opened this issue Jan 14, 2020 · 3 comments
Closed

if I want to get x by y? #38

luther-nwpu opened this issue Jan 14, 2020 · 3 comments

Comments

@luther-nwpu
Copy link

I need this function。

@gre
Copy link
Owner

gre commented Jan 14, 2020

There is not a single solution to this problem, bezier curve is not a bijection.

That said, it only happens when one of the handle goes out of [0,1] on the y axis.

So what you can do is simply switch x and y of the bezier parameter and I think you get the reverse function

@housseynCheriet
Copy link

Best explanation of easing function
https://www.selectionjs.com/animation

@gre gre closed this as completed Sep 30, 2020
@zikaari
Copy link

zikaari commented Aug 17, 2023

I also need to resolve x from y.

So what you can do is simply switch x and y of the bezier parameter and I think you get the reverse function

I tried but no luck, do I also need to invert/adjust some other parameters?

EDIT

Looked at the the code more closely - just need to swap the position of first 2 arguments and last 2 arguments to bezier function and then call the returned function with the y that you need the x for.

// resolve y
const interpolate = bezier(0.4, 0, 0.6, 1)

// resolve x
const uninterpolate =  bezier(0, 0.4, 1, 0.6)

const x = 0.25
const y = interpolate(x)

uninterpolate(y) === x  // true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants