Difference between revisions of "Interpolation/Spline/Vectors"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with "{{LSL_Function |mode=user |func=pSpline |p1_type=list|p1_name=v |p2_type=float|p2_name=t |p3_type=integer|p3_name=Loop|p3_desc=Whether the list is a curved line or loops into a c…")
 
Line 3: Line 3:
|func=pSpline
|func=pSpline
|p1_type=list|p1_name=v
|p1_type=list|p1_name=v
|p2_type=float|p2_name=t
|p2_type=float|p2_name=t|p2_desc=Ranges between [0, 1]
|p3_type=integer|p3_name=Loop|p3_desc=Whether the list is a curved line or loops into a closed shape.
|p3_type=integer|p3_name=Loop|p3_desc=Whether the list is a curved line or loops into a closed shape.
|return_type=vector
|return_type=vector

Revision as of 13:10, 16 September 2011

Summary

Function: vector pSpline( list v, float t, integer Loop );

B-Spline Interpolation between four vector points in a list of vectors that define a path.
Returns a vector

• list v
• float t Ranges between [0, 1]
• integer Loop Whether the list is a curved line or loops into a closed shape.

Specification

<lsl>vector pSpline(list v, float t, integer Loop) {

   integer l = llGetListLength(v); t *= l-1;
   integer f = llFloor(t); t -= f;
   float t2 = t * t; float t3 = t2 * t;
   return (
     ( (-t3 + (3.*t2) - (3.*t) + 1.) * llList2Vector(v, pIndex(f-1,l,Loop)) )
   + ( ((3.*t3) - (6.*t2) + 4.) * llList2Vector(v, pIndex(f,l,Loop)) )
   + ( ((-3.*t3) + (3.*t2) + (3.*t) + 1.) * llList2Vector(v, pIndex(f+1,l,Loop)) )
   + ( t3 * llList2Vector(v, pIndex(f+2,l,Loop)) )
   ) / 6.0;

} integer pIndex( integer Index, integer Length, integer Loop) {

   if(Loop) return Index % Length;
   if(Index < 0) return 0;
   if(Index > --Length) return Length;
   return Index;

} // Released into public domain. By Nexii Malthus.</lsl>

Examples

<lsl></lsl>