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

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

Intercepting and adjusting SQL generated by Eclipselink JPA

Exporting Kendo UI GRID to Excel with Java