0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

windows11で、sketchup6 その89

Posted at

概要

windows11に、sketchup6を入れてみた。
rubyで、3Dを書く。
練習問題やってみた。

練習問題

ボールの弾みをシミュレーションせよ。

写真

image.png

サンプルコード

起動 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





以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?