Interpolation/Linear

From Second Life Wiki
< Interpolation
Revision as of 13:22, 4 September 2011 by Nexii Malthus (talk | contribs) (Created page with "{{LSL Header|Interpolation}} {{RightToc|clear:right;}} == Linear Interpolation == {|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em…")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Linear Interpolation

Float Linear

Linear interpolation of f0 and f1 with fraction t. <lsl> float fLin(float f0,float f1,float t) {

   return f0*(1-t) + f1*t;

} </lsl>

Input Description
float f0 Start (t = 0.0)
float f1 End (t = 1.0)
float t Fraction of interpolation
Output Description
return float fLin Returns linear interpolation of two floats
Interp Chart1.png
Released to Public Domain. By Nexii Malthus


Vector Linear

Linear interpolation of v0 and v1 with fraction t. <lsl> vector vLin(vector v0, vector v1,float t){

   return v0*(1-t) + v1*t;

} </lsl>

Input Description
vector v0 Start (t = 0.0)
vector v1 End (t = 1.0)
float t Fraction of interpolation
Output Description
return vector vLin Returns linear interpolation of two vectors
Graph goes here, k.
Released to Public Domain. By Nexii Malthus


Rotation Linear

Spherical Linear interpolation of r0 and r1 with fraction t. Also known as SLERP <lsl> rotation rLin(rotation r0,rotation r1,float t) {

   float ang = llAngleBetween(r0, r1);
   if(ang > PI) ang -= TWO_PI;
   return r0 * llAxisAngle2Rot( llRot2Axis(r1/r0)*r0, ang*t);

} </lsl>

Input Description
rotation r0 Start (t = 0.0)
rotation r1 End (t = 1.0)
float t Fraction of interpolation
Output Description
return rotation rLin Returns spherical linear interpolation of two rotations
Graph goes here, k.
Released to Public Domain. By Nexii Malthus