Difference between revisions of "Interpolation/Rescale/Float"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
Line 11: Line 11:
|func_desc=
|func_desc=
Rescales a value from one range to another range.
Rescales a value from one range to another range.
|spec=<lsl>float fScl(float from_min, float from_max, float to_min, float to_max, float from) {
|spec=<source lang="lsl2">float fScl(float from_min, float from_max, float to_min, float to_max, float from) {
     return to_min + ((to_max-to_min) * ((from_min-from) / (from_min-from_max)));
     return to_min + ((to_max-to_min) * ((from_min-from) / (from_min-from_max)));
}
}
// Released into public domain. By Nexii Malthus.</lsl>
// Released into public domain. By Nexii Malthus.</source>
|examples=<lsl>float value = fScl(0.0, 1.0, -5, 15, 0.6); // value == 7</lsl>
|examples=<source lang="lsl2">float value = fScl(0.0, 1.0, -5, 15, 0.6); // value == 7</source>
|cat1=Examples
|cat1=Examples
}}
}}

Latest revision as of 15:06, 24 January 2015

Summary

Function: float fScl( float from_min, float from_max, float to_min, float to_max, float from );

Rescales a value from one range to another range.
Returns a float

• float from_min Minimum of range From
• float from_max Maximum of range From
• float to_min Minimum of range To
• float to_max Maximum of range To
• float from Value in range From

Specification

float fScl(float from_min, float from_max, float to_min, float to_max, float from) {
    return to_min + ((to_max-to_min) * ((from_min-from) / (from_min-from_max)));
}
// Released into public domain. By Nexii Malthus.

Examples

float value = fScl(0.0, 1.0, -5, 15, 0.6); // value == 7