(33)二重振子 5(二重振子をアニメ化する)

確認のためとりあえず棒だけ描いた。節と先端とにある質点は描いていない。


local w = platform.window:width()
local h = platform.window:height()

local x0 = w/2
local y0 = h/2

local step = 0.02
var.store("g", 9.80665)
var.store("l1", 1)
var.store("m1", 1)
var.store("l2", 1)
var.store("m2", 1)
var.store("tstart", 0)
var.store("tstop", step)
var.store("ini_theta1", 3)
var.store("ini_v1", 0)
var.store("ini_theta2", 3)
var.store("ini_v2", 0)
var.store("step", step)
var.store("tol", 0.0001)
 
function on.paint(gc)
   mat = math.eval("calculus\\w_pend(g, l1, m1, l2, m2, tstart, tstop, ini_theta1, ini_v1, ini_theta2, ini_v2, step, tol)")

   for i = 1, #mat do
      for j = 1, #mat[1] do
         gc:setFont("sansserif", "r", 7)
         gc:drawString(mat[i][j], 5 + (j-1) * 220, (i-1) * 10)
      end
   end

   x1 = x0 + 50 * math.sin(mat[2][1])
   y1 = y0 + 50 * math.cos(mat[2][1])
   x2 = x1 + 50 * math.sin(mat[4][1])
   y2 = y1 + 50 * math.cos(mat[4][1])
      
   gc:drawLine(x0, y0, x1, y1)
   gc:drawLine(x1, y1, x2, y2)
      
   var.store("ini_theta1", mat[2][2])
   var.store("ini_v1", mat[3][2])
   var.store("ini_theta2", mat[4][2])
   var.store("ini_v2", mat[5][2])
end

function on.construction()
   timer.start(step)
end
function on.timer()
   platform.window:invalidate()
end

参考文献:

工業力学 (機械工学基礎講座)

工業力学 (機械工学基礎講座)

(p. 229 - 231)