<% # See-saw world with balanced boxes # SI units (length in meters) # wood density = 500 boxes = { "cube1" => {}, "cube2" => {}, "fulcrum" => {}, "plank" => {}, } boxes["fulcrum"][:size] = [0.1, 0.5, 0.8] boxes["plank"][:size] = [6.0, 0.5, 0.08] boxes["cube1"][:size] = [0.45, 0.45, 0.45] boxes["cube2"][:size] = [0.45, 0.45, 0.45] boxes.keys.each do |name| box = boxes[name] dx = box[:size][0] dy = box[:size][1] dz = box[:size][2] volume = box[:size].reduce(:*) box[:pose] = [0, 0, dz/2, 0, 0, 0] box[:mass] = density * volume box[:ixx] = box[:mass] / 12.0 * (dy**2 + dz**2) box[:iyy] = box[:mass] / 12.0 * (dz**2 + dx**2) box[:izz] = box[:mass] / 12.0 * (dx**2 + dy**2) end boxes["plank"][:pose][2] += boxes["fulcrum"][:size][2] boxes["cube1"][:pose][2] += boxes["plank"][:pose][2] + boxes["plank"][:size][2]/2 boxes["cube2"][:pose][2] += boxes["plank"][:pose][2] + boxes["plank"][:size][2]/2 boxes["cube1"][:pose][0] += boxes["plank"][:size][0] * 0.45 boxes["cube2"][:pose][0] -= boxes["plank"][:size][0] * 0.45 %> 150 model://ground_plane model://sun <% boxes.keys.each do |name| box = boxes[name] %> <%= box[:pose].join(" ") %> 0 <%= box[:mass] %> <%= box[:ixx] %> 0 0 <%= box[:iyy] %> 0 <%= box[:izz] %> <%= box[:size].join(" ") %> 0.1 0.01 <%= box[:size].join(" ") %> <% end %> 0 -7 2.41737 0 0.339643 <%= Math::PI / 2%> orbit perspective