Merged l10n branch to trunk
[debian/openrocket] / src / net / sf / openrocket / rocketcomponent / TrapezoidFinSet.java
1 package net.sf.openrocket.rocketcomponent;
2
3 import net.sf.openrocket.l10n.Translator;
4 import net.sf.openrocket.startup.Application;
5 import net.sf.openrocket.util.Coordinate;
6
7 /**
8  * A set of trapezoidal fins.  The root and tip chords are perpendicular to the rocket
9  * base line, while the leading and aft edges may be slanted.
10  *
11  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
12  */
13
14 public class TrapezoidFinSet extends FinSet {
15         private static final Translator trans = Application.getTranslator();
16
17         public static final double MAX_SWEEP_ANGLE=(89*Math.PI/180.0);
18
19         /*
20          *           sweep   tipChord
21          *           |    |___________
22          *           |   /            |
23          *           |  /             |
24          *           | /              |  height
25          *            /               |
26          * __________/________________|_____________
27          *                length
28          *              == rootChord
29          */
30
31         // rootChord == length
32         private double tipChord = 0;
33         private double height = 0;
34         private double sweep = 0;
35
36
37         public TrapezoidFinSet() {
38                 this (3, 0.05, 0.05, 0.025, 0.05);
39         }
40
41         // TODO: HIGH:  height=0 -> CP = NaN
42         public TrapezoidFinSet(int fins, double rootChord, double tipChord, double sweep,
43                         double height) {
44                 super();
45
46                 this.setFinCount(fins);
47                 this.length = rootChord;
48                 this.tipChord = tipChord;
49                 this.sweep = sweep;
50                 this.height = height;
51         }
52
53
54         public void setFinShape(double rootChord, double tipChord, double sweep, double height,
55                         double thickness) {
56                 if (this.length==rootChord && this.tipChord==tipChord && this.sweep==sweep &&
57                                 this.height==height && this.thickness==thickness)
58                         return;
59                 this.length=rootChord;
60                 this.tipChord=tipChord;
61                 this.sweep=sweep;
62                 this.height=height;
63                 this.thickness=thickness;
64                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
65         }
66
67         public double getRootChord() {
68                 return length;
69         }
70         public void setRootChord(double r) {
71                 if (length == r)
72                         return;
73                 length = Math.max(r,0);
74                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
75         }
76
77         public double getTipChord() {
78                 return tipChord;
79         }
80         public void setTipChord(double r) {
81                 if (tipChord == r)
82                         return;
83                 tipChord = Math.max(r,0);
84                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
85         }
86
87         /**
88          * Get the sweep length.
89          */
90         public double getSweep() {
91                 return sweep;
92         }
93         /**
94          * Set the sweep length.
95          */
96         public void setSweep(double r) {
97                 if (sweep == r)
98                         return;
99                 sweep = r;
100                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
101         }
102
103         /**
104          * Get the sweep angle.  This is calculated from the true sweep and height, and is not
105          * stored separetely.
106          */
107         public double getSweepAngle() {
108                 if (height == 0) {
109                         if (sweep > 0)
110                                 return Math.PI/2;
111                         if (sweep < 0)
112                                 return -Math.PI/2;
113                         return 0;
114                 }
115                 return Math.atan(sweep/height);
116         }
117         /**
118          * Sets the sweep by the sweep angle.  The sweep is calculated and set by this method,
119          * and the angle itself is not stored.
120          */
121         public void setSweepAngle(double r) {
122                 if (r > MAX_SWEEP_ANGLE)
123                         r = MAX_SWEEP_ANGLE;
124                 if (r < -MAX_SWEEP_ANGLE)
125                         r = -MAX_SWEEP_ANGLE;
126                 double sweep = Math.tan(r) * height;
127                 if (Double.isNaN(sweep) || Double.isInfinite(sweep))
128                         return;
129                 setSweep(sweep);
130         }
131
132         public double getHeight() {
133                 return height;
134         }
135         public void setHeight(double r) {
136                 if (height == r)
137                         return;
138                 height = Math.max(r,0);
139                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
140         }
141
142
143
144         /**
145          * Returns the geometry of a trapezoidal fin.
146          */
147         @Override
148         public Coordinate[] getFinPoints() {
149                 Coordinate[] c = new Coordinate[4];
150
151                 c[0] = Coordinate.NUL;
152                 c[1] = new Coordinate(sweep,height);
153                 c[2] = new Coordinate(sweep+tipChord,height);
154                 c[3] = new Coordinate(length,0);
155
156                 return c;
157         }
158
159         /**
160          * Returns the span of a trapezoidal fin.
161          */
162         @Override
163         public double getSpan() {
164                 return height;
165         }
166
167
168         @Override
169         public String getComponentName() {
170                 //// Trapezoidal fin set
171                 return trans.get("TrapezoidFinSet.TrapezoidFinSet");
172         }
173
174 }