Converting from linear to logarithmic scale

A simple function useful to plot a logarithmic scale. Just provide it with the min and max values of the scale and the value you want to convert - and you'll get in return a value as it should be positioned on a logarithmic scale in the given range.
 public double toLogScale(double min, double max,double val) {  
     double logmin = Math.log(min);  
     double logmax = Math.log(max);  
     double logscale = (Math.log(val)-logmin) / (logmax-logmin);  
     return min+(max-min)*logscale;  
   }    

Comments

Popular posts from this blog

Create PDF's in Angular / Typescript

My VNC based development environment with Visual Studio Code running on Ubuntu

Angular 5 - Ahead of Time build configuration for rollup