Skip to content

Instantly share code, notes, and snippets.

@chriswhocodes
Created October 5, 2013 10:23
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 chriswhocodes/6839214 to your computer and use it in GitHub Desktop.
Save chriswhocodes/6839214 to your computer and use it in GitHub Desktop.
Normalise a double in a range and scale to a dimension (with optional invert). Useful for chart scaling.
public static double normalise(double value, double min, double max, double size, boolean invert)
{
double range = max - min;
double result = 0;
if (range != 0)
{
result = (value - min) / range;
}
result *= size;
if (invert)
{
result = size - result;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment