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 );
62 assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
63 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
67 public void simpleConeHollow() {
68 NoseCone nc = new NoseCone();
70 final double epsilonPercent = 0.001;
71 final double density = 2.0;
76 nc.setType( Transition.Shape.CONICAL );
77 nc.setMaterial( new Material.Bulk("test",density,true));
79 System.out.println( nc.getComponentVolume() );
81 double volume = Math.PI / 3.0; // outer volume
83 // manually projected Thickness of 0.5 on to radius to determine
84 // the innerConeDimen. Since the outer cone is "square" (height = radius),
85 // we only need to compute this one dimension in order to compute the
86 // volume of the inner cone.
87 double innerConeDimen = 1.0 - Math.sqrt(2.0) / 2.0;
88 double innerVolume = Math.PI / 3.0 * innerConeDimen * innerConeDimen * innerConeDimen;
89 volume -= innerVolume;
91 double mass = density * volume;
93 System.out.println( volume );
95 assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
96 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
100 public void simpleConeWithShoulderHollow() {
101 NoseCone nc = new NoseCone();
103 final double epsilonPercent = 0.001;
104 final double density = 2.0;
107 nc.setType( Transition.Shape.CONICAL );
108 nc.setAftRadius(1.0);
109 nc.setThickness(0.5);
110 nc.setAftShoulderRadius(1.0);
111 nc.setAftShoulderLength(1.0);
112 nc.setAftShoulderThickness(0.5);
113 nc.setMaterial( new Material.Bulk("test",density,true));
116 System.out.println( nc.getComponentVolume() );
118 double volume = Math.PI / 3.0; // outer volume
120 // manually projected Thickness of 0.5 on to radius to determine
121 // the innerConeDimen. Since the outer cone is "square" (height = radius),
122 // we only need to compute this one dimension in order to compute the
123 // volume of the inner cone.
124 double innerConeDimen = 1.0 - Math.sqrt(2.0) / 2.0;
125 double innerVolume = Math.PI / 3.0 * innerConeDimen * innerConeDimen * innerConeDimen;
126 volume -= innerVolume;
128 volume += Math.PI - Math.PI * 0.5 * 0.5;
131 double mass = density * volume;
133 System.out.println( volume );
135 assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
136 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
140 public void simpleTransitionFilled() {
141 Transition nc = new Transition();
143 final double epsilonPercent = 0.001;
144 final double density = 2.0;
148 nc.setType( Transition.Shape.CONICAL );
149 nc.setForeRadius(1.0);
150 nc.setAftRadius(2.0);
151 nc.setMaterial( new Material.Bulk("test",density,true));
153 System.out.println( nc.getComponentVolume() );
155 double volume = Math.PI / 3.0 * (2.0*2.0 + 2.0 * 1.0 + 1.0 * 1.0) * 4.0;
157 double mass = density * volume;
159 System.out.println( volume );
161 assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
162 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
166 public void simpleTransitionWithShouldersFilled() {
167 Transition nc = new Transition();
169 final double epsilonPercent = 0.001;
170 final double density = 2.0;
174 nc.setType( Transition.Shape.CONICAL );
175 nc.setForeRadius(1.0);
176 nc.setAftRadius(2.0);
177 nc.setAftShoulderLength(1.0);
178 nc.setAftShoulderRadius(2.0);
179 nc.setAftShoulderThickness(2.0);
180 nc.setForeShoulderLength(1.0);
181 nc.setForeShoulderRadius(1.0);
182 nc.setForeShoulderThickness(1.0);
183 nc.setMaterial( new Material.Bulk("test",density,true));
185 System.out.println( nc.getComponentVolume() );
187 double volume = Math.PI / 3.0 * (2.0*2.0 + 2.0 * 1.0 + 1.0 * 1.0) * 4.0;
188 // plus aft shoulder:
189 volume += Math.PI * 1.0 * 2.0 * 2.0;
190 // plus fore shoulder:
191 volume += Math.PI * 1.0 * 1.0 * 1.0;
193 double mass = density * volume;
195 System.out.println( volume );
197 assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
198 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
202 public void simpleTransitionHollow1() {
203 Transition nc = new Transition();
205 final double epsilonPercent = 0.001;
206 final double density = 2.0;
209 nc.setType( Transition.Shape.CONICAL );
210 nc.setForeRadius(0.5);
211 nc.setAftRadius(1.0);
212 nc.setThickness(0.5);
213 nc.setMaterial( new Material.Bulk("test",density,true));
215 System.out.println( nc.getComponentVolume() );
217 // Volume of filled transition =
218 double filledVolume = Math.PI /3.0 * ( 1.0*1.0 + 1.0 * 0.5 + 0.5 * 0.5 ) * 1.0;
220 // magic 2D cad drawing...
222 // Since the thickness >= fore radius, the
223 // hollowed out portion of the transition
225 // the dimensions of this cone were determined
226 // using a 2d cad tool.
228 double innerConeRadius = 0.441;
229 double innerConeLength = 0.882;
230 double innerVolume = Math.PI /3.0 * innerConeLength * innerConeRadius * innerConeRadius;
232 double volume = filledVolume - innerVolume;
234 double mass = density * volume;
236 System.out.println( volume );
238 assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
239 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
243 public void simpleTransitionWithShouldersHollow1() {
244 Transition nc = new Transition();
246 final double epsilonPercent = 0.001;
247 final double density = 2.0;
250 nc.setType( Transition.Shape.CONICAL );
251 nc.setForeRadius(0.5);
252 nc.setAftRadius(1.0);
253 nc.setThickness(0.5);
254 nc.setAftShoulderLength(1.0);
255 nc.setAftShoulderRadius(1.0);
256 nc.setAftShoulderThickness(0.5);
257 nc.setForeShoulderLength(1.0);
258 nc.setForeShoulderRadius(0.5);
259 nc.setForeShoulderThickness(0.5); // note this means fore shoulder is filled.
260 nc.setMaterial( new Material.Bulk("test",density,true));
262 System.out.println( nc.getComponentVolume() );
264 // Volume of filled transition =
265 double filledVolume = Math.PI /3.0 * ( 1.0*1.0 + 1.0 * 0.5 + 0.5 * 0.5 ) * 1.0;
267 // magic 2D cad drawing...
269 // Since the thickness >= fore radius, the
270 // hollowed out portion of the transition
272 // the dimensions of this cone were determined
273 // using a 2d cad tool.
275 double innerConeRadius = 0.441;
276 double innerConeLength = 0.882;
277 double innerVolume = Math.PI /3.0 * innerConeLength * innerConeRadius * innerConeRadius;
279 double volume = filledVolume - innerVolume;
281 // Now add aft shoulder
282 volume += Math.PI * 1.0 * 1.0 * 1.0 - Math.PI * 1.0 * 0.5 * 0.5;
283 // Now add fore shoulder
284 volume += Math.PI * 1.0 * 0.5 * 0.5;
286 double mass = density * volume;
288 System.out.println( volume );
290 assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
291 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
295 public void simpleTransitionHollow2() {
296 Transition nc = new Transition();
298 final double epsilonPercent = 0.001;
299 final double density = 2.0;
302 nc.setType( Transition.Shape.CONICAL );
303 nc.setForeRadius(0.5);
304 nc.setAftRadius(1.0);
305 nc.setThickness(0.25);
306 nc.setMaterial( new Material.Bulk("test",density,true));
308 System.out.println( nc.getComponentVolume() );
310 // Volume of filled transition =
311 double filledVolume = Math.PI /3.0 * ( 1.0*1.0 + 1.0 * 0.5 + 0.5 * 0.5 ) * 1.0;
313 // magic 2D cad drawing...
315 // Since the thickness < fore radius, the
316 // hollowed out portion of the transition
317 // forms a transition.
318 // the dimensions of this transition were determined
319 // using a 2d cad tool.
321 double innerTransitionAftRadius = 0.7205;
322 double innerTransitionForeRadius = 0.2205;
323 double innerVolume = Math.PI /3.0 * ( innerTransitionAftRadius * innerTransitionAftRadius + innerTransitionAftRadius * innerTransitionForeRadius + innerTransitionForeRadius * innerTransitionForeRadius);
325 double volume = filledVolume - innerVolume;
327 double mass = density * volume;
329 System.out.println( volume );
331 assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
332 assertEquals( mass, nc.getMass(), epsilonPercent * mass );
336 public void simpleTransitionWithShouldersHollow2() {
337 Transition nc = new Transition();
339 final double epsilonPercent = 0.001;
340 final double density = 2.0;
343 nc.setType( Transition.Shape.CONICAL );
344 nc.setForeRadius(0.5);
345 nc.setAftRadius(1.0);
346 nc.setThickness(0.25);
347 nc.setAftShoulderLength(1.0);
348 nc.setAftShoulderRadius(1.0);
349 nc.setAftShoulderThickness(0.25);
350 nc.setForeShoulderLength(1.0);
351 nc.setForeShoulderRadius(0.5);
352 nc.setForeShoulderThickness(0.25);
354 nc.setMaterial( new Material.Bulk("test",density,true));
356 System.out.println( nc.getComponentVolume() );
358 // Volume of filled transition =
359 double filledVolume = Math.PI /3.0 * ( 1.0*1.0 + 1.0 * 0.5 + 0.5 * 0.5 ) * 1.0;
361 // magic 2D cad drawing...
363 // Since the thickness < fore radius, the
364 // hollowed out portion of the transition
365 // forms a transition.
366 // the dimensions of this transition were determined
367 // using a 2d cad tool.
369 double innerTransitionAftRadius = 0.7205;
370 double innerTransitionForeRadius = 0.2205;
371 double innerVolume = Math.PI /3.0 * ( innerTransitionAftRadius * innerTransitionAftRadius + innerTransitionAftRadius * innerTransitionForeRadius + innerTransitionForeRadius * innerTransitionForeRadius);
373 double volume = filledVolume - innerVolume;
375 // now add aft shoulder
376 volume += Math.PI * 1.0 * 1.0 * 1.0 - Math.PI * 1.0 * 0.75 * 0.75;
377 // now add fore shoulder
378 volume += Math.PI * 1.0 * 0.5 * 0.5 - Math.PI * 1.0 * 0.25 * 0.25;
381 double mass = density * volume;
383 System.out.println( volume );
385 assertEquals( volume, nc.getComponentVolume(), epsilonPercent * volume);
386 assertEquals( mass, nc.getMass(), epsilonPercent * mass );