概要
windows11に、sketchup6を入れてみた。
rubyで、3Dを書く。
練習問題やってみた。
練習問題
ボールの弾みをシミュレーションせよ。
写真
サンプルコード
起動 Ball.new
require 'sketchup.rb'
class Ball
def initialize
model = Sketchup.active_model
entities = model.active_entities
@tid = 0
@v0 = 10
@pz = 0
@t = 0
@view = model.active_view
@ball = entities.add_group
circle = @ball.entities.add_circle [0, 1, 2], Y_AXIS, 4.0, 20
circle_face = @ball.entities.add_face circle
circle_face.pushpull -0.1
@tid = UI.start_timer(0.9, true) {
tick
}
end
def tick
g = 9.8
@t += 0.1
z = 2 + @v0 * @t - 0.5 * g * @t * @t
puts z
if (z < 2)
@v0 = @v0 * 0.8
@t = 0
end
trans = Geom::Transformation.translation [0, 0, z - @pz]
@ball.transform! trans
@view.invalidate
if @pz == z
UI.stop_timer @tid
end
@pz = z
end
end
以上。