Created
March 19, 2015 16:37
-
-
Save krhoyt/fa2a1dc71eab10d5a671 to your computer and use it in GitHub Desktop.
Linear transform to map a value in one range to a value in another.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function scale( value, old_top, old_bottom, new_top, new_bottom ) | |
{ | |
// minTo + (maxTo - minTo) * ((value - minFrom) / (maxFrom - minFrom)) | |
return new_bottom + ( new_top - new_bottom ) * ( ( value - old_bottom ) / ( old_top - old_bottom ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment