1 package net.sf.openrocket.rocketcomponent;
3 import static org.junit.Assert.assertEquals;
4 import net.sf.openrocket.material.Material;
5 import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
9 public class SymmetricComponentVolumeTest extends BaseTestCase {
12 public void simpleConeFilled() {
13 NoseCone nc = new NoseCone();
15 final double epsilonPercent = 0.001;
16 final double density = 2.0;
20 nc.setType( Transition.Shape.CONICAL );
22 nc.setMaterial( new Material.Bulk("test",density,true));
24 System.out.println( nc.getComponentVolume() );
26 double volume = Math.PI / 3.0;
28 double mass = density * volume;
30 System.out.println( volume );
32 assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
33 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
37 public void simpleConeWithShoulderFilled() {
38 NoseCone nc = new NoseCone();
40 final double epsilonPercent = 0.001;
41 final double density = 2.0;
45 nc.setType( Transition.Shape.CONICAL );
47 nc.setAftShoulderRadius(1.0);
48 nc.setAftShoulderLength(1.0);
49 nc.setAftShoulderThickness(1.0);
50 nc.setMaterial( new Material.Bulk("test",density,true));
53 System.out.println( nc.getComponentVolume() + "\t" + nc.getMass() );
55 double volume = Math.PI / 3.0;
58 double mass = density * volume;
60 System.out.println( volume + "\t" + mass );
63 //assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
64 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
68 public void simpleConeHollow() {
69 NoseCone nc = new NoseCone();
71 final double epsilonPercent = 0.001;
72 final double density = 2.0;
77 nc.setType( Transition.Shape.CONICAL );
78 nc.setMaterial( new Material.Bulk("test",density,true));
80 System.out.println( nc.getComponentVolume() );
82 double volume = Math.PI / 3.0; // outer volume
84 // manually projected Thickness of 0.5 on to radius to determine
85 // the innerConeDimen. Since the outer cone is "square" (height = radius),
86 // we only need to compute this one dimension in order to compute the
87 // volume of the inner cone.
88 double innerConeDimen = 1.0 - Math.sqrt(2.0) / 2.0;
89 double innerVolume = Math.PI / 3.0 * innerConeDimen * innerConeDimen * innerConeDimen;
90 volume -= innerVolume;
92 double mass = density * volume;
94 System.out.println( volume );
96 assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
97 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
101 public void simpleConeWithShoulderHollow() {
102 NoseCone nc = new NoseCone();
104 final double epsilonPercent = 0.001;
105 final double density = 2.0;
108 nc.setType( Transition.Shape.CONICAL );
109 nc.setAftRadius(1.0);
110 nc.setThickness(0.5);
111 nc.setAftShoulderRadius(1.0);
112 nc.setAftShoulderLength(1.0);
113 nc.setAftShoulderThickness(0.5);
114 nc.setMaterial( new Material.Bulk("test",density,true));
117 System.out.println( nc.getComponentVolume() );
119 double volume = Math.PI / 3.0; // outer volume
121 // manually projected Thickness of 0.5 on to radius to determine
122 // the innerConeDimen. Since the outer cone is "square" (height = radius),
123 // we only need to compute this one dimension in order to compute the
124 // volume of the inner cone.
125 double innerConeDimen = 1.0 - Math.sqrt(2.0) / 2.0;
126 double innerVolume = Math.PI / 3.0 * innerConeDimen * innerConeDimen * innerConeDimen;
127 volume -= innerVolume;
129 volume += Math.PI - Math.PI * 0.5 * 0.5;
132 double mass = density * volume;
134 System.out.println( volume );
137 //assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
138 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
142 public void simpleTransitionFilled() {
143 Transition nc = new Transition();
145 final double epsilonPercent = 0.001;
146 final double density = 2.0;
150 nc.setType( Transition.Shape.CONICAL );
151 nc.setForeRadius(1.0);
152 nc.setAftRadius(2.0);
153 nc.setMaterial( new Material.Bulk("test",density,true));
155 System.out.println( nc.getComponentVolume() );
157 double volume = Math.PI / 3.0 * (2.0*2.0 + 2.0 * 1.0 + 1.0 * 1.0) * 4.0;
159 double mass = density * volume;
161 System.out.println( volume );
163 assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
164 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
168 public void simpleTransitionWithShouldersFilled() {
169 Transition nc = new Transition();
171 final double epsilonPercent = 0.001;
172 final double density = 2.0;
176 nc.setType( Transition.Shape.CONICAL );
177 nc.setForeRadius(1.0);
178 nc.setAftRadius(2.0);
179 nc.setAftShoulderLength(1.0);
180 nc.setAftShoulderRadius(2.0);
181 nc.setAftShoulderThickness(2.0);
182 nc.setForeShoulderLength(1.0);
183 nc.setForeShoulderRadius(1.0);
184 nc.setForeShoulderThickness(1.0);
185 nc.setMaterial( new Material.Bulk("test",density,true));
187 System.out.println( nc.getComponentVolume() );
189 double volume = Math.PI / 3.0 * (2.0*2.0 + 2.0 * 1.0 + 1.0 * 1.0) * 4.0;
190 // plus aft shoulder:
191 volume += Math.PI * 1.0 * 2.0 * 2.0;
192 // plus fore shoulder:
193 volume += Math.PI * 1.0 * 1.0 * 1.0;
195 double mass = density * volume;
197 System.out.println( volume );
200 //assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
201 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
205 public void simpleTransitionHollow1() {
206 Transition nc = new Transition();
208 final double epsilonPercent = 0.001;
209 final double density = 2.0;
212 nc.setType( Transition.Shape.CONICAL );
213 nc.setForeRadius(0.5);
214 nc.setAftRadius(1.0);
215 nc.setThickness(0.5);
216 nc.setMaterial( new Material.Bulk("test",density,true));
218 System.out.println( nc.getComponentVolume() );
220 // Volume of filled transition =
221 double filledVolume = Math.PI /3.0 * ( 1.0*1.0 + 1.0 * 0.5 + 0.5 * 0.5 ) * 1.0;
223 // magic 2D cad drawing...
225 // Since the thickness >= fore radius, the
226 // hollowed out portion of the transition
228 // the dimensions of this cone were determined
229 // using a 2d cad tool.
231 double innerConeRadius = 0.441;
232 double innerConeLength = 0.882;
233 double innerVolume = Math.PI /3.0 * innerConeLength * innerConeRadius * innerConeRadius;
235 double volume = filledVolume - innerVolume;
237 double mass = density * volume;
239 System.out.println( volume );
241 assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
242 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
246 public void simpleTransitionWithShouldersHollow1() {
247 Transition nc = new Transition();
249 final double epsilonPercent = 0.001;
250 final double density = 2.0;
253 nc.setType( Transition.Shape.CONICAL );
254 nc.setForeRadius(0.5);
255 nc.setAftRadius(1.0);
256 nc.setThickness(0.5);
257 nc.setAftShoulderLength(1.0);
258 nc.setAftShoulderRadius(1.0);
259 nc.setAftShoulderThickness(0.5);
260 nc.setForeShoulderLength(1.0);
261 nc.setForeShoulderRadius(0.5);
262 nc.setForeShoulderThickness(0.5); // note this means fore shoulder is filled.
263 nc.setMaterial( new Material.Bulk("test",density,true));
265 System.out.println( nc.getComponentVolume() );
267 // Volume of filled transition =
268 double filledVolume = Math.PI /3.0 * ( 1.0*1.0 + 1.0 * 0.5 + 0.5 * 0.5 ) * 1.0;
270 // magic 2D cad drawing...
272 // Since the thickness >= fore radius, the
273 // hollowed out portion of the transition
275 // the dimensions of this cone were determined
276 // using a 2d cad tool.
278 double innerConeRadius = 0.441;
279 double innerConeLength = 0.882;
280 double innerVolume = Math.PI /3.0 * innerConeLength * innerConeRadius * innerConeRadius;
282 double volume = filledVolume - innerVolume;
284 // Now add aft shoulder
285 volume += Math.PI * 1.0 * 1.0 * 1.0 - Math.PI * 1.0 * 0.5 * 0.5;
286 // Now add fore shoulder
287 volume += Math.PI * 1.0 * 0.5 * 0.5;
289 double mass = density * volume;
291 System.out.println( volume );
294 //assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
295 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
299 public void simpleTransitionHollow2() {
300 Transition nc = new Transition();
302 final double epsilonPercent = 0.001;
303 final double density = 2.0;
306 nc.setType( Transition.Shape.CONICAL );
307 nc.setForeRadius(0.5);
308 nc.setAftRadius(1.0);
309 nc.setThickness(0.25);
310 nc.setMaterial( new Material.Bulk("test",density,true));
312 System.out.println( nc.getComponentVolume() );
314 // Volume of filled transition =
315 double filledVolume = Math.PI /3.0 * ( 1.0*1.0 + 1.0 * 0.5 + 0.5 * 0.5 ) * 1.0;
317 // magic 2D cad drawing...
319 // Since the thickness < fore radius, the
320 // hollowed out portion of the transition
321 // forms a transition.
322 // the dimensions of this transition were determined
323 // using a 2d cad tool.
325 double innerTransitionAftRadius = 0.7205;
326 double innerTransitionForeRadius = 0.2205;
327 double innerVolume = Math.PI /3.0 * ( innerTransitionAftRadius * innerTransitionAftRadius + innerTransitionAftRadius * innerTransitionForeRadius + innerTransitionForeRadius * innerTransitionForeRadius);
329 double volume = filledVolume - innerVolume;
331 double mass = density * volume;
333 System.out.println( volume );
335 assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
336 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
340 public void simpleTransitionWithShouldersHollow2() {
341 Transition nc = new Transition();
343 final double epsilonPercent = 0.001;
344 final double density = 2.0;
347 nc.setType( Transition.Shape.CONICAL );
348 nc.setForeRadius(0.5);
349 nc.setAftRadius(1.0);
350 nc.setThickness(0.25);
351 nc.setAftShoulderLength(1.0);
352 nc.setAftShoulderRadius(1.0);
353 nc.setAftShoulderThickness(0.25);
354 nc.setForeShoulderLength(1.0);
355 nc.setForeShoulderRadius(0.5);
356 nc.setForeShoulderThickness(0.25);
358 nc.setMaterial( new Material.Bulk("test",density,true));
360 System.out.println( nc.getComponentVolume() );
362 // Volume of filled transition =
363 double filledVolume = Math.PI /3.0 * ( 1.0*1.0 + 1.0 * 0.5 + 0.5 * 0.5 ) * 1.0;
365 // magic 2D cad drawing...
367 // Since the thickness < fore radius, the
368 // hollowed out portion of the transition
369 // forms a transition.
370 // the dimensions of this transition were determined
371 // using a 2d cad tool.
373 double innerTransitionAftRadius = 0.7205;
374 double innerTransitionForeRadius = 0.2205;
375 double innerVolume = Math.PI /3.0 * ( innerTransitionAftRadius * innerTransitionAftRadius + innerTransitionAftRadius * innerTransitionForeRadius + innerTransitionForeRadius * innerTransitionForeRadius);
377 double volume = filledVolume - innerVolume;
379 // now add aft shoulder
380 volume += Math.PI * 1.0 * 1.0 * 1.0 - Math.PI * 1.0 * 0.75 * 0.75;
381 // now add fore shoulder
382 volume += Math.PI * 1.0 * 0.5 * 0.5 - Math.PI * 1.0 * 0.25 * 0.25;
385 double mass = density * volume;
387 System.out.println( volume );
390 //assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
391 assertEquals( mass, nc.getMass(), epsilonPercent * mass );