Created
May 21, 2017 03:33
-
-
Save thobroni/c887387491625592c73bfd6d2f9c1dca to your computer and use it in GitHub Desktop.
Python number mapping
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