48 12345
發新話題
打印

[3D 建模軟體] SketchUp

TOP

TOP

原問題https://math.pro/db/viewthread.php?tid=3508&page=1#pid22993

Keyframe Animation 1.6只支援元件移動動畫功能,需安裝Keyframe Animation 2.5才有元件縮放大小動畫功能。
https://regular-polygon.com/keyframe-animation/download/



SketchUp檔下載

TOP

TOP

原問題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檔下載

TOP

原問題https://math.pro/db/viewthread.php?tid=3944&page=1#pid26856

程式碼
# Default code
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
###########先產生動畫所需的各個群組###########
#半徑30的圓
circle=ent.add_circle [0,0,0],[0,0,1],30
#將圓的各頂點形成面
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)
#縮成一個橢圓
t = Geom::Transformation.scaling(1.0, 0.6666, 1.0)
group.transform!(t)
group.name="橢圓"

#新增x軸群組
xline=ent.add_line([-30,0,0],[30,0,0])
group=ent.add_group(xline)
group.name="x軸"
group.visible=false

#新增y軸群組
yline=ent.add_line([0,20,0],[0,-20,0])
group=ent.add_group(yline)
group.name="x軸"
group.visible=false

#新增積分體積群組
#當x=-27時,(-27)^2/900+y^2/400=1,y=±√76
x=-27
y=Math.sqrt(76)
z=2*y
pt0=[-30,0,0]
pt1=[x,y,0]
pt2=[x,y,z]
pt3=[x,-y,z]
pt4=[x,-y,0]
#增加為正方形面
face=ent.add_face pt0,pt1,pt2
face=ent.add_face pt0,pt2,pt3
face=ent.add_face pt0,pt3,pt4

#新增正方形群組
for i in -9..9
  x=i*3
  y=Math.sqrt(400-(x**2)*4/9)
  z=2*y
  pt1=[x,y,0]
  pt2=[x,y,z]
  pt3=[x,-y,z]
  pt4=[x,-y,0]
  
  group = ent.add_group
  group.entities.add_curve [pt1,pt2,pt3,pt4,pt1]
  group.name="正方形x=#{x}"
  group.visible=false
  if x==27
    break
  end
  x=(i+1)*3
  y=Math.sqrt(400-(x**2)*4/9)
  z=2*y
  pt5=[x,y,0]
  pt6=[x,y,z]
  pt7=[x,-y,z]
  pt8=[x,-y,0]
  #增加為四邊形面
  face=ent.add_face pt1,pt5,pt6,pt2
  face=ent.add_face pt2,pt3,pt7,pt6
  face=ent.add_face pt4,pt3,pt7,pt8
end

x=27
y=Math.sqrt(76)
z=2*y
pt1=[x,y,0]
pt2=[x,y,z]
pt3=[x,-y,z]
pt4=[x,-y,0]
pt0=[30,0,0]

#增加為正方形面
face=ent.add_face pt0,pt1,pt2
face=ent.add_face pt0,pt2,pt3
face=ent.add_face pt0,pt3,pt4
#將所有連接平面的邊都隱藏起來
for edge in face.all_connected.grep(Sketchup::Edge)
  edge.visible=false#將邊隱藏
end
#將所有連接平面的面都反轉過來
for faces in face.all_connected.grep(Sketchup::Face)
  faces.reverse!
end

group = ent.add_group(face.all_connected)
group.name="積分體積"
group.visible=false

#複製原本的積分體積群組後再手動刪除一半的面
group2=group.copy
group2.name="積分體積(刪除一半的面)"
group2.visible=false
###########新增場景,依序顯示各個群組###########
#顯示橢圓
ent[0].visible=true
pages=mod.pages.add "場景號1"
#顯示x軸y軸
ent[1].visible=true
ent[2].visible=true
pages=mod.pages.add "場景號2"
for i in 3..21
  ent[ i ].visible=true#顯示正方形
  pages=mod.pages.add "場景號#{i+1}"
end
#顯示積分體積
ent[22].visible=true
pages=mod.pages.add "場景號22"
#只留下x=-12的正方形,其餘正方形隱藏
for i in 3..7
  ent[ i ].visible=false
end
for i in 9..21
  ent[ i ].visible=false
end
pages=mod.pages.add "場景號23"
#改顯示積分體積(刪除一半的面)
ent[22].visible=false
ent[23].visible=true
pages=mod.pages.add "場景號24"


SketchUp檔下載

TOP

原問題https://math.pro/db/viewthread.php?tid=3830&page=1#pid25718

程式碼
# Default code, use or delete...
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection

#ent.add_face [5,5,0],[5,-5,0],[-5,-5,0],[-5,5,0]

r=5*Math.sqrt(2)
group = ent.add_group
group.entities.add_arc [0,0,0],[1,1,0],[1,-1,0],r,0.degrees,180.degrees
group.name="半圓形1"
group.visible=false

group = ent.add_group
group.entities.add_arc [0,0,0],[-1,1,0],[1,1,0],r,0.degrees,180.degrees
group.name="半圓形2"
group.visible=false

face=ent.add_face [5,5,0],[-5,5,0],[-5,-5,0],[5,-5,0]
for z in 0..6
  x=Math.sqrt((r**2-z**2)/2)
  y=x
  pt1=[x,y,z]
  pt2=[-x,y,z]
  pt3=[-x,-y,z]
  pt4=[x,-y,z]
  group = ent.add_group
  group.entities.add_curve [pt1,pt2,pt3,pt4,pt1]
  group.name="正方形z=#{z}"
  group.visible=false
  if z==6
    break
  end
  x=Math.sqrt((r**2-(z+1)**2)/2)
  y=x
  pt5=[x,y,z+1]
  pt6=[-x,y,z+1]
  pt7=[-x,-y,z+1]
  pt8=[x,-y,z+1]
  #增加為四邊形面
  face=ent.add_face pt1,pt5,pt8,pt4
  face=ent.add_face pt1,pt2,pt6,pt5
  face=ent.add_face pt2,pt3,pt7,pt6
  face=ent.add_face pt3,pt4,pt8,pt7
end
pt9=[0,0,r]
face=ent.add_face pt9,pt1,pt2
face=ent.add_face pt9,pt2,pt3
face=ent.add_face pt9,pt3,pt4
face=ent.add_face pt9,pt4,pt1
#將所有連接平面的邊都隱藏起來
for edge in face.all_connected.grep(Sketchup::Edge)
  edge.visible=false#將邊隱藏
end
group = ent.add_group(face.all_connected)
group.name="積分體積"
group.visible=false

#複製原本的積分體積群組後再手動刪除一半的面,選取全部的面再反轉表面
group2=group.copy
group2.name="積分體積(刪除一半的面)"
group2.visible=false

#z軸
group = ent.add_group
group.entities.add_line [0,0,0],[0,0,r]
group.name="z軸"
group.visible=false

#直角三角形
group = ent.add_group
x=Math.sqrt(41/2)
y=-x
group.entities.add_line [0,0,0],[x,y,3]
group.entities.add_line [x,y,3],[0,0,3]
group.name="直角三角形"
group.visible=false
###########新增場景,依序顯示各個群組###########
ent[ 2 ].visible=true#顯示z=0正方形
mod.pages.add "場景號1"

ent[ 0 ].visible=true#顯示半圓形1
mod.pages.add "場景號2"
ent[ 1 ].visible=true#顯示半圓形2
mod.pages.add "場景號3"
for i in 3..8
  ent[ i ].visible=true#顯示正方形
  pages=mod.pages.add "場景號#{i+4}"
end
#顯示積分體積
ent[9].visible=true
pages=mod.pages.add "場景號11"

#只留下z=3的正方形,其餘正方形隱藏
for i in 2..4
  ent[ i ].visible=false
end
for i in 6..8
  ent[ i ].visible=false
end
pages=mod.pages.add "場景號12"
#改顯示積分體積(刪除一半的面)
ent[9].visible=false
ent[10].visible=true
pages=mod.pages.add "場景號13"
#顯示z軸
ent[11].visible=true
pages=mod.pages.add "場景號14"
#顯示直角三角形
ent[12].visible=true
pages=mod.pages.add "場景號15"


SketchUp檔下載

TOP

原問題https://math.pro/db/viewthread.php?tid=1442&page=5#pid8157

程式碼
# Default code, use or delete...
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
#產生拋物線x=y^2線段
pts=[]
13.downto(0){|x| pts << [x, Math::sqrt(10.0*x), 0]}
1.upto(13)  {|x| pts << [x,-Math::sqrt(10.0*x), 0]}
group = ent.add_group
group.entities.add_curve pts
group.name="拋物線x=y^2"
group.visible=false

#產生拋物線x=3-2y^2線段
pts=[]
7.upto(30)  {|x| pts << [x, Math::sqrt(150.0-5*x), 0]}
29.downto(7){|x| pts << [x,-Math::sqrt(150.0-5*x), 0]}
group = ent.add_group
group.entities.add_curve pts
group.name="拋物線x=3-2y^2"
group.visible=false

#產生兩個拋物線交集的底面
pts=[]
0.upto(10) {|x| pts << [x, Math::sqrt(10.0*x), 0]}
11.upto(30){|x| pts << [x, Math::sqrt(150.0-5*x), 0]}
29.downto(10){|x| pts <<[x,-Math::sqrt(150.0-5*x), 0]}
9.downto(0){|x| pts << [x,-Math::sqrt(10.0*x), 0]}
group = ent.add_group
group.entities.add_face pts
group.name="拋物線交集底面"
group.visible=false

#產生正方形框框
for i in 1..14
  x=2.0*i
  #i=1~5拋物線為x=y^2
  #i=6~14拋物線為x=3-2y^2
  i<=5?y=Math::sqrt(10.0*x):y=Math::sqrt(150.0-5*x)
  z=2.0*y
  pt1=[x,y,0]
  pt2=[x,y,z]
  pt3=[x,-y,z]
  pt4=[x,-y,0]
  group = ent.add_group
  group.entities.add_curve [pt1,pt2,pt3,pt4,pt1]
  group.name="正方形x=#{x/10.0}"
  group.visible=false
end

#產生積分體積
ptStart=[0,0,0]
x=1
y=Math::sqrt(10.0*x)
z=2.0*y
pt1=[x,y,0]
pt2=[x,y,z]
pt3=[x,-y,z]
pt4=[x,-y,0]
face=ent.add_face ptStart,pt1,pt2
face=ent.add_face ptStart,pt2,pt3
face=ent.add_face ptStart,pt3,pt4
for i in 2..29
  x=i
  i<=10?y=Math::sqrt(10.0*x):y=Math::sqrt(150.0-5*x)
  z=2.0*y
  pt5=[x,y,0]
  pt6=[x,y,z]
  pt7=[x,-y,z]
  pt8=[x,-y,0]
  face=ent.add_face pt1,pt5,pt6,pt2
  face=ent.add_face pt2,pt3,pt7,pt6
  face=ent.add_face pt4,pt3,pt7,pt8
  pt1=pt5
  pt2=pt6
  pt3=pt7
  pt4=pt8
end
ptEnd=[30,0,0]
face=ent.add_face ptEnd,pt1,pt2
face=ent.add_face ptEnd,pt2,pt3
face=ent.add_face ptEnd,pt3,pt4
#將所有連接平面的邊都隱藏起來
for edge in face.all_connected.grep(Sketchup::Edge)
  edge.visible=false#將邊隱藏
end
#將所有連接平面的面都反轉過來
for faces in face.all_connected.grep(Sketchup::Face)
  faces.reverse!
end
group = ent.add_group(face.all_connected)
group.name="積分體積"
group.visible=false


#複製原本的積分體積群組後再手動刪除一半的面
group2=group.copy
group2.name="積分體積(刪除一半的面)"
group2.visible=false

#x軸
group = ent.add_group
group.entities.add_line [0,0,0],[30,0,0]
group.name="x軸"
group.visible=false

#x=1線段
group = ent.add_group
group.entities.add_line [10,10,0],[10,-10,0]
group.name="x=1線段"
group.visible=false
###########新增場景,依序顯示各個群組###########
ent[ 0 ].visible=true#顯示拋物線x=y^2
mod.pages.add "場景號1"

ent[ 1 ].visible=true#顯示拋物線x=3-2y^2
mod.pages.add "場景號2"

ent[ 2 ].visible=true#顯示拋物線交集底面
mod.pages.add "場景號3"

for i in 3..16
  ent[ i ].visible=true#顯示正方形
  pages=mod.pages.add "場景號#{i+1}"
end

#顯示積分體積
ent[17].visible=true
pages=mod.pages.add "場景號18"

#只留下x=0.6,2.0的正方形
for i in 3..16
  ent[ i ].visible=false#隱藏正方形
end
ent[ 5 ].visible=true#顯示x=0.6的正方形
ent[ 12].visible=true#顯示x=2.0的正方形
pages=mod.pages.add "場景號19"

#顯示積分體積(刪除一半的面)
ent[17].visible=false
ent[18].visible=true
pages=mod.pages.add "場景號20"

#顯示x軸
ent[19].visible=true
pages=mod.pages.add "場景號21"

#顯示x=1線段
ent[20].visible=true
pages=mod.pages.add "場景號22"


SketchUp檔下載

TOP

 48 12345
發新話題