Updates for 0.9.5
[debian/openrocket] / src / net / sf / openrocket / aerodynamics / AerodynamicForces.java
1 package net.sf.openrocket.aerodynamics;
2
3 import net.sf.openrocket.rocketcomponent.RocketComponent;
4 import net.sf.openrocket.util.BugException;
5 import net.sf.openrocket.util.Coordinate;
6
7 public class AerodynamicForces implements Cloneable {
8         
9         /** 
10          * The component this data is referring to.  Used in analysis methods.
11          * A total value is indicated by the component being the Rocket component. 
12          */
13         public RocketComponent component = null;
14         
15
16         /** CG and mass */
17         public Coordinate cg = null;
18
19         /** Longitudal moment of inertia with reference to the CG. */
20         public double longitudalInertia = Double.NaN;
21         
22         /** Rotational moment of inertia with reference to the CG. */
23         public double rotationalInertia = Double.NaN;
24         
25         
26
27         /** CP and CNa. */
28         public Coordinate cp = null;
29         
30         
31         /**
32          * Normal force coefficient derivative.  At values close to zero angle of attack
33          * this value may be poorly defined or NaN if the calculation method does not
34          * compute CNa directly.
35          */
36         public double CNa = Double.NaN;
37
38         
39         /** Normal force coefficient. */
40         public double CN = Double.NaN;
41
42         /** Pitching moment coefficient, relative to the coordinate origin. */
43         public double Cm = Double.NaN;
44         
45         /** Side force coefficient, Cy */
46         public double Cside = Double.NaN;
47         
48         /** Yaw moment coefficient, Cn, relative to the coordinate origin. */
49         public double Cyaw = Double.NaN;
50         
51         /** Roll moment coefficient, Cl, relative to the coordinate origin. */
52         public double Croll = Double.NaN;
53         
54         /** Roll moment damping coefficient */
55         public double CrollDamp = Double.NaN;
56         
57         /** Roll moment forcing coefficient */
58         public double CrollForce = Double.NaN;
59         
60
61         
62         /** Axial drag coefficient, CA */
63         public double Caxial = Double.NaN;
64         
65         /** Total drag force coefficient, parallel to the airflow. */
66         public double CD = Double.NaN;
67         
68         /** Drag coefficient due to fore pressure drag. */
69         public double pressureCD = Double.NaN;
70         
71         /** Drag coefficient due to base drag. */
72         public double baseCD = Double.NaN;
73         
74         /** Drag coefficient due to friction drag. */
75         public double frictionCD = Double.NaN;
76         
77         
78         public double pitchDampingMoment = Double.NaN;
79         public double yawDampingMoment = Double.NaN;
80         
81         
82         /**
83          * Reset all values to null/NaN.
84          */
85         public void reset() {
86                 component = null;
87                 cg = null;
88                 longitudalInertia = Double.NaN;
89                 rotationalInertia = Double.NaN;
90
91                 cp = null;
92                 CNa = Double.NaN;
93                 CN = Double.NaN;
94                 Cm = Double.NaN;
95                 Cside = Double.NaN;
96                 Cyaw = Double.NaN;
97                 Croll = Double.NaN;
98                 CrollDamp = Double.NaN;
99                 CrollForce = Double.NaN;
100                 Caxial = Double.NaN;
101                 CD = Double.NaN;
102                 pitchDampingMoment = Double.NaN;
103                 yawDampingMoment = Double.NaN;
104         }
105         
106         /**
107          * Zero all values to 0 / Coordinate.NUL.  Component is left as it was.
108          */
109         public void zero() {
110                 // component untouched
111                 cg = Coordinate.NUL;
112                 longitudalInertia = 0;
113                 rotationalInertia = 0;
114
115                 cp = Coordinate.NUL;
116                 CNa = 0;
117                 CN = 0;
118                 Cm = 0;
119                 Cside = 0;
120                 Cyaw = 0;
121                 Croll = 0;
122                 CrollDamp = 0;
123                 CrollForce = 0;
124                 Caxial = 0;
125                 CD = 0;
126                 pitchDampingMoment = 0;
127                 yawDampingMoment = 0;
128         }
129
130         
131         @Override
132         public AerodynamicForces clone() {
133                 try {
134                         return (AerodynamicForces)super.clone();
135                 } catch (CloneNotSupportedException e) {
136                         throw new BugException("CloneNotSupportedException?!?");
137                 }
138         }
139         
140         @Override
141         public String toString() {
142                 String text="AerodynamicForces[";
143                 
144                 if (component != null)
145                         text += "component:" + component + ",";
146                 if (cg != null)
147                         text += "cg:" + cg + ",";
148                 if (cp != null)
149                         text += "cp:" + cp + ",";
150                 if (!Double.isNaN(longitudalInertia))
151                         text += "longIn:" + longitudalInertia + ",";
152                 if (!Double.isNaN(rotationalInertia))
153                         text += "rotIn:" + rotationalInertia + ",";
154                 
155                 if (!Double.isNaN(CNa))
156                         text += "CNa:" + CNa + ",";
157                 if (!Double.isNaN(CN))
158                         text += "CN:" + CN + ",";
159                 if (!Double.isNaN(Cm))
160                         text += "Cm:" + Cm + ",";
161                 
162                 if (!Double.isNaN(Cside))
163                         text += "Cside:" + Cside + ",";
164                 if (!Double.isNaN(Cyaw))
165                         text += "Cyaw:" + Cyaw + ",";
166                 
167                 if (!Double.isNaN(Croll))
168                         text += "Croll:" + Croll + ",";
169                 if (!Double.isNaN(Caxial))
170                         text += "Caxial:" + Caxial + ",";
171                 
172                 if (!Double.isNaN(CD))
173                         text += "CD:" + CD + ",";
174
175                 if (text.charAt(text.length()-1) == ',')
176                         text = text.substring(0, text.length()-1);
177                 
178                 text += "]";
179                 return text;
180         }
181 }