ruby - How do I map number ranges to each other? -
how can map 2 opposing numbers ranges each other?
i have 1 range 3 numbers: 1, 2, 3
(and potential decimals).
i'd map on range of 1000 0.
so, 1 = 1000
, 2 = 500
, 3 = 0
.
ultimately, want take number 1.68 , figure out on 1000-0 scale it'd match up.
using math!
assuming want linear mapping first range (1-3) second (1000-0, descending), function:
y = (3 - x) / 2 * 1000
where x
input (1 <= x <= 3
) , y
output (0 <= y <= 1000
).
this can generalized different ranges needed.
patent pending.
Comments
Post a Comment