interpolation/Hermite/Float

From Second Life Wiki
Jump to navigation Jump to search

Summary

Function: float fHem( float a, float b, float c, float d, float t, float tens, float bias );

Hermite interpolation of floating points a, b, c and d with fraction t, tension and bias.
Returns a float

• float a
• float b
• float c
• float d
• float t
• float tens
• float bias

Specification

float fHem(float a, float b, float c, float d, float t, float tens, float bias){
    float t2 = t*t;float t3 = t2*t;
    float a0 =  (b-a)*(1+bias)*(1-tens)/2;
          a0 += (c-b)*(1-bias)*(1-tens)/2;
    float a1 =  (c-b)*(1+bias)*(1-tens)/2;
          a1 += (d-c)*(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 * b + b1 * a0 + b2 * a1 + b3 * c;
}
// Released into public domain. By Nexii Malthus.

Examples