Beej's Bit Bucket
a day ago
- The article explains how to transform numbers from one range to another using simple arithmetic like multiplication, division, addition, and subtraction.
- It uses a faux-3D carousel as an example, starting with angles in turns (0 to 1) and mapping them to radians, then to screen coordinates via sine and cosine.
- By applying scaling, translation, and trigonometric functions, carousel elements are positioned in a squished circle with depth effects such as z-index, scale, opacity, and blur.
- The author demonstrates step-by-step mapping from [0,1] to other ranges, emphasizing the simplicity of starting with a [0,1] range to solve complex problems.
- A general formula is provided to map any range [A,B] to [C,D]: v = C + (v0 - A)/(B - A)*(D - C).
- The technique is applicable beyond graphics, e.g., easing functions, dollar-to-million conversions, or random number generation.