updates for 0.9.4
[debian/openrocket] / src / net / sf / openrocket / rocketcomponent / Transition.java
1 package net.sf.openrocket.rocketcomponent;
2
3 import static java.lang.Math.*;
4 import static net.sf.openrocket.util.Chars.*;
5 import static net.sf.openrocket.util.MathUtil.*;
6
7 import java.util.Collection;
8
9 import net.sf.openrocket.util.Coordinate;
10 import net.sf.openrocket.util.MathUtil;
11
12
13 public class Transition extends SymmetricComponent {
14         private static final double CLIP_PRECISION = 0.0001;
15         
16         
17         private Shape type;
18         private double shapeParameter;
19         private boolean clipped;    // Not to be read - use isClipped(), which may be overriden
20         
21         private double radius1, radius2;
22         private boolean autoRadius1, autoRadius2;   // Whether the start radius is automatic
23         
24         
25         private double foreShoulderRadius;
26         private double foreShoulderThickness;
27         private double foreShoulderLength;
28         private boolean foreShoulderCapped;
29         private double aftShoulderRadius;
30         private double aftShoulderThickness;
31         private double aftShoulderLength;
32         private boolean aftShoulderCapped;
33         
34         
35         // Used to cache the clip length
36         private double clipLength=-1;
37         
38         public Transition() {
39                 super();
40                 
41                 this.radius1 = DEFAULT_RADIUS;
42                 this.radius2 = DEFAULT_RADIUS;
43                 this.length = DEFAULT_RADIUS * 3;
44                 this.autoRadius1 = true;
45                 this.autoRadius2 = true;
46                 
47                 this.type = Shape.CONICAL;
48                 this.shapeParameter = 0;
49                 this.clipped = true;
50         }
51         
52         
53         
54         
55         ////////  Fore radius  ////////
56         
57         
58         @Override
59         public double getForeRadius() {
60                 if (isForeRadiusAutomatic()) {
61                         // Get the automatic radius from the front
62                         double r = -1;
63                         SymmetricComponent c = this.getPreviousSymmetricComponent();
64                         if (c != null) {
65                                 r = c.getFrontAutoRadius();
66                         }
67                         if (r < 0)
68                                 r = DEFAULT_RADIUS;
69                         return r;
70                 }
71                 return radius1;
72         }
73         
74         public void setForeRadius(double radius) {
75                 if ((this.radius1 == radius) && (autoRadius1 == false))
76                         return;
77                 
78                 this.autoRadius1 = false;
79                 this.radius1 = Math.max(radius,0);
80
81                 if (this.thickness > this.radius1 && this.thickness > this.radius2)
82                         this.thickness = Math.max(this.radius1, this.radius2);
83                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
84         }
85         
86         @Override
87         public boolean isForeRadiusAutomatic() {
88                 return autoRadius1;
89         }
90         
91         public void setForeRadiusAutomatic(boolean auto) {
92                 if (autoRadius1 == auto)
93                         return;
94                 
95                 autoRadius1 = auto;
96                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
97         }
98         
99
100         ////////  Aft radius  /////////
101         
102         @Override
103         public double getAftRadius() {
104                 if (isAftRadiusAutomatic()) {
105                         // Return the auto radius from the rear
106                         double r = -1;
107                         SymmetricComponent c = this.getNextSymmetricComponent();
108                         if (c != null) {
109                                 r = c.getRearAutoRadius();
110                         }
111                         if (r < 0)
112                                 r = DEFAULT_RADIUS;
113                         return r;
114                 }
115                 return radius2;
116         }
117         
118         
119         
120         public void setAftRadius(double radius) {
121                 if ((this.radius2 == radius) && (autoRadius2 == false))
122                         return;
123                 
124                 this.autoRadius2 = false;
125                 this.radius2 = Math.max(radius,0);
126
127                 if (this.thickness > this.radius1 && this.thickness > this.radius2)
128                         this.thickness = Math.max(this.radius1, this.radius2);
129                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
130         }
131
132         @Override
133         public boolean isAftRadiusAutomatic() {
134                 return autoRadius2;
135         }
136         
137         public void setAftRadiusAutomatic(boolean auto) {
138                 if (autoRadius2 == auto)
139                         return;
140                 
141                 autoRadius2 = auto;
142                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
143         }
144         
145         
146         
147         //// Radius automatics
148         
149         @Override
150         protected double getFrontAutoRadius() {
151                 if (isAftRadiusAutomatic())
152                         return -1;
153                 return getAftRadius();
154         }
155
156
157         @Override
158         protected double getRearAutoRadius() {
159                 if (isForeRadiusAutomatic())
160                         return -1;
161                 return getForeRadius();
162         }
163
164
165         
166         
167         ////////  Type & shape  /////////
168         
169         public Shape getType() {
170                 return type;
171         }
172         
173         public void setType(Shape type) {
174                 if (type == null) {
175                         throw new IllegalArgumentException("BUG:  setType called with null argument");
176                 }
177                 if (this.type == type)
178                         return;
179                 this.type = type;
180                 this.clipped = type.isClippable();
181                 this.shapeParameter = type.defaultParameter();
182                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
183         }
184         
185         public double getShapeParameter() {
186                 return shapeParameter;
187         }
188         
189         public void setShapeParameter(double n) {
190                 if (shapeParameter == n)
191                         return;
192                 this.shapeParameter = MathUtil.clamp(n, type.minParameter(), type.maxParameter());
193                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
194         }
195
196         public boolean isClipped() {
197                 if (!type.isClippable())
198                         return false;
199                 return clipped;
200         }
201         
202         public void setClipped(boolean c) {
203                 if (clipped == c)
204                         return;
205                 clipped = c;
206                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
207         }
208         
209         public boolean isClippedEnabled() {
210                 return type.isClippable();
211         }
212
213         public double getShapeParameterMin() {
214                 return type.minParameter();
215         }
216         
217         public double getShapeParameterMax() {
218                 return type.maxParameter();
219         }
220         
221         
222         ////////  Shoulders  ////////
223         
224         public double getForeShoulderRadius() {
225                 return foreShoulderRadius;
226         }
227
228         public void setForeShoulderRadius(double foreShoulderRadius) {
229                 if (MathUtil.equals(this.foreShoulderRadius, foreShoulderRadius))
230                         return;
231                 this.foreShoulderRadius = foreShoulderRadius;
232                 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
233         }
234
235         public double getForeShoulderThickness() {
236                 return foreShoulderThickness;
237         }
238
239         public void setForeShoulderThickness(double foreShoulderThickness) {
240                 if (MathUtil.equals(this.foreShoulderThickness, foreShoulderThickness))
241                         return;
242                 this.foreShoulderThickness = foreShoulderThickness;
243                 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
244         }
245
246         public double getForeShoulderLength() {
247                 return foreShoulderLength;
248         }
249
250         public void setForeShoulderLength(double foreShoulderLength) {
251                 if (MathUtil.equals(this.foreShoulderLength, foreShoulderLength))
252                         return;
253                 this.foreShoulderLength = foreShoulderLength;
254                 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
255         }
256         
257         public boolean isForeShoulderCapped() {
258                 return foreShoulderCapped;
259         }
260         
261         public void setForeShoulderCapped(boolean capped) {
262                 if (this.foreShoulderCapped == capped)
263                         return;
264                 this.foreShoulderCapped = capped;
265                 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
266         }
267
268
269         
270         
271         public double getAftShoulderRadius() {
272                 return aftShoulderRadius;
273         }
274
275         public void setAftShoulderRadius(double aftShoulderRadius) {
276                 if (MathUtil.equals(this.aftShoulderRadius, aftShoulderRadius))
277                         return;
278                 this.aftShoulderRadius = aftShoulderRadius;
279                 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
280         }
281
282         public double getAftShoulderThickness() {
283                 return aftShoulderThickness;
284         }
285
286         public void setAftShoulderThickness(double aftShoulderThickness) {
287                 if (MathUtil.equals(this.aftShoulderThickness, aftShoulderThickness))
288                         return;
289                 this.aftShoulderThickness = aftShoulderThickness;
290                 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
291         }
292
293         public double getAftShoulderLength() {
294                 return aftShoulderLength;
295         }
296
297         public void setAftShoulderLength(double aftShoulderLength) {
298                 if (MathUtil.equals(this.aftShoulderLength, aftShoulderLength))
299                         return;
300                 this.aftShoulderLength = aftShoulderLength;
301                 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
302         }
303         
304         public boolean isAftShoulderCapped() {
305                 return aftShoulderCapped;
306         }
307         
308         public void setAftShoulderCapped(boolean capped) {
309                 if (this.aftShoulderCapped == capped)
310                         return;
311                 this.aftShoulderCapped = capped;
312                 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
313         }
314
315
316         
317         
318         ///////////   Shape implementations   ////////////
319         
320
321
322         /**
323          * Return the radius at point x of the transition.
324          */
325         @Override
326         public double getRadius(double x) {
327                 if (x<0 || x>length)
328                         return 0;
329                 
330                 double r1=getForeRadius();
331                 double r2=getAftRadius();
332
333                 if (r1 == r2)
334                         return r1;
335                 
336                 if (r1 > r2) {
337                         x = length-x;
338                         double tmp = r1;
339                         r1 = r2;
340                         r2 = tmp;
341                 }
342                 
343                 if (isClipped()) {
344                         // Check clip calculation
345                         if (clipLength < 0)
346                                 calculateClip(r1,r2);
347                         return type.getRadius(clipLength+x, r2, clipLength+length, shapeParameter);
348                 } else {
349                         // Not clipped
350                         return r1 + type.getRadius(x, r2-r1, length, shapeParameter);
351                 }
352         }
353
354         /**
355          * Numerically solve clipLength from the equation
356          *     r1 == type.getRadius(clipLength,r2,clipLength+length)
357          * using a binary search.  It assumes getRadius() to be monotonically increasing.
358          */
359         private void calculateClip(double r1, double r2) {
360                 double min=0, max=length;
361                 
362                 if (r1 >= r2) {
363                         double tmp=r1;
364                         r1 = r2;
365                         r2 = tmp;
366                 }
367                 
368                 if (r1==0) {
369                         clipLength = 0;
370                         return;
371                 }
372                 
373                 if (length <= 0) {
374                         clipLength = 0;
375                         return;
376                 }
377                 
378                 // Required:
379                 //    getR(min,min+length,r2) - r1 < 0
380                 //    getR(max,max+length,r2) - r1 > 0
381
382                 int n=0;
383                 while (type.getRadius(max, r2, max+length, shapeParameter) - r1 < 0) {
384                         min = max;
385                         max *= 2;
386                         n++;
387                         if (n>10)
388                                 break;
389                 }
390
391                 while (true) {
392                         clipLength = (min+max)/2;
393                         if ((max-min)<CLIP_PRECISION)
394                                 return;
395                         double val = type.getRadius(clipLength, r2, clipLength+length, shapeParameter);
396                         if (val-r1 > 0) {
397                                 max = clipLength;
398                         } else {
399                                 min = clipLength;
400                         }
401                 }
402         }
403         
404         
405         @Override
406         public double getInnerRadius(double x) {
407                 return Math.max(getRadius(x)-thickness,0);
408         }
409                 
410         
411
412         @Override
413         public Collection<Coordinate> getComponentBounds() {
414                 Collection<Coordinate> bounds = super.getComponentBounds();
415                 if (foreShoulderLength > 0.001)
416                         addBound(bounds, -foreShoulderLength, foreShoulderRadius);
417                 if (aftShoulderLength > 0.001)
418                         addBound(bounds, getLength() + aftShoulderLength, aftShoulderRadius);
419                 return bounds;
420         }
421         
422         @Override
423         public double getComponentMass() {
424                 double mass = super.getComponentMass();
425                 if (getForeShoulderLength() > 0.001) {
426                         final double or = getForeShoulderRadius();
427                         final double ir = Math.max(getForeShoulderRadius() - getForeShoulderThickness(), 0);
428                         mass += ringMass(or, ir, getForeShoulderLength(), getMaterial().getDensity());
429                 }
430                 if (isForeShoulderCapped()) {
431                         final double ir = Math.max(getForeShoulderRadius() - getForeShoulderThickness(), 0);
432                         mass += ringMass(ir, 0, getForeShoulderThickness(), getMaterial().getDensity());
433                 }
434                 
435                 if (getAftShoulderLength() > 0.001) {
436                         final double or = getAftShoulderRadius();
437                         final double ir = Math.max(getAftShoulderRadius() - getAftShoulderThickness(), 0);
438                         mass += ringMass(or, ir, getAftShoulderLength(), getMaterial().getDensity());
439                 }
440                 if (isAftShoulderCapped()) {
441                         final double ir = Math.max(getAftShoulderRadius() - getAftShoulderThickness(), 0);
442                         mass += ringMass(ir, 0, getAftShoulderThickness(), getMaterial().getDensity());
443                 }
444                 
445                 return mass;
446         }
447
448         @Override
449         public Coordinate getComponentCG() {
450                 Coordinate cg = super.getComponentCG();
451                 if (getForeShoulderLength() > 0.001) {
452                         final double ir = Math.max(getForeShoulderRadius() - getForeShoulderThickness(), 0);
453                         cg = cg.average(ringCG(getForeShoulderRadius(), ir, -getForeShoulderLength(), 0,
454                                         getMaterial().getDensity()));
455                 }
456                 if (isForeShoulderCapped()) {
457                         final double ir = Math.max(getForeShoulderRadius() - getForeShoulderThickness(), 0);
458                         cg = cg.average(ringCG(ir, 0, -getForeShoulderLength(), 
459                                         getForeShoulderThickness()-getForeShoulderLength(),
460                                         getMaterial().getDensity()));
461                 }
462                 
463                 if (getAftShoulderLength() > 0.001) {
464                         final double ir = Math.max(getAftShoulderRadius() - getAftShoulderThickness(), 0);
465                         cg = cg.average(ringCG(getAftShoulderRadius(), ir, getLength(), 
466                                         getLength()+getAftShoulderLength(), getMaterial().getDensity()));
467                 }
468                 if (isAftShoulderCapped()) {
469                         final double ir = Math.max(getAftShoulderRadius() - getAftShoulderThickness(), 0);
470                         cg = cg.average(ringCG(ir, 0, 
471                                         getLength()+getAftShoulderLength()-getAftShoulderThickness(), 
472                                         getLength()+getAftShoulderLength(), getMaterial().getDensity()));
473                 }
474                 return cg;
475         }
476
477         
478         /*
479          * The moments of inertia are not explicitly corrected for the shoulders.
480          * However, since the mass is corrected, the inertia is automatically corrected
481          * to very nearly the correct value.
482          */
483
484
485
486         /**
487          * Returns the name of the component ("Transition").
488          */
489         @Override
490         public String getComponentName() {
491                 return "Transition";
492         }
493         
494         @Override
495         protected void componentChanged(ComponentChangeEvent e) {
496                 super.componentChanged(e);
497                 clipLength = -1;
498         }
499         
500         
501         
502         /**
503          * An enumeration listing the possible shapes of transitions.
504          * 
505          * @author Sampo Niskanen <sampo.niskanen@iki.fi>
506          */
507         public static enum Shape {
508
509                 /**
510                  * Conical shape.
511                  */
512                 CONICAL("Conical",
513                                 "A conical nose cone has a profile of a triangle.",
514                                 "A conical transition has straight sides.") {
515                         @Override
516                         public double getRadius(double x, double radius, double length, double param) {
517                                 assert x >= 0;
518                                 assert x <= length;
519                                 assert radius >= 0;
520                                 return radius*x/length;
521                         }
522                 },
523
524                 /**
525                  * Ogive shape.  The shape parameter is the portion of an extended tangent ogive
526                  * that will be used.  That is, for param==1 a tangent ogive will be produced, and
527                  * for smaller values the shape straightens out into a cone at param==0.
528                  */
529                 OGIVE("Ogive",
530                                 "An ogive nose cone has a profile that is a segment of a circle.  " +
531                                 "The shape parameter value 1 produces a <b>tangent ogive</b>, which has " +
532                                 "a smooth transition to the body tube, values less than 1 produce "+
533                                 "<b>secant ogives</b>.",
534                                 "An ogive transition has a profile that is a segment of a circle.  " +
535                                 "The shape parameter value 1 produces a <b>tangent ogive</b>, which has " +
536                                 "a smooth transition to the body tube at the aft end, values less than 1 " +
537                                 "produce <b>secant ogives</b>.") {
538                         @Override
539                         public boolean usesParameter() {
540                                 return true;   // Range 0...1 is default
541                         }
542                         @Override
543                         public double defaultParameter() {
544                                 return 1.0;    // Tangent ogive by default
545                         }
546                         @Override
547                         public double getRadius(double x, double radius, double length, double param) {
548                                 assert x >= 0;
549                                 assert x <= length;
550                                 assert radius >= 0;
551                                 assert param >= 0;
552                                 assert param <= 1;
553                                 
554                                 // Impossible to calculate ogive for length < radius, scale instead
555                                 // TODO: LOW: secant ogive could be calculated lower
556                                 if (length < radius) {
557                                         x = x * radius / length;
558                                         length = radius;
559                                 }
560                                 
561                                 if (param < 0.001)
562                                         return CONICAL.getRadius(x, radius, length, param);
563                                 
564                                 // Radius of circle is:
565                                 double R = sqrt((pow2(length)+pow2(radius)) *
566                                                 (pow2((2-param)*length) + pow2(param*radius))/(4*pow2(param*radius)));
567                                 double L = length/param;
568 //                              double R = (radius + length*length/(radius*param*param))/2;
569                                 double y0 = sqrt(R*R - L*L);
570                                 return sqrt(R*R - (L-x)*(L-x)) - y0;
571                         }
572                 },
573
574                 /**
575                  * Ellipsoidal shape.
576                  */
577                 ELLIPSOID("Ellipsoid",
578                                 "An ellipsoidal nose cone has a profile of a half-ellipse "+
579                                 "with major axes of lengths 2&times;<i>Length</i> and <i>Diameter</i>.",
580                                 "An ellipsoidal transition has a profile of a half-ellipse "+
581                                 "with major axes of lengths 2&times;<i>Length</i> and <i>Diameter</i>.  If the "+
582                                 "transition is not clipped, then the profile is extended at the center by the "+
583                                 "corresponding radius.",true) {
584                         @Override
585                         public double getRadius(double x, double radius, double length, double param) {
586                                 assert x >= 0;
587                                 assert x <= length;
588                                 assert radius >= 0;
589                                 x = x*radius/length;
590                                 return sqrt(2*radius*x-x*x);  // radius/length * sphere
591                         }
592                 },
593
594                 POWER("Power series",
595                                 "A power series nose cone has a profile of "+
596                                 "<i>Radius</i>&nbsp;&times;&nbsp;(<i>x</i>&nbsp;/&nbsp;<i>Length</i>)" +
597                                 "<sup><i>k</i></sup> "+
598                                 "where <i>k</i> is the shape parameter.  For <i>k</i>=0.5 this is a "+
599                                 "<b>" + FRAC12 +"-power</b> or <b>parabolic</b> nose cone, for <i>k</i>=0.75 a "+
600                                 "<b>" + FRAC34 +"-power</b>, and for <i>k</i>=1 a <b>conical</b> nose cone.",
601                                 "A power series transition has a profile of "+
602                                 "<i>Radius</i>&nbsp;&times;&nbsp;(<i>x</i>&nbsp;/&nbsp;<i>Length</i>)" +
603                                 "<sup><i>k</i></sup> "+
604                                 "where <i>k</i> is the shape parameter.  For <i>k</i>=0.5 the transition is "+
605                                 "<b>" + FRAC12 + "-power</b> or <b>parabolic</b>, for <i>k</i>=0.75 a " +
606                                 "<b>" + FRAC34 + "-power</b>, and for <i>k</i>=1 <b>conical</b>.",true) {
607                         @Override
608                         public boolean usesParameter() {  // Range 0...1
609                                 return true;
610                         }
611                         @Override
612                         public double defaultParameter() {
613                                 return 0.5;
614                         }
615                         @Override
616                         public double getRadius(double x, double radius, double length, double param) {
617                                 assert x >= 0;
618                                 assert x <= length;
619                                 assert radius >= 0;
620                                 assert param >= 0;
621                                 assert param <= 1;
622                                 if (param<=0.00001) {
623                                         if (x<=0.00001)
624                                                 return 0;
625                                         else
626                                                 return radius;
627                                 }
628                                 return radius*Math.pow(x/length, param);
629                         }
630                         
631                 },
632                 
633                 PARABOLIC("Parabolic series",
634                                 "A parabolic series nose cone has a profile of a parabola.  The shape "+
635                                 "parameter defines the segment of the parabola to utilize.  The shape " +
636                                 "parameter 1.0 produces a <b>full parabola</b> which is tangent to the body " +
637                                 "tube, 0.75 produces a <b>3/4 parabola</b>, 0.5 procudes a " +
638                                 "<b>1/2 parabola</b> and 0 produces a <b>conical</b> nose cone.",
639                                 "A parabolic series transition has a profile of a parabola.  The shape "+
640                                 "parameter defines the segment of the parabola to utilize.  The shape " +
641                                 "parameter 1.0 produces a <b>full parabola</b> which is tangent to the body " +
642                                 "tube at the aft end, 0.75 produces a <b>3/4 parabola</b>, 0.5 procudes a " +
643                                 "<b>1/2 parabola</b> and 0 produces a <b>conical</b> transition.") {
644                         
645                         // In principle a parabolic transition is clippable, but the difference is
646                         // negligible.
647                         
648                         @Override
649                         public boolean usesParameter() {  // Range 0...1
650                                 return true;
651                         }
652                         @Override
653                         public double defaultParameter() {
654                                 return 1.0;
655                         }
656                         @Override
657                         public double getRadius(double x, double radius, double length, double param) {
658                                 assert x >= 0;
659                                 assert x <= length;
660                                 assert radius >= 0;
661                                 assert param >= 0;
662                                 assert param <= 1;
663
664                                 return radius * ((2*x/length - param*pow2(x/length))/(2-param));
665                         }
666                 },
667                 
668                 
669                 
670                 HAACK("Haack series",
671                                 "The Haack series nose cones are designed to minimize drag.  The shape parameter " +
672                                 "0 produces an <b>LD-Haack</b> or <b>Von Karman</b> nose cone, which minimizes " +
673                                 "drag for fixed length and diameter, while a value of 0.333 produces an " +
674                                 "<b>LV-Haack</b> nose cone, which minimizes drag for fixed length and volume.",
675                                 "The Haack series <i>nose cones</i> are designed to minimize drag.  " +
676                                 "These transition shapes are their equivalents, but do not necessarily produce " +
677                                 "optimal drag for transitions.  " +
678                                 "The shape parameter 0 produces an <b>LD-Haack</b> or <b>Von Karman</b> shape, " +
679                                 "while a value of 0.333 produces an <b>LV-Haack</b> shape.",true) {
680                         @Override
681                         public boolean usesParameter() {
682                                 return true;
683                         }
684                         @Override 
685                         public double maxParameter() {
686                                 return 1.0/3.0;  // Range 0...1/3
687                         }
688                         @Override
689                         public double getRadius(double x, double radius, double length, double param) {
690                                 assert x >= 0;
691                                 assert x <= length;
692                                 assert radius >= 0;
693                                 assert param >= 0;
694                                 assert param <= 2;
695
696                                 double theta = Math.acos(1-2*x/length); 
697                                 if (param==0) {
698                                         return radius*sqrt((theta-sin(2*theta)/2)/Math.PI);
699                                 }
700                                 return radius*sqrt((theta-sin(2*theta)/2+param*pow3(sin(theta)))/Math.PI);
701                         }
702                 },
703                 
704 //              POLYNOMIAL("Smooth polynomial",
705 //                              "A polynomial is fitted such that the nose cone profile is horizontal "+
706 //                              "at the aft end of the transition.  The angle at the tip is defined by "+
707 //                              "the shape parameter.",
708 //                              "A polynomial is fitted such that the transition profile is horizontal "+
709 //                              "at the aft end of the transition.  The angle at the fore end is defined "+
710 //                              "by the shape parameter.") {
711 //                      @Override
712 //                      public boolean usesParameter() {
713 //                              return true;
714 //                      }
715 //                      @Override
716 //                      public double maxParameter() {
717 //                              return 3.0;   //  Range 0...3
718 //                      }
719 //                      @Override
720 //                      public double defaultParameter() {
721 //                              return 0.0;
722 //                      }
723 //                      public double getRadius(double x, double radius, double length, double param) {
724 //                              assert x >= 0;
725 //                              assert x <= length;
726 //                              assert radius >= 0;
727 //                              assert param >= 0;
728 //                              assert param <= 3;
729 //                              // p(x) = (k-2)x^3 + (3-2k)x^2 + k*x
730 //                              x = x/length;
731 //                              return radius*((((param-2)*x + (3-2*param))*x + param)*x);
732 //                      }
733 //              }
734                 ;
735                                                 
736                 // Privete fields of the shapes
737                 private final String name;
738                 private final String transitionDesc;
739                 private final String noseconeDesc;
740                 private final boolean canClip;
741
742                 // Non-clippable constructor
743                 Shape(String name, String noseconeDesc, String transitionDesc) {
744                         this(name,noseconeDesc,transitionDesc,false);
745                 }
746
747                 // Clippable constructor
748                 Shape(String name, String noseconeDesc, String transitionDesc, boolean canClip) {
749                         this.name = name;
750                         this.canClip = canClip;
751                         this.noseconeDesc = noseconeDesc;
752                         this.transitionDesc = transitionDesc;
753                 }
754                 
755                 
756                 /**
757                  * Return the name of the transition shape name.
758                  */
759                 public String getName() {
760                         return name;
761                 }
762                 
763                 /**
764                  * Get a description of the Transition shape.
765                  */
766                 public String getTransitionDescription() {
767                         return transitionDesc;
768                 }
769                 
770                 /**
771                  * Get a description of the NoseCone shape.
772                  */
773                 public String getNoseConeDescription() {
774                         return noseconeDesc;
775                 }
776
777                 /**
778                  * Check whether the shape differs in clipped mode.  The clipping should be
779                  * enabled by default if possible.
780                  */
781                 public boolean isClippable() {
782                         return canClip;
783                 }
784                 
785                 /**
786                  * Return whether the shape uses the shape parameter.  (Default false.)
787                  */
788                 public boolean usesParameter() {
789                         return false;
790                 }
791
792                 /**
793                  * Return the minimum value of the shape parameter.  (Default 0.)
794                  */
795                 public double minParameter() {
796                         return 0.0;
797                 }
798                 
799                 /**
800                  * Return the maximum value of the shape parameter.  (Default 1.)
801                  */
802                 public double maxParameter() {
803                         return 1.0;
804                 }
805                 
806                 /**
807                  * Return the default value of the shape parameter.  (Default 0.)
808                  */
809                 public double defaultParameter() {
810                         return 0.0;
811                 }
812
813                 /**
814                  * Calculate the basic radius of a transition with the given radius, length and
815                  * shape parameter at the point x from the tip of the component.  It is assumed
816                  * that the fore radius if zero and the aft radius is <code>radius >= 0</code>.
817                  * Boattails are achieved by reversing the component.
818                  * 
819                  * @param x      Position from the tip of the component.
820                  * @param radius Aft end radius >= 0.
821                  * @param length Length of the transition >= 0.
822                  * @param param  Valid shape parameter.
823                  * @return       The basic radius at the given position.
824                  */
825                 public abstract double getRadius(double x, double radius, double length, double param);
826
827                 
828                 /**
829                  * Returns the name of the shape (same as getName()).
830                  */
831                 @Override
832                 public String toString() {
833                         return name;
834                 }
835         }
836 }