How do I map numbers, linearly, between a and b to go between c and d.
That is, I want numbers between 2 and 6 to map to numbers between 10 and 20... but I need the generalized case.
My brain is fried.
Mapping applies to any set: a collection of objects, such as all whole numbers, all the points on a line, or all those inside a circle. For example, “multiply by two” defines a mapping of the set of all whole numbers onto the set of even numbers. A rotation is a map of a plane or of all of space into itself.
An example of mapping is creating a map to get to your house. An example of mapping is identifying which cell on one spreadsheet contains the same information as the cell on another speadsheet. The process of making maps. (computing) Assigning a PC to a shared drive or printer port on a network.
If your number X falls between A and B, and you would like Y to fall between C and D, you can apply the following linear transform:
Y = (X-A)/(B-A) * (D-C) + C
That should give you what you want, although your question is a little ambiguous, since you could also map the interval in the reverse direction. Just watch out for division by zero and you should be OK.
Divide to get the ratio between the sizes of the two ranges, then subtract the starting value of your inital range, multiply by the ratio and add the starting value of your second range. In other words,
R = (20 - 10) / (6 - 2) y = (x - 2) * R + 10
This evenly spreads the numbers from the first range in the second range.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With