Created
March 10, 2016 10:10
-
-
Save atika/f9ee912c8f701ea7cbf2 to your computer and use it in GitHub Desktop.
Remap/Convert a value from one range to another range (graph) in Swift
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
let high1 = 1000 | |
let low1 = 200 | |
let high2 = 250 | |
let low2 = 10 | |
let value = 200 | |
let remapedValue = low2 + (value - low1) * (high2 - low2) / (high1 - low1) | |
print(remapedValue) //-> 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment