local c=2.718281828459 local function T(T,m,B,u,G,Y,l)if m==0 then return B elseif T<.99999999 then local q=(1-T*T)^.5 local y=(B-G)+((2*T)/m)*Y local C=((T/q)*(B-G)+u/(q*m))+(((2*T)*T-1)/(q*m))*Y local Z=math.cos((q*m)*l)local s=math.sin((q*m)*l)local b=c^((T*m)*l)return(((Z/b)*y+(s/b)*C)+G)+(l-(2*T)/m)*Y,(((m*(Z*q-T*s))/b)*C-((m*(Z*T+q*s))/b)*y)+Y elseif T<1.00000001 then local T=(B-G)+(2/m)*Y local q=(B-G)+(u+Y)/m local y=c^(m*l)return((T+(q*m)*l)/y+G)+(l-2/m)*Y,Y-(m/y)*(T+(m*l-1)*q)else local q=(T*T-1)^.5 local y=(Y-u)/((2*m)*q)local C=(T/m)*Y-(G-B)/2 local Z=(1-T/q)*C+y local s=(1+T/q)*C-y local b=c^((-(q+T)*m)*l)local g=c^(((q-T)*m)*l)return((Z*b+s*g)+G)+(l-(2*T)/m)*Y,(((g*(q-T))*m)*s-((b*(T+q))*m)*Z)+Y end end local function m(c,T,m)return c+m*T,T end local B={}B.__index=B


local e=2.718281828459045

local function posvel(d,s,p0,v0,p1,v1,x)
	if s==0 then
		return p0
	elseif d<1-1e-8 then
		local h=(1-d*d)^0.5
		local c1=(p0-p1+2*d/s*v1)
		local c2=d/h*(p0-p1)+v0/(h*s)+(2*d*d-1)/(h*s)*v1
		local co=math.cos(h*s*x)
		local si=math.sin(h*s*x)
		local ex=e^(d*s*x)
		return co/ex*c1+si/ex*c2+p1+(x-2*d/s)*v1, s*(co*h-d*si)/ex*c2-s*(co*d+h*si)/ex*c1+v1
	elseif d<1+1e-8 then
		local c1=p0-p1+2/s*v1
		local c2=p0-p1+(v0+v1)/s
		local ex=e^(s*x)
		return (c1+c2*s*x)/ex+p1+(x-2/s)*v1, v1-s/ex*(c1+(s*x-1)*c2)
	else
		local h=(d*d-1)^0.5
		local a=(v1-v0)/(2*s*h)
		local b=d/s*v1-(p1-p0)/2
		local c1=(1-d/h)*b+a
		local c2=(1+d/h)*b-a
		local co=e^(-(h+d)*s*x)
		local si=e^((h-d)*s*x)
		return c1*co+c2*si+p1+(x-2*d/s)*v1, si*(h-d)*s*c2-co*(d+h)*s*c1+v1
	end
end

local function targposvel(p1,v1,x)
	return p1+x*v1,v1
end

local Spring = {}

Spring.__index = Spring
