1 package net.sf.openrocket.rocketcomponent;
3 import net.sf.openrocket.util.Coordinate;
4 import net.sf.openrocket.util.MathUtil;
7 * An inner component that consists of a hollow cylindrical component. This can be
8 * an inner tube, tube coupler, centering ring, bulkhead etc.
10 * The properties include the inner and outer radii, length and radial position.
12 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
14 public abstract class RadiusRingComponent extends RingComponent implements Coaxial {
16 protected double outerRadius = 0;
17 protected double innerRadius = 0;
20 public double getOuterRadius() {
21 if (outerRadiusAutomatic && getParent() instanceof RadialParent) {
22 RocketComponent parent = getParent();
23 double pos1 = this.toRelative(Coordinate.NUL, parent)[0].x;
24 double pos2 = this.toRelative(new Coordinate(getLength()), parent)[0].x;
25 pos1 = MathUtil.clamp(pos1, 0, parent.getLength());
26 pos2 = MathUtil.clamp(pos2, 0, parent.getLength());
27 outerRadius = Math.min(((RadialParent)parent).getInnerRadius(pos1),
28 ((RadialParent)parent).getInnerRadius(pos2));
35 public void setOuterRadius(double r) {
37 if (MathUtil.equals(outerRadius, r) && !isOuterRadiusAutomatic())
41 outerRadiusAutomatic = false;
42 if (getInnerRadius() > r) {
44 innerRadiusAutomatic = false;
47 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
52 public double getInnerRadius() {
56 public void setInnerRadius(double r) {
58 if (MathUtil.equals(innerRadius, r))
62 innerRadiusAutomatic = false;
63 if (getOuterRadius() < r) {
65 outerRadiusAutomatic = false;
68 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
73 public double getThickness() {
74 return Math.max(getOuterRadius() - getInnerRadius(), 0);
77 public void setThickness(double thickness) {
78 double outer = getOuterRadius();
80 thickness = MathUtil.clamp(thickness, 0, outer);
81 setInnerRadius(outer - thickness);