scaleConversion function

double scaleConversion(
  1. double ay,
  2. double yStart,
  3. double yEnd,
  4. double yMin,
  5. double yMax
)

Scale/Convert Y points from Array values to Pixels values, this is important to plot in the correct position and keep the values set proportions.

References

  1. "Comparison Between Celsius and Fahrenheit Scales". http://www.pstcc.edu/nbs/WebPhysics/Chapter12.htm. Retrieved 2021-03-01.

Implementation

double scaleConversion(
    double ay, double yStart, double yEnd, double yMin, double yMax) {
  // http://www.pstcc.edu/nbs/WebPhysics/Chapter12.htm
  // (- yEnd + yPoint) / (yEnd - yStart) = (yMin - ay[i]) / (yMax - yMin)
  // (- yEnd + yPoint) = (yEnd - yStart) * (yMin - ay[i]) / (yMax - yMin)
  //  yPoint = yEnd + ((yEnd - yStart) * (yMin - ay[i]) / (yMax - yMin))

  return yEnd + ((yEnd - yStart) * (yMin - ay) / (yMax - yMin));
}