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