1 package net.sf.openrocket.rocketcomponent;
3 import net.sf.openrocket.preset.ComponentPreset;
4 import net.sf.openrocket.util.Coordinate;
5 import net.sf.openrocket.util.MathUtil;
8 * An inner component that consists of a hollow cylindrical component. This can be
9 * an inner tube, tube coupler, centering ring, bulkhead etc.
11 * The properties include the inner and outer radii, length and radial position.
13 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
15 public abstract class RadiusRingComponent extends RingComponent implements Coaxial {
17 protected double outerRadius = 0;
18 protected double innerRadius = 0;
21 protected void loadFromPreset(ComponentPreset preset) {
22 super.loadFromPreset(preset);
23 if ( preset.has(ComponentPreset.OUTER_DIAMETER)) {
24 this.outerRadius = preset.get(ComponentPreset.OUTER_DIAMETER) / 2.0;
25 this.outerRadiusAutomatic = false;
27 this.innerRadiusAutomatic = false;
28 if ( preset.has(ComponentPreset.INNER_DIAMETER)) {
29 this.innerRadius = preset.get(ComponentPreset.INNER_DIAMETER) / 2.0;
32 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
37 public double getOuterRadius() {
38 if (outerRadiusAutomatic && getParent() instanceof RadialParent) {
39 RocketComponent parent = getParent();
40 double pos1 = this.toRelative(Coordinate.NUL, parent)[0].x;
41 double pos2 = this.toRelative(new Coordinate(getLength()), parent)[0].x;
42 pos1 = MathUtil.clamp(pos1, 0, parent.getLength());
43 pos2 = MathUtil.clamp(pos2, 0, parent.getLength());
44 outerRadius = Math.min(((RadialParent)parent).getInnerRadius(pos1),
45 ((RadialParent)parent).getInnerRadius(pos2));
52 public void setOuterRadius(double r) {
54 if (MathUtil.equals(outerRadius, r) && !isOuterRadiusAutomatic())
58 outerRadiusAutomatic = false;
59 if (getInnerRadius() > r) {
61 innerRadiusAutomatic = false;
65 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
70 public double getInnerRadius() {
74 public void setInnerRadius(double r) {
76 if (MathUtil.equals(innerRadius, r))
80 innerRadiusAutomatic = false;
81 if (getOuterRadius() < r) {
83 outerRadiusAutomatic = false;
87 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
92 public double getThickness() {
93 return Math.max(getOuterRadius() - getInnerRadius(), 0);
96 public void setThickness(double thickness) {
97 double outer = getOuterRadius();
99 thickness = MathUtil.clamp(thickness, 0, outer);
100 setInnerRadius(outer - thickness);