Interpolation/Cubic

From Second Life Wiki
Jump to navigation Jump to search

Cubic Interpolation

Float Cubic

Cubic interpolation of f0, f1, f2 and f3 with fraction t. <lsl> float fCub(float f0,float f1,float f2,float f3,float t) {

   float P = (f3-f2)-(f0-f1);
   return P*llPow(t,3) + ((f0-f1)-P)*llPow(t,2) + (f2-f0)*t + f1;

} </lsl>

Input Description
float f0 Modifier (t = 0.33~)
float f1 Start (t = 0.0)
float f2 End (t = 1.0)
float f3 Modifier (t = 0.66~)
float t Fraction of interpolation
Output Description
return float fCub Returns cubic interpolation of four floats
Interp Chart3.png
Release to Public Domain. By Nexii Malthus


Vector Cubic

Cubic interpolation of v0, v1, v2 and v3 with fraction t. <lsl> vector vCub(vector v0,vector v1,vector v2,vector v3,float t){

   vector P = (v3-v2)-(v1-v0);
   return P*llPow(t,3) + ((v1-v0)-P)*llPow(t,2) + (v2-v1)*t + v0;

} </lsl>

Input Description
vector v0 Start Point
vector v1 Start Tangent
vector v2 End Point
vector v3 End Tangent
float t Fraction of interpolation
Output Description
return vector vCub Returns cubic interpolation of four vectors
Graph goes here, k.
Released to Public Domain. By Nexii Malthus


Rotation Cubic

Spherical Cubic interpolation of r0 and r1 with fraction t. I liken to call it as SCURP <lsl> rotation rCub(rotation r0,rotation r1,rotation r2,rotation r3,float t){

   // Spherical-Cubic Interpolation
   // r0 = Start, r1 = End, r2 and r3 affect path of curve!
   return rLin( rLin(r0,r1,t), rLin(r2,r3,t), 2*t*(1-t) );

} </lsl>

Input Description
rotation r0 Start (t = 0.0)
rotation r1 End (t = 1.0)
rotation r2 Modifier (t = 0.33~)
rotation r3 Modifier (t = 0.66~)
float t Fraction of interpolation
Output Description
return rotation rCub Returns spherical cubic interpolation of four rotations
Requirement
function rotation rLin(rotation r0,rotation r1,float t)
Graph goes here, k.
Released to Public Domain. By Nexii Malthus