1 package net.sf.openrocket.rocketcomponent;
3 import net.sf.openrocket.preset.ComponentPreset;
4 import net.sf.openrocket.preset.ComponentPreset.Type;
5 import net.sf.openrocket.util.MathUtil;
7 public class Streamer extends RecoveryDevice {
9 public static final double DEFAULT_CD = 0.6;
11 public static final double MAX_COMPUTED_CD = 0.4;
14 private double stripLength;
15 private double stripWidth;
19 this.stripLength = 0.5;
20 this.stripWidth = 0.05;
24 public double getStripLength() {
28 public void setStripLength(double stripLength) {
29 if (MathUtil.equals(this.stripLength, stripLength))
31 this.stripLength = stripLength;
33 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
36 public double getStripWidth() {
40 public void setStripWidth(double stripWidth) {
41 if (MathUtil.equals(this.stripWidth, stripWidth))
43 this.stripWidth = stripWidth;
44 this.length = stripWidth;
46 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
50 public void setLength(double length) {
51 setStripWidth(length);
55 public double getAspectRatio() {
56 if (stripWidth > 0.0001)
57 return stripLength / stripWidth;
61 public void setAspectRatio(double ratio) {
62 if (MathUtil.equals(getAspectRatio(), ratio))
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);
74 public double getArea() {
75 return stripWidth * stripLength;
78 public void setArea(double area) {
79 if (MathUtil.equals(getArea(), area))
82 double ratio = Math.max(getAspectRatio(), 0.01);
83 stripWidth = MathUtil.safeSqrt(area / ratio);
84 stripLength = ratio * stripWidth;
85 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
91 public Type getPresetType() {
92 return ComponentPreset.Type.STREAMER;
97 protected void loadFromPreset(ComponentPreset preset) {
98 if ( preset.has(ComponentPreset.LENGTH)) {
99 this.stripLength = preset.get(ComponentPreset.LENGTH);
101 if ( preset.has(ComponentPreset.WIDTH)) {
102 this.stripWidth = preset.get(ComponentPreset.WIDTH);
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);
112 public double getComponentCD(double mach) {
113 double density = this.getMaterial().getDensity();
116 cd = 0.034 * ((density + 0.025) / 0.105) * (stripLength + 1) / stripLength;
117 cd = MathUtil.min(cd, MAX_COMPUTED_CD);
122 public String getComponentName() {
127 public boolean allowsChildren() {
132 public boolean isCompatible(Class<? extends RocketComponent> type) {