We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › exponential mapping
Page Index Toggle Pages: 1
exponential mapping (Read 1162 times)
exponential mapping
Dec 8th, 2009, 7:23am
 
i have a long type number im getting from an arduino sensor (capSensing). it has a very large range from 0 to 10,000 but it has exponential tendecies.
i searched and found this snippet here >((cant post link) .../discourse/yabb2/num_1206881824.html
Code:
 for (i=0;i<n;i++)   values[i] = values[i]/n*pow(1.6,(i/50.))*3.;   // Exponential Scaling.  Adjust values as desired. 



cant seem to understand this, any ideas on using the function?

Re: exponential mapping
Reply #1 - Dec 8th, 2009, 7:49am
 
Maybe take a look at toxiclibs and the interpolate and ZoomLensInterpolation example. that helps to map data the way you need it. really useful

http://code.google.com/p/toxiclibs/downloads/list

it is in the toxiclibs Core
Re: exponential mapping
Reply #2 - Dec 9th, 2009, 7:20am
 
Yes, Cedric the ZoomLensInterpolation would be good, but might be a bit overkill for this. The ScaleMap class would be another alternative. See the quick example below:

Code:
/**
* Logarithmic scale vs. linear scale example
* Requires toxiclibscore-0014 or newer: http://toxiclibs.org/
*
* @author toxi
*/
import toxi.math.*;

float expectedMinValue=1;
float expectedMaxValue=800;

ScaleMap linearMap;
ScaleMap logMap;

size(1000,200);
smooth();

// create 2 scale maps
// parameters: in_min, in_max, out_min, out_max
logMap=new ScaleMap(log(expectedMinValue),log(expectedMaxValue),0,width);
linearMap=new ScaleMap(expectedMinValue,expectedMaxValue,0,width);

for(float i=expectedMinValue; i<expectedMaxValue; i+=10) {
 // get log scale value
 float x1=(float)logMap.getMappedValueFor(log(i));
 stroke(0);
 line(x1,0,x1,50);
 // get linear mapped value
 float x2=(float)linearMap.getMappedValueFor(i);
 line(x2,150,x2,200);
 // draw connection line
 stroke(0,50);
 line(x1,50,x2,150);
}
Re: exponential mapping
Reply #3 - Dec 9th, 2009, 8:19am
 
Ah ok, good to know. i am not familiar with all the features yet.
Page Index Toggle Pages: 1