forked from adavidzh/SketchUpCMS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw_solids.rb
More file actions
executable file
·218 lines (173 loc) · 7.44 KB
/
draw_solids.rb
File metadata and controls
executable file
·218 lines (173 loc) · 7.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Tai Sakuma <sakuma@fnal.gov>
require 'sketchup'
require File.dirname(__FILE__) + '/sitecfg.rb'
load 'solids.rb'
##____________________________________________________________________________||
def draw_solids
def test_draw_Box entities
box = draw_Box entities, {"dx" => 0.2.m, "dy" => 0.3.m, "dz" => 0.5.m}
box.move! Geom::Transformation.translation(Geom::Vector3d.new(0, 0, 0.3.m))
model = Sketchup.active_model
layer = model.layers.add(model.layers.unique_name('Box'))
box.layer = layer
end
def test_draw_Cone entities
args = Hash.new
args["startPhi"] = 210.degrees
args["deltaPhi"] = 240.degrees
args["dz"] = 0.5.m
args["rMin1"] = 0.1.m
args["rMax1"] = 0.2.m
args["rMin2"] = 0.2.m
args["rMax2"] = 0.3.m
s1 = draw_Cone entities, args
s1.move! Geom::Transformation.translation(Geom::Vector3d.new(0, 1.m, 0.3.m))
model = Sketchup.active_model
layer = model.layers.add(model.layers.unique_name('Cone'))
s1.layer = layer
end
def test_draw_Polycone entities
args = Hash.new
args["startPhi"] = 210.degrees
args["deltaPhi"] = 240.degrees
args["ZSection"] = Array.new
args["ZSection"] << {"z" => -0.5.m, "rMin" => 0.1.m, "rMax" => 0.3.m}
args["ZSection"] << {"z" => -0.2.m, "rMin" => 0.2.m, "rMax" => 0.4.m}
args["ZSection"] << {"z" => 0.4.m, "rMin" => 0.2.m, "rMax" => 0.3.m}
s1 = draw_Polycone entities, args
s1.move! Geom::Transformation.translation(Geom::Vector3d.new(0, 2.m, 0.4.m))
model = Sketchup.active_model
layer = model.layers.add(model.layers.unique_name('Polycone'))
s1.layer = layer
end
def test_draw_Tubs entities
s1 = draw_Tubs entities, {"dz" => 0.5.m, "startPhi" => 210.degrees, "deltaPhi" => 240.degrees, "rMin" => 0.3.m, "rMax" => 0.4.m}
s1.move! Geom::Transformation.translation(Geom::Vector3d.new(0, 3.m, 0.4.m))
model = Sketchup.active_model
layer = model.layers.add(model.layers.unique_name('Tubs'))
s1.layer = layer
end
def test_draw_Torus entities
args = Hash.new
args["innerRadius"] = 0.05.m
args["outerRadius"] = 0.1.m
args["deltaPhi"] = 240.degrees
args["startPhi"] = 210.degrees
args["torusRadius"] = 0.3.m
s1 = draw_Torus entities, args
s1.move! Geom::Transformation.translation(Geom::Vector3d.new(0, 4.m, 0.4.m))
model = Sketchup.active_model
layer = model.layers.add(model.layers.unique_name('Torus'))
s1.layer = layer
end
def test_draw_Polyhedra entities
args = {
"ZSection"=>[
{"rMax"=>0.4.m, "rMin"=>0.3.m, "z"=>-0.5.m},
{"rMax"=>0.3.m, "rMin"=>0.2.m, "z"=>-0.2.m},
{"rMax"=>0.4.m, "rMin"=>0.3.m, "z"=>0.5.m},
],
"deltaPhi"=>240.degrees,
"startPhi"=>210.degrees,
"numSide"=>6}
s1 = draw_Polyhedra entities, args
s1.move! Geom::Transformation.translation(Geom::Vector3d.new(0, 5.m, 0.4.m))
model = Sketchup.active_model
layer = model.layers.add(model.layers.unique_name('Polyhedra'))
s1.layer = layer
end
def test_draw_PseudoTrap entities
args = {
"dx1"=>0.1.m, "dx2"=>0.4.m,
"dy1"=>0.1.m, "dy2"=>0.1.m,
"dz"=>0.5.m
}
s1 = draw_PseudoTrap entities, args
s1.move! Geom::Transformation.translation(Geom::Vector3d.new(0, 6.m, 0.1.m))
model = Sketchup.active_model
layer = model.layers.add(model.layers.unique_name('PseudoTrap'))
s1.layer = layer
end
def test_draw_Trapezoid entities
args = {
"dz"=>0.5.m, "theta"=>20.0.degrees, "phi"=>0.0,
"h1"=>0.2.m, "bl1"=>0.15.m, "tl1"=>0.150.m, "alp1"=>10.0.degrees,
"h2"=>0.2.m, "bl2"=>0.304.m, "tl2"=>0.304.m, "alp2"=>10.0.degrees
}
s1 = draw_Trapezoid entities, args
s1.move! Geom::Transformation.translation(Geom::Vector3d.new(0, 7.m, 0.2.m))
model = Sketchup.active_model
layer = model.layers.add(model.layers.unique_name('Trapezoid'))
s1.layer = layer
end
def test_draw_UnionSolid entities
# CHIMNEY_HOLE_N_c
solid1 = draw_Box(entities, {"dz"=>16.3385826771653, "dx"=>5.90551181102362, "dy"=>9.84251968503937})
solid1 = solid1.to_component.definition
# CHIMNEY_HOLE_N_a
solid2 = draw_Tubs(entities, {"rMax"=>28.5433070866142, "dz"=>16.3385826771653, "deltaPhi"=>3.14159265358979, "rMin"=>0.0, "startPhi"=>1.5707963267949})
solid2 = solid2.to_component.definition
entities.clear!
origin = Geom::Point3d.new 0, 0, 0
transform = Geom::Transformation.new origin
rotation = Geom::Transformation.new origin
vector = Geom::Vector3d.new 0, -0.15.m, 0
translation = Geom::Transformation.translation vector
args = Hash.new
args["rSolid"] = [solid1, solid2]
args["rRotation"] = rotation
args["Translation"] = translation
draw_UnionSolid(entities, args)
# {"rSolid"=>[{"name"=>"CHIMNEY_HOLE_N_c"}, {"name"=>"CHIMNEY_HOLE_N_a"}], "rRotation"=>[{"name"=>"rotations:000D"}], "Translation"=>[{"x"=>"-0.15*m", "y"=>"0.*fm", "z"=>"0.*fm"}]}
end
def test_draw_SubtractionSolid entities
# "MGNT_0"
args = Hash.new
args["startPhi"] = 0
args["deltaPhi"] = 6.28318530717959
args["ZSection"] = Array.new
args["ZSection"] << {"rMax"=>148.425196850394, "z"=>-255.905511811024, "rMin"=>116.929133858268}
args["ZSection"] << {"rMax"=>148.425196850394, "z"=>-86.6141732283465, "rMin"=>116.929133858268}
args["ZSection"] << {"rMax"=>149.606299212598, "z"=>-86.6141732283465, "rMin"=>116.929133858268}
args["ZSection"] << {"rMax"=>149.606299212598, "z"=>86.6141732283465, "rMin"=>116.929133858268}
args["ZSection"] << {"rMax"=>148.425196850394, "z"=>86.6141732283465, "rMin"=>116.929133858268}
args["ZSection"] << {"rMax"=>148.425196850394, "z"=>255.905511811024, "rMin"=>116.929133858268}
solid1 = draw_Polycone(entities, args)
solid1 = solid1.to_component.definition
# "CHIMNEY_HOLE_P"
solid2 = draw_Tubs(entities, {"rMax"=>18.8976377952756, "dz"=>16.3385826771653, "deltaPhi"=>6.28318530717959, "rMin"=>0.0, "startPhi"=>0.0})
solid2 = solid2.to_component.definition
entities.clear!
origin = Geom::Point3d.new 0, 0, 0
# RMCHIMHOLEP" thetaX="90*deg" phiX="00*deg" thetaY="180*deg" phiY="90*deg" thetaZ="90*deg" phiZ="90*deg"/>
xaxis = Geom::Vector3d.new Math::cos(Math::PI/2), Math::sin(Math::PI/2)*Math::cos(0), Math::sin(Math::PI/2)*Math::sin(0)
yaxis = Geom::Vector3d.new Math::cos(Math::PI), Math::sin(Math::PI)*Math::cos(Math::PI/2), Math::sin(Math::PI)*Math::sin(Math::PI/2)
zaxis = Geom::Vector3d.new Math::cos(Math::PI/2), Math::sin(Math::PI/2)*Math::cos(Math::PI/2), Math::sin(Math::PI/2)*Math::sin(Math::PI/2)
rotation = Geom::Transformation.axes origin, zaxis, xaxis, yaxis
vector = Geom::Vector3d.new 1.471.m, 0, 3.385.m
translation = Geom::Transformation.translation vector
args = Hash.new
args["rSolid"] = [solid1, solid2]
args["rRotation"] = rotation
args["Translation"] = translation
draw_SubtractionSolid(entities, args)
end
model = Sketchup.active_model
model.layers.purge_unused
entities = model.entities
test_draw_Box entities
test_draw_Cone entities
test_draw_Polycone entities
test_draw_Tubs entities
test_draw_Torus entities
test_draw_Polyhedra entities
test_draw_PseudoTrap entities
test_draw_Trapezoid entities
# test_draw_Cylinder entities
# test_draw_Polycone_2pi entities
# test_draw_Polycone_BeamVacuum5 entities
# test_draw_CALO entities
# test_draw_UnionSolid entities
# test_draw_SubtractionSolid entities
end
draw_solids