Skip to content

Instantly share code, notes, and snippets.

@LaptopHeaven
Created January 15, 2015 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LaptopHeaven/a280a94ec6f589bfc805 to your computer and use it in GitHub Desktop.
Save LaptopHeaven/a280a94ec6f589bfc805 to your computer and use it in GitHub Desktop.
C# method to map a value to a new scale. Requires the value, the current min and max values and the new min and max values.
public static double Map(double value, double fromMin, double fromMax, double toMin, double toMax)
{
return (value - fromMin) * (toMax - toMin) / (fromMax - fromMin) + toMin;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment