94f9986ba0a515fb18b1bd6bec2746cb51abd7d3
[debian/openrocket] / core / src / net / sf / openrocket / rocketcomponent / Streamer.java
1 package net.sf.openrocket.rocketcomponent;
2
3 import net.sf.openrocket.preset.ComponentPreset;
4 import net.sf.openrocket.preset.ComponentPreset.Type;
5 import net.sf.openrocket.util.MathUtil;
6
7 public class Streamer extends RecoveryDevice {
8         
9         public static final double DEFAULT_CD = 0.6;
10         
11         public static final double MAX_COMPUTED_CD = 0.4;
12         
13
14         private double stripLength;
15         private double stripWidth;
16         
17         
18         public Streamer() {
19                 this.stripLength = 0.5;
20                 this.stripWidth = 0.05;
21         }
22         
23         
24         public double getStripLength() {
25                 return stripLength;
26         }
27         
28         public void setStripLength(double stripLength) {
29                 if (MathUtil.equals(this.stripLength, stripLength))
30                         return;
31                 this.stripLength = stripLength;
32                 clearPreset();
33                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
34         }
35         
36         public double getStripWidth() {
37                 return stripWidth;
38         }
39         
40         public void setStripWidth(double stripWidth) {
41                 if (MathUtil.equals(this.stripWidth, stripWidth))
42                         return;
43                 this.stripWidth = stripWidth;
44                 this.length = stripWidth;
45                 clearPreset();
46                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
47         }
48         
49         @Override
50         public void setLength(double length) {
51                 setStripWidth(length);
52         }
53         
54         
55         public double getAspectRatio() {
56                 if (stripWidth > 0.0001)
57                         return stripLength / stripWidth;
58                 return 1000;
59         }
60         
61         public void setAspectRatio(double ratio) {
62                 if (MathUtil.equals(getAspectRatio(), ratio))
63                         return;
64                 
65                 ratio = Math.max(ratio, 0.01);
66                 double area = getArea();
67                 stripWidth = MathUtil.safeSqrt(area / ratio);
68                 stripLength = ratio * stripWidth;
69                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
70         }
71         
72         
73         @Override
74         public double getArea() {
75                 return stripWidth * stripLength;
76         }
77         
78         public void setArea(double area) {
79                 if (MathUtil.equals(getArea(), area))
80                         return;
81                 
82                 double ratio = Math.max(getAspectRatio(), 0.01);
83                 stripWidth = MathUtil.safeSqrt(area / ratio);
84                 stripLength = ratio * stripWidth;
85                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
86         }
87         
88         
89
90         @Override
91         public Type getPresetType() {
92                 return ComponentPreset.Type.STREAMER;
93         }
94
95
96         @Override
97         protected void loadFromPreset(ComponentPreset preset) {
98                 if ( preset.has(ComponentPreset.LENGTH)) {
99                         this.stripLength = preset.get(ComponentPreset.LENGTH);
100                 }
101                 if ( preset.has(ComponentPreset.WIDTH)) {
102                         this.stripWidth = preset.get(ComponentPreset.WIDTH);
103                 }
104                 super.loadFromPreset(preset);
105                 // Fix the length to the stripWidth since RocketComponent assigns ComponentPreset.LENGTH to length.
106                 this.length = this.stripWidth;
107                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
108         }
109
110
111         @Override
112         public double getComponentCD(double mach) {
113                 double density = this.getMaterial().getDensity();
114                 double cd;
115                 
116                 cd = 0.034 * ((density + 0.025) / 0.105) * (stripLength + 1) / stripLength;
117                 cd = MathUtil.min(cd, MAX_COMPUTED_CD);
118                 return cd;
119         }
120         
121         @Override
122         public String getComponentName() {
123                 return "Streamer";
124         }
125         
126         @Override
127         public boolean allowsChildren() {
128                 return false;
129         }
130         
131         @Override
132         public boolean isCompatible(Class<? extends RocketComponent> type) {
133                 return false;
134         }
135 }