I need to convert a linear range [0.1 ... 4 ... 10] to logarithmic one [0.5 ... 1 ... 5], so that 0.1 -> 0.5, 4 -> 1, 10 -> 5
I've found the similar problem here From half to double, linear to logarithmic scale. but don't understand the solution.
I also have a code in C++ from an SDK which perfectly does what I need (simplified a bit), but I can't figure out how the formulas have been obtained:
double srcMin = 0.1, srcMax = 10, input = 4.0;
double destMin = 0.5, destMax = 5, output = 1.0;
double destDistance = (destMax - destMin);
double srcDistance = (srcMax - srcMin);
double expo = ::log10((output - destMin) / destDistance) / ::log10((input - srcMin) / srcDistance); // formula 1
for (int i = 0; i <= 100; ++i)
{
auto currentPoint = srcMin*i; // calculate for [0.1, 0.2, ..., 10]
auto res = ::pow(((currentPoint - srcMin) / srcDistance), expo) * destDistance + destMin; // formula 2
cout << setw(4) << srcMin*i << ": " << res << endl;
}
Update: Actually code produce exp plot (sorry for confusing). So I have to change my question - how to convert from linear to exponential