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 ThicknessRingComponent extends RingComponent {
16 protected double outerRadius = 0;
17 protected double thickness = 0;
21 public double getOuterRadius() {
22 if (isOuterRadiusAutomatic() && getParent() instanceof RadialParent) {
23 RocketComponent parent = getParent();
24 double pos1 = this.toRelative(Coordinate.NUL, parent)[0].x;
25 double pos2 = this.toRelative(new Coordinate(getLength()), parent)[0].x;
26 pos1 = MathUtil.clamp(pos1, 0, parent.getLength());
27 pos2 = MathUtil.clamp(pos2, 0, parent.getLength());
28 outerRadius = Math.min(((RadialParent)parent).getInnerRadius(pos1),
29 ((RadialParent)parent).getInnerRadius(pos2));
37 public void setOuterRadius(double r) {
39 if (MathUtil.equals(outerRadius, r) && !isOuterRadiusAutomatic())
43 outerRadiusAutomatic = false;
45 if (thickness > outerRadius)
46 thickness = outerRadius;
48 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
54 public double getThickness() {
55 return Math.min(thickness, getOuterRadius());
58 public void setThickness(double thickness) {
59 double outer = getOuterRadius();
61 thickness = MathUtil.clamp(thickness, 0, outer);
62 if (MathUtil.equals(getThickness(), thickness))
65 this.thickness = thickness;
67 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
72 public double getInnerRadius() {
73 return Math.max(getOuterRadius()-thickness, 0);
76 public void setInnerRadius(double r) {
78 setThickness(getOuterRadius() - r);