c# simple-code
public static float map( float origin, float inputMin, float inputMax, float outputMin, float outputMax )
{
return outputMin + ( origin - inputMin ) * ( outputMax - outputMin ) / ( inputMax - inputMin );
}
float map(float s, float a1, float a2, float b1, float b2)
{
return b1 + (s-a1)*(b2-b1)/(a2-a1);
}