原問題
https://math.pro/db/viewthread.php?tid=3898&page=1#pid26489
使用SketchUp Ruby Code Editor編輯程式碼
https://alexschreyer.net/projects/sketchup-ruby-code-editor/
SketchUp的ruby語法介紹
https://ruby.sketchup.com/Sketchup.html
程式碼
# Default code
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
###########先產生動畫所需的各個群組###########
#半徑10的圓
circle=ent.add_circle [0,0,0],[0,0,1],10
#將圓的各頂點形成面
cv_arr = []
circle.each do |c|
cv_arr << c.vertices[0]
end
face = ent.add_face cv_arr
#新增一個圓的群組
group=ent.add_group(face.all_connected)
group.name="圓"
#新增x軸群組
xline=ent.add_line([-10,0,0],[10,0,0])
group=ent.add_group(xline)
group.name="x軸"
group.visible=false
#新增積分體積群組
pt1=[-10,0,0]
pt2=[-9,Math.sqrt(100-(-9)**2),0]
pt3=[-9,-Math.sqrt(100-(-9)**2),0]
pt4=[-9,0,Math.sqrt(300-3*(-9)**2)]
face=ent.add_face pt1,pt4,pt2
edges=face.edges
for edge in edges
edge.visible=false#將邊隱藏
end
#增加為三角形面
face=ent.add_face pt1,pt4,pt3
edges=face.edges
for edge in edges
edge.visible=false#將邊隱藏
end
#新增正三角形群組
for i in -9..9
x=i
pt1=[i,Math.sqrt(100-i**2),0]
pt2=[i,-Math.sqrt(100-i**2),0]
pt3=[i,0,Math.sqrt(300-3*i**2)]
group = ent.add_group
group.entities.add_curve [pt1,pt2,pt3,pt1]
group.name="正三角形x=#{i}"
group.visible=false
if x==9
break
end
pt4=[i+1,Math.sqrt(100-(i+1)**2),0]
pt5=[i+1,-Math.sqrt(100-(i+1)**2),0]
pt6=[i+1,0,Math.sqrt(300-3*(i+1)**2)]
#增加為四邊形面
face1=ent.add_face pt1 , pt3 , pt6,pt4
edges=face1.edges
for edge in edges
edge.visible=false#將邊隱藏
end
#增加為四邊形面
face2=ent.add_face pt2 , pt3 , pt6,pt5
edges=face2.edges
for edge in edges
edge.visible=false#將邊隱藏
end
end
pt1=[10,0,0]
pt2=[9,Math.sqrt(100-9**2),0]
pt3=[9,-Math.sqrt(100-9**2),0]
pt4=[9,0,Math.sqrt(300-3*9**2)]
face=ent.add_face pt1,pt2,pt4
edges=face.edges
for edge in edges
edge.visible=false#將邊隱藏
end
face=ent.add_face pt1,pt3,pt4
edges=face.edges
for edge in edges
edge.visible=false#將邊隱藏
end
group = ent.add_group(face.all_connected)
group.name="積分體積"
group.visible=false
#複製原本的積分體積群組後再手動刪除一半的面
group2=group.copy
group2.name="積分體積(刪除一半的面)"
group2.visible=false
#新增直角三角形群組
pt2=[-4,Math.sqrt(100-(-4)**2),0]
group = ent.add_group
group.entities.add_line [0,0,0],pt2
group.name="直角三角形"
group.visible=false
###########新增場景,依序顯示各個群組###########
#顯示圓
ent[0].visible=true
pages=mod.pages.add "場景號1"
#顯示x軸
ent[1].visible=true
pages=mod.pages.add "場景號2"
for i in 2..20
ent[ i ].visible=true#顯示正三角形
pages=mod.pages.add "場景號#{i+1}"
end
#顯示積分體積
ent[21].visible=true
pages=mod.pages.add "場景號22"
#只留下x=-6的正三角形,其餘正三角形隱藏
for i in 2..6
ent[ i ].visible=false
end
for i in 8..20
ent[ i ].visible=false
end
pages=mod.pages.add "場景號23"
#改顯示積分體積(刪除一半的面)
ent[21].visible=false
ent[22].visible=true
pages=mod.pages.add "場景號24"
#顯示直角三角形
ent[23].visible=true
pages=mod.pages.add "場景號25"
SketchUp檔下載