Skip to content

Instantly share code, notes, and snippets.

@rfzeg
Created May 1, 2019 02:56
Show Gist options
  • Save rfzeg/a4c7589a856ee50c5c4aad362fcaa4e6 to your computer and use it in GitHub Desktop.
Save rfzeg/a4c7589a856ee50c5c4aad362fcaa4e6 to your computer and use it in GitHub Desktop.
remap c++
#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