Difference between revisions of "Interpolation/Cubic"

From Second Life Wiki
Jump to navigation Jump to search
(Page not needed anymore.)
 
Line 1: Line 1:
{{LSL Header|[[Interpolation]]}}
{{RightToc|clear:right;}}


== Cubic Interpolation ==
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
!style="color: #000000; background-color: #aaaaff;" height="20px"|
===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>
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
|
{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
!style="background-color: #d0d0ee" | Input
!style="background-color: #d0d0ee" | 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
|-
!style="background-color: #d0d0ee" | Output
!style="background-color: #d0d0ee" | Description
|-
| return float fCub
| Returns cubic interpolation of four floats
|}
| [[Image:Interp_Chart3.png|center]]
|}
<div style="float:right;font-size: 80%;">
Release to Public Domain. By Nexii Malthus</div>
|}
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
!style="color: #000000; background-color: #aaaaff;" height="20px"|
===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>
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
|
{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
!style="background-color: #d0d0ee" | Input
!style="background-color: #d0d0ee" | Description
|-
| vector v0
| Start Point
|-
| vector v1
| Start Tangent
|-
| vector v2
| End Point
|-
| vector v3
| End Tangent
|-
| float t
| Fraction of interpolation
|-
!style="background-color: #d0d0ee" | Output
!style="background-color: #d0d0ee" | Description
|-
| return vector vCub
| Returns cubic interpolation of four vectors
|}
| Graph goes here, k.
|}
<div style="float:right;font-size: 80%;">
Released to Public Domain. By Nexii Malthus</div>
|}
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
!style="color: #000000; background-color: #aaaaff;" height="20px"|
===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>
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
|
{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
!style="background-color: #d0d0ee" | Input
!style="background-color: #d0d0ee" | 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
|-
!style="background-color: #d0d0ee" | Output
!style="background-color: #d0d0ee" | Description
|-
| return rotation rCub
| Returns spherical cubic interpolation of four rotations
|-
!style="background-color: #eed0d0" colspan="2"| Requirement
|-
|style="background-color: #eed0d0" colspan="2"| function rotation rLin(rotation r0,rotation r1,float t)
|}
| Graph goes here, k.
|}
<div style="float:right;font-size: 80%;">
Released to Public Domain. By Nexii Malthus</div>
|}

Latest revision as of 03:58, 14 September 2011