Forums - Open Redstone Engineers
Range Mapping Theorem - Printable Version

+- Forums - Open Redstone Engineers (https://forum.openredstone.org)
+-- Forum: Off-Topic (https://forum.openredstone.org/forum-4.html)
+--- Forum: General computing and engineering (https://forum.openredstone.org/forum-66.html)
+--- Thread: Range Mapping Theorem (/thread-2688.html)



Range Mapping Theorem - tokumei - 03-08-2014

So, I know that this has already become a thing that people know about, I just wanted to say I found out myself how to do it, and would like to post it here as a reference for others. In case you aren't familiar with the concept of mapping ranges, it's a very commonly used formula by programmers, especially robot enthusiasts like myself. The concept treats the input value as a percent of the way through a certain range, then maps that to a percent of the way through another range.

Here's an example. Say we have a floating-point input from our joystick axis that ranges from 0 to 1, but we want it to change so it ranges from 0.5 to 1. Now, say that the current input from the joystick axis is 0.25 exactly. 0.25 is 25% of the way through the range of 0 to 1, and we want it 25% of the way through the range of 0.5 to 1.We can map it to the value we want by using this formula -- (x a) * (dc) / (b a) + c -- where x ranges from a to b, and we are mapping it to the range c to d. When we substitute in our values, we get the expression (0.25 – 0) * (1 – 0.5) / (1 – 0) + 0.5. When we simplify that, we get 0.625, which is 25% of the way through the target range.

This can also be used to map to backwards ranges, i.e. from 0 to 1 to 1 to 0. If you want to use this formula to do this, make sure the target range is the backwards one. If you try to map from 1 to 0, to 0 to 1, it will derp.


RE: Range Mapping Theorem - Iceglade - 03-08-2014

[Image: mimetex.cgi?\frac{(x-a)(d-c)}{b-a}+c]

:3


RE: Range Mapping Theorem - Thor23 - 03-10-2014

Why exactly does doing from 1 to 0 -> 0 to 1 derp up? You would get a negative for both the top and bottom, which would just make it positive, wouldn't it?


RE: Range Mapping Theorem - tokumei - 03-11-2014

(03-10-2014, 07:16 PM)Thor23 Wrote: Why exactly does doing from 1 to 0 -> 0 to 1 derp up? You would get a negative for both the top and bottom, which would just make it positive, wouldn't it?

I honestly don't know; that's what I thought when I evaluated it in my head, but it came up with some negative thing when I tried it in the calculator.