double map(double x, double minIn, double maxIn, double minOut, double maxOut) { return (x - minIn) * (maxOut - minOut) / (maxIn - minIn) + minOut; }