概要
windows11に、sketchup6を入れてみた。
rubyで、3Dを書く。
練習問題、やってみた。
練習問題
sketchupでペジェ曲線を描くrubyスクリプトは
写真
サンプルコード
def create_bezi
model = Sketchup.active_model
entities = model.active_entities
p0x = 0
p0y = 0
p1x = 10
p1y = 10
p2x = 20
p2y = 20
p3x = 30
p3y = 0
prompts = ["p0 x", "p0 y", "p1 x", "p1 y", "p2 x", "p2 y","p3 x", "p3 y"]
values = [p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y]
results = UI.inputbox(prompts, values, "Bezier")
if results
p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y = results
else
return
end
x2 = 0
y2 = 0
(100).times { |i|
t = (i.to_f) / 100
x1 = (1 - t) * (1 - t) * (1 - t) * p0x + 3 * t * (1 - t) * (1 - t) * p1x + 3 * t * t * (1 - t) * p2x + t * t * t * p3x
y1 = (1 - t) * (1 - t) * (1 - t) * p0y + 3 * t * (1 - t) * (1 - t) * p1y + 3 * t * t * (1 - t) * p2y + t * t * t * p3y
if i > 1
line1 = entities.add_line [x1, y1, 0] , [x2, y2, 0]
end
x2 = x1
y2 = y1
}
UI.messagebox "ok"
end
以上。