Created
May 1, 2019 02:56
-
-
Save rfzeg/a4c7589a856ee50c5c4aad362fcaa4e6 to your computer and use it in GitHub Desktop.
remap c++
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
#include <iostream> | |
float remap(float fromValue, float fromMin, float fromMax, float toMin, float toMax) | |
{ | |
float fromAbs = fromValue - fromMin; | |
float fromMaxAbs = fromMax - fromMin; | |
float normal = fromAbs / fromMaxAbs; | |
float toMaxAbs = toMax - toMin; | |
float toAbs = toMaxAbs * normal; | |
float toValue = toAbs + toMin; | |
return toValue; | |
} | |
int main() { | |
std::cout << "Hello!\n"; | |
float cmd = remap(101, 100, 200, 0, 1.0); | |
std::cout << "Output value is: " << cmd << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment