Map range: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 1,360: | Line 1,360: | ||
The resulting inverse function is: |
The resulting inverse function is: |
||
<lang frink>inverseMapRange[t, a1, a2, b1, b2] := a1 + a1 b1 (-1 b1 + b2)^-1 + -1 a2 b1 (-1 b1 + b2)^-1 + -1 a1 (-1 b1 + b2)^-1 t + a2 (-1 b1 + b2)^-1 t</lang> |
<lang frink>inverseMapRange[t, a1, a2, b1, b2] := a1 + a1 b1 (-1 b1 + b2)^-1 + -1 a2 b1 (-1 b1 + b2)^-1 + -1 a1 (-1 b1 + b2)^-1 t + a2 (-1 b1 + b2)^-1 t</lang> |
||
=={{header|GDScript}}== |
|||
<lang GDScript>func mapRange(s:float, a1:float, a2:float, b1:float, b2:float) -> float : |
|||
return b1 + ((b2-b1)/(a2-a1))*(s-a1) |
|||
for i in 11 : |
|||
print( "%2d %+.1f" % [i,mapRange(i,0.0,10.0,-1.0,0.0)] ) |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
0 -1.0 |
|||
1 -0.9 |
|||
2 -0.8 |
|||
3 -0.7 |
|||
4 -0.6 |
|||
5 -0.5 |
|||
6 -0.4 |
|||
7 -0.3 |
|||
8 -0.2 |
|||
9 -0.1 |
|||
10 +0.0 |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |