Created
May 21, 2017 03:34
-
-
Save thobroni/2f3ab90e7f8b79bbfc3981a6cf573bf3 to your computer and use it in GitHub Desktop.
Python number mapping, taken from : http://stackoverflow.com/a/1969274
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
def mapping(value, leftMin, leftMax, rightMin, rightMax): | |
# Figure out how 'wide' each range is | |
leftSpan = leftMax - leftMin | |
rightSpan = rightMax - rightMin | |
# Convert the left range into a 0-1 range (float) | |
valueScaled = float(value - leftMin) / float(leftSpan) | |
# Convert the 0-1 range into a value in the right range. | |
return rightMin + (valueScaled * rightSpan) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment