Difference between revisions of "Interpolation/Hermite/Vector"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
(Add documentation of what the inputs are)
Line 13: Line 13:
|func_desc=
|func_desc=
Hermite interpolation of vectors a, b, c and d with fraction t, tension and bias.
Hermite interpolation of vectors a, b, c and d with fraction t, tension and bias.
|spec=<source lang="lsl2">vector vHem(vector a, vector b, vector c, vector d, float t, float tens, float bias){
|spec=<syntaxhighlight lang="lsl2">//A: start tangent, B: start vector, C: end vector, D: end tangent
vector vHem(vector a, vector b, vector c, vector d, float t, float tens, float bias){
     float t2 = t*t;float t3 = t2*t;
     float t2 = t*t;float t3 = t2*t;
     vector a0 =  (b-a)*(1+bias)*(1-tens)/2;
     vector a0 =  (b-a)*(1+bias)*(1-tens)/2;
Line 26: Line 27:
}
}
// Released into public domain. By Nexii Malthus.</source>
// Released into public domain. By Nexii Malthus.</source>
|examples=<source lang="lsl2"></source>
|examples=<syntaxhighlight lang="lsl2"></syntaxhighlight>
|cat1=Examples
|cat1=Examples
}}
}}

Revision as of 18:19, 1 April 2024

Summary

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

Hermite interpolation of vectors a, b, c and d with fraction t, tension and bias.
Returns a vector

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

Specification

//A: start tangent, B: start vector, C: end vector, D: end tangent
vector vHem(vector a, vector b, vector c, vector d, float t, float tens, float bias){
    float t2 = t*t;float t3 = t2*t;
    vector a0 =  (b-a)*(1+bias)*(1-tens)/2;
           a0 += (c-b)*(1-bias)*(1-tens)/2;
    vector 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.</source>
|examples=<syntaxhighlight lang="lsl2">

Examples