Difference between revisions of "Interpolation/Rescale"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "{{LSL Header|Interpolation}} {{RightToc|clear:right;}} == Rescale == {|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt;…")
 
(Page not needed anymore.)
 
Line 1: Line 1:
{{LSL Header|[[Interpolation]]}}
{{RightToc|clear:right;}}


== Rescale ==
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
!style="color: #000000; background-color: #aaaaff;" height="20px"|
===Float Rescale===
|-
|
Rescales a value from one range to another range.
<lsl>
float fScl(float from0, float from1, float to0, float to1, float t) {
    return to0 + ( (to1 - to0) * ( (from0 - t) / (from0-from1) ) );
}
</lsl>
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
|
{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
!style="background-color: #d0d0ee" | Input
!style="background-color: #d0d0ee" | Description
|-
| float from0
| 'From' Range minimum
|-
| float from1
| 'From' Range maximum
|-
| float to0
| 'To' Range minimum
|-
| float to1
| 'To' Range maximum
|-
| float t
| 'From' Range value
|-
!style="background-color: #d0d0ee" | Output
!style="background-color: #d0d0ee" | Description
|-
| return float fScl
| Returns rescaled value between two different ranges.
|}
| Graph goes here, k.
|}
<div style="float:right;font-size: 80%;">
Released to Public Domain. By Nexii Malthus</div>
|}
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
!style="color: #000000; background-color: #aaaaff;" height="20px"|
===Float Rescale Fixed===
|-
|
Rescales a value from one range to another range. The value is clamped between the range.
<lsl>
float fSclFix(float from0, float from1, float to0, float to1, float t) {
    t = to0 + ( (to1 - to0) * ( (from0 - t) / (from0-from1) ) );
    if(to0 < to1) {
        if(t < to0) t = to0; else if(t > to1) t = to1;
    } else {
        if(t < to1) t = to1; else if(t > to0) t = to0;
    }
    return t;
}
</lsl>
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
|
{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
!style="background-color: #d0d0ee" | Input
!style="background-color: #d0d0ee" | Description
|-
| float from0
| 'From' Range minimum
|-
| float from1
| 'From' Range maximum
|-
| float to0
| 'To' Range minimum
|-
| float to1
| 'To' Range maximum
|-
| float t
| 'From' Range value
|-
!style="background-color: #d0d0ee" | Output
!style="background-color: #d0d0ee" | Description
|-
| return float fScl
| Returns rescaled and clamped value between two different ranges.
|}
| Graph goes here, k.
|}
<div style="float:right;font-size: 80%;">
Released to Public Domain. By Nexii Malthus</div>
|}

Latest revision as of 04:25, 14 September 2011