Scale a number but ensure it is greater than a value

66 Views Asked by At

I have a grid with a Y-axis with a minimum of 25, and a maximum of 50 but the scale begins at 25 (25-50) and a X-axis with a minimum of 0, and a maximum of 4 that begins at 0 (0-4)

I have a set of coordinates (X&Y) and they must not exceed the max values

x,y
--------------
0,25

0,52

The max Y is 50 so I tried to create a scale 50/52=0.96

25*0.96=24 52*0.96=49.92

So now my coordinates become

x,y
--------------
0,24

0,49.92

24<25 so this won't work. How can I scale these numbers but ensure they are greater than 25?

1

There are 1 best solutions below

0
On

I think (maybe) you want to transform the $x$-range $0$ to $25$ so it evenly covers the range $25$ to $50$, and you want to transform the $y$-range $0$ to $52$ so it evenly covers the range $0$ to $50$.

The $x$-range is easy, just add $25$, because the two ranges are equal in size. For the $y$-range, $0$ to $52$ is too big by a factor of $52\over50$, so* multiply by $50\over52$. *You don’t need to add or subtract anything before or after you multiply, since the range starts at $0$ and you still want it to start at $0$.

In general, if you have $x$ in the range $a$ to $b$ and you want a transformed $x'$ to be in the range $c$ to $d$, change $x$ by first subtracting $a$, then multiplying by the width $d-c$ divided by the width $b-a$, then add $c$ to get the starting point right. So $x_new=(x-a)\cdot{d-c\over b-a} + c$. This assumes $a<b$ and $c<d$ and you don’t need to reverse the direction of the range.