Last active
August 29, 2015 14:15
-
-
Save TechplexEngineer/18ec1370df5f338c7f58 to your computer and use it in GitHub Desktop.
map a number from one range to another
This file contains hidden or 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
| /** | |
| * map a number from one range to another | |
| * @param {num} value the value to be mapped | |
| * @param {num} old_min the minimum of value | |
| * @param {num} old_max the maximum of value | |
| * @param {num} new_min the new minimum value | |
| * @param {num} new_max the new maximum value | |
| * @return {num} the value remaped on the range [new_min new_max] | |
| */ | |
| public double map(double value, double old_min, double old_max, double new_min, double new_max) { | |
| return (value - old_min) / (old_max - old_min) * (new_max - new_min) + new_min; | |
| } |
This file contains hidden or 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
| /** | |
| * map a number from one range to another | |
| * @param {num} value the value to be mapped | |
| * @param {num} old_min the minimum of value | |
| * @param {num} old_max the maximum of value | |
| * @param {num} new_min the new minimum value | |
| * @param {num} new_max the new maximum value | |
| * @return {num} the value remaped on the range [new_min new_max] | |
| */ | |
| function map(value, old_min, old_max, new_min, new_max) { | |
| return (value - old_min) / (old_max - old_min) * (new_max - new_min) + new_min; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment