Interpolation/Hermite

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

Hermite Interpolation

Float Hermite

Hermite interpolation of f0, f1, f2 and f3 with fraction t, tension and bias. <lsl> float fHem(float f0,float f1,float f2,float f3,float t,float tens,float bias){

   float t2 = t*t;float t3 = t2*t;
   float a0 =  (f1-f0)*(1+bias)*(1-tens)/2;
         a0 += (f2-f1)*(1-bias)*(1-tens)/2;
   float a1 =  (f2-f1)*(1+bias)*(1-tens)/2;
         a1 += (f3-f2)*(1-bias)*(1-tens)/2;
   float b0 =  2*t3 - 3*t2 + 1;
   float b1 =    t3 - 2*t2 + t;
   float b2 =    t3 -   t2;
   float b3 = -2*t3 + 3*t2;
   return (  b0  *  f1+b1  *  a0+b2  *  a1+b3  *  f2  );

} </lsl>

Input Description
float f0 Modifier, 0.33~
float f1 Start, 0.0
float f2 End, 1.0
float f3 Modifier, 0.66~
float t Fraction of interpolation
float tens Tension of interpolation
float bias Bias of interpolation
Output Description
return float fHem Returns hermite interpolation of four floats with tension and bias
Graph goes here, k.
Released to Public Domain. By Nexii Malthus


Vector Hermite

Hermite interpolation of v0, v1, v2 and v3 with fraction t, tension and bias. <lsl> vector vHem(vector v0,vector v1,vector v2,vector v3,float t,float tens,float bias){

   float t2 = t*t;float t3 = t2*t;
   vector a0 =  (v1-v0)*(1+bias)*(1-tens)/2;
          a0 += (v2-v1)*(1-bias)*(1-tens)/2;
   vector a1 =  (v2-v1)*(1+bias)*(1-tens)/2;
          a1 += (v3-v2)*(1-bias)*(1-tens)/2;
   float b0 =  2*t3 - 3*t2 + 1;
   float b1 =    t3 - 2*t2 + t;
   float b2 =    t3 -   t2;
   float b3 = -2*t3 + 3*t2;
   return (  b0  *  v1+b1  *  a0+b2  *  a1+b3  *  v2  );}

</lsl>

Input Description
vector v0 Modifier, 0.33~
vector v1 Start, 0.0
vector v2 End, 1.0
vector v3 Modifier, 0.66~
float t Fraction of interpolation
float tens Tension of interpolation
float bias Bias of interpolation
Output Description
return vector vHem Returns hermite interpolation of four vectors with tension and bias
Graph goes here, k.
Released to Public Domain. By Nexii Malthus