Difference between revisions of "Interpolation/Linear/Vectors"

From Second Life Wiki
Jump to: navigation, search
(Created page with "{{LSL_Function |mode=user |func=vLin |p1_type=list|p1_name=v |p2_type=float|p2_name=t |p3_type=integer|p3_name=Loop |return_type=vector |return_value=returns the interpolation of…")
 
m (<lsl> tag to <source>)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
{{LSL_Function
 
{{LSL_Function
 
|mode=user
 
|mode=user
|func=vLin
+
|func=pLin
 
|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_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
 
|return_value=returns the interpolation of a list of vectors.
 
|return_value=returns the interpolation of a list of vectors.
 
|func_desc=
 
|func_desc=
 
Linearly interpolates between two vector points in a list of vectors that define a path.
 
Linearly interpolates between two vector points in a list of vectors that define a path.
|spec=<lsl>vector pLin(list v, float t, integer Loop){
+
|spec=<source lang="lsl2">vector pLin(list v, float t, integer Loop) {
  float l = llGetListLength(v); t *= l-1;
+
    integer l = llGetListLength(v); t *= l-1;
  float f = (float)llFloor(t);
+
    integer f = llFloor(t); t -= f;
  integer i1 = 0; integer i2 = 0;
+
    return llList2Vector(v,pIndex(f,l,Loop))*(1-t) + llList2Vector(v,pIndex(f+1,l,Loop))*t;
  if(Loop){ i1 = (integer)(f-llFloor(f/l)*l);
+
}
        ++f;i2 = (integer)(f-llFloor(f/l)*l);
+
integer pIndex( integer Index, integer Length, integer Loop) {
  } else {
+
     if(Loop) return Index % Length;
     if( f > l-1 ) i1 = (integer)l-1;
+
     if(Index < 0) return 0;
     else if( f >= 0 ) i1 = (integer)f;
+
     if(Index > --Length) return Length;
     if(f+1 > l-1 ) i2 = (integer)l-1;
+
     return Index;
     else if(f+1 >= 0 ) i2 = (integer)f+1;
+
}
  }
+
// Released into public domain. By Nexii Malthus.</source>
  vector v1 = llList2Vector(v, i1);
+
|examples=<source lang="lsl2"></source>
  vector v2 = llList2Vector(v, i2);
+
  t-=f;
+
  return v1*(1-t) + v2*t;
+
}</lsl>
+
|examples=<lsl></lsl>
+
 
|cat1=Examples
 
|cat1=Examples
 
}}
 
}}

Latest revision as of 16:06, 24 January 2015

Summary

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

Linearly interpolates between two 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

vector pLin(list v, float t, integer Loop) {
    integer l = llGetListLength(v); t *= l-1;
    integer f = llFloor(t); t -= f;
    return llList2Vector(v,pIndex(f,l,Loop))*(1-t) + llList2Vector(v,pIndex(f+1,l,Loop))*t;
}
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.

Examples