-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
MathUtils: Added .inverseLerp(). #21544
Conversation
We should consider to implement the method like in Unity. If you do this: const t = MathUtils.inverseLerp( 2, 2, 2 ); The method returns inverseLerp: function ( a, b, value ) {
if ( a !== b ) {
return MathUtils.clamp( ( value - a ) / ( b - a ) );
} else {
return 0;
}
} |
Resolved |
Update variable names to match `lerp()`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrdoob This looks good to me.
I can enhance the docs and unit tests with a subsequent PR.
I think it's a valid use case. I wouldn't want it to focus too much on games but I'm interested in making it easier for people to do games with it: |
Thanks! |
Description
Calculates the linear parameter t that produces the interpolant value within the range [a, b]. The a and b values define the start and end of the line.
https://www.gamedev.net/tutorials/programming/general-and-gameplay-programming/inverse-lerp-a-super-useful-yet-often-overlooked-function-r5230/ for more information and to why its useful
This contribution is funded by Hoodgail.