obj.interpolation
型:function
code:Lua
obj.interpolation(t,x0,x1,x2,x3)
obj.interpolation(t,x0,y0,x1,y1,x2,y2,x3,y3)
obj.interpolation(t,x0,y0,z0,x1,y1,z1,x2,y2,z2,x3,y3,z3)
説明
連続した点P0,P1,P2,P3から時間tに応じたP1,P2間の座標を返す
戻り値の数は次元数に応じて変わる
使用例
exedit.traの補間移動が参考になる
簡易版
code:Lua
local index,ratio=math.modf(obj.getpoint("index"))
local num=obj.getpoint("num")
local x0,x1,x2,x3
x1=obj.getpoint(index)
x2=obj.getpoint(index+1)
if(index==0)then
x0=x1
else
x0=obj.getpoint(index-1)
end
if(index==num)then
x3=x2
else
x3=obj.getpoint(index+1)
end
return obj.interpolation(ratio,x0,x1,x2,x3)
実装例
code:lua
function obj.interpolation(t,...)
local f=function(t,p0,p1,p2,p3)
local xd0,xd1,xd2=p11-p01,p21-p11,p31-p21 local yd0,yd1,yd2=p12-p02,p22-p12,p32-p22 local zd0,zd1,zd2=p13-p03,p23-p13,p33-p23 local d0=math.sqrt(xd0*xd0+yd0*yd0+zd0*zd0)
local d1=math.sqrt(xd1*xd1+yd1*yd1+zd1*zd1)
local d2=math.sqrt(xd2*xd2+yd2*yd2+zd2*zd2)
if(d1<=0)then return p1 end
local dd0=d0+d0+d1+d1
local dd1=d1+d1+d2+d2
local s=1-t
return {
((p11+(d1*xd0+d0*xd1)/dd0)*s*s*3+t*t*p21)*t+ ((p21-(d2*xd1+d1*xd2)/dd1)*t*t*3+s*s*p11)*s, ((p12+(d1*yd0+d0*yd1)/dd0)*s*s*3+t*t*p22)*t+ ((p22-(d2*yd1+d1*yd2)/dd1)*t*t*3+s*s*p12)*s, ((p13+(d1*zd0+d0*zd1)/dd0)*s*s*3+t*t*p23)*t+ ((p23-(d2*zd1+d1*zd2)/dd1)*t*t*3+s*s*p13)*s }
end
local arg={...}
if(#arg<4)then error("引数不足") end
local p0,p1,p2,p3
if(#arg<8)then p0,p1,p2,p3={arg1,0,0},{arg2,0,0},{arg3,0,0},{arg4,0,0} elseif(#arg<12)then p0,p1,p2,p3={arg1,arg2,0},{arg3,arg4,0},{arg5,arg6,0},{arg7,arg8,0} else p0,p1,p2,p3=arg,{arg4,arg5,arg6},{arg7,arg8,arg9},{arg10,arg11,arg12} end result=f(t,p0,p1,p2,p3)
if(#arg<8)then return result1 elseif(#arg<12)then return result1,result2 else return unpack(result) end
end