views:

28

answers:

1

Processing has a great function I use all the time:

map(value, low1, high1, low2, high2)

http://processing.org/reference/map_.html

It remaps value (that has an expected range of low1 to high1) into a target range of low2 to high2).

I want to understand the math behind it so I can use it in other languages. Anyone want to throw me a bone and help me reverse engineer it? I understand that it's a lerp that's been re-scaled and re-offset... feeling brain dead this morning.

+3  A: 

From your description, it ought to be doing this, right?

low2 + (value - low1) * (high2 - low2) / (high1 - low1)

Find how far you are into the first range, scale that distance by the ratio of sizes of the ranges, and that's how far you should be into the second range.

Jefromi
perfect, thank you
AK