Interpolation/Rescale

From Second Life Wiki
< Interpolation
Revision as of 14:18, 4 September 2011 by Nexii Malthus (talk | contribs) (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;…")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Rescale

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>

Input 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
Output Description
return float fScl Returns rescaled value between two different ranges.
Graph goes here, k.
Released to Public Domain. By Nexii Malthus


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>

Input 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
Output Description
return float fScl Returns rescaled and clamped value between two different ranges.
Graph goes here, k.
Released to Public Domain. By Nexii Malthus