X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fnet%2Fsf%2Fopenrocket%2Frocketcomponent%2FRingComponent.java;h=9e2c16bc11a8dc8465decd2a70d26a9f11c3c484;hb=10c2e190c2e70564be6768a1acafa232dfff8e5c;hp=7c8523b0063688a27a820f77edc03664f8b95bf1;hpb=720d4935bc6bec453e6478ad5227356c626610a2;p=debian%2Fopenrocket diff --git a/src/net/sf/openrocket/rocketcomponent/RingComponent.java b/src/net/sf/openrocket/rocketcomponent/RingComponent.java index 7c8523b0..9e2c16bc 100644 --- a/src/net/sf/openrocket/rocketcomponent/RingComponent.java +++ b/src/net/sf/openrocket/rocketcomponent/RingComponent.java @@ -11,33 +11,40 @@ import net.sf.openrocket.util.MathUtil; /** * An inner component that consists of a hollow cylindrical component. This can be * an inner tube, tube coupler, centering ring, bulkhead etc. - * + * * The properties include the inner and outer radii, length and radial position. - * + * * @author Sampo Niskanen */ -public abstract class RingComponent extends StructuralComponent { - +public abstract class RingComponent extends StructuralComponent implements Coaxial { + protected boolean outerRadiusAutomatic = false; protected boolean innerRadiusAutomatic = false; - + private double radialDirection = 0; private double radialPosition = 0; private double shiftY = 0; private double shiftZ = 0; - + @Override public abstract double getOuterRadius(); + + @Override public abstract void setOuterRadius(double r); - public abstract double getInnerRadius(); + @Override + public abstract double getInnerRadius(); + + @Override public abstract void setInnerRadius(double r); + @Override public abstract double getThickness(); + public abstract void setThickness(double thickness); @@ -45,6 +52,7 @@ public abstract class RingComponent extends StructuralComponent { return outerRadiusAutomatic; } + // Setter is protected, subclasses may make it public protected void setOuterRadiusAutomatic(boolean auto) { if (auto == outerRadiusAutomatic) return; @@ -57,6 +65,7 @@ public abstract class RingComponent extends StructuralComponent { return innerRadiusAutomatic; } + // Setter is protected, subclasses may make it public protected void setInnerRadiusAutomatic(boolean auto) { if (auto == innerRadiusAutomatic) return; @@ -65,22 +74,22 @@ public abstract class RingComponent extends StructuralComponent { } - - + + public final void setLength(double length) { - double l = Math.max(length,0); + double l = Math.max(length, 0); if (this.length == l) return; this.length = l; fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); } - + /** * Return the radial direction of displacement of the component. Direction 0 * is equivalent to the Y-direction. - * + * * @return the radial direction. */ public double getRadialDirection() { @@ -90,7 +99,7 @@ public abstract class RingComponent extends StructuralComponent { /** * Set the radial direction of displacement of the component. Direction 0 * is equivalent to the Y-direction. - * + * * @param dir the radial direction. */ public void setRadialDirection(double dir) { @@ -102,14 +111,14 @@ public abstract class RingComponent extends StructuralComponent { shiftZ = radialPosition * Math.sin(radialDirection); fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); } - - + + /** * Return the radial position of the component. The position is the distance * of the center of the component from the center of the parent component. - * + * * @return the radial position. */ public double getRadialPosition() { @@ -119,7 +128,7 @@ public abstract class RingComponent extends StructuralComponent { /** * Set the radial position of the component. The position is the distance * of the center of the component from the center of the parent component. - * + * * @param pos the radial position. */ public void setRadialPosition(double pos) { @@ -131,15 +140,36 @@ public abstract class RingComponent extends StructuralComponent { shiftZ = radialPosition * Math.sin(radialDirection); fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); } - - - + + + public double getRadialShiftY() { + return shiftY; + } + + public double getRadialShiftZ() { + return shiftZ; + } + + public void setRadialShift(double y, double z) { + radialPosition = Math.hypot(y, z); + radialDirection = Math.atan2(z, y); + + // Re-calculate to ensure consistency + shiftY = radialPosition * Math.cos(radialDirection); + shiftZ = radialPosition * Math.sin(radialDirection); + assert (MathUtil.equals(y, shiftY)); + assert (MathUtil.equals(z, shiftZ)); + + fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); + } + + /** * Return the number of times the component is multiplied. */ public int getClusterCount() { if (this instanceof Clusterable) - return ((Clusterable)this).getClusterConfiguration().getClusterCount(); + return ((Clusterable) this).getClusterConfiguration().getClusterCount(); return 1; } @@ -149,7 +179,7 @@ public abstract class RingComponent extends StructuralComponent { */ @Override public Coordinate[] shiftCoordinates(Coordinate[] array) { - for (int i=0; i < array.length; i++) { + for (int i = 0; i < array.length; i++) { array[i] = array[i].add(0, shiftY, shiftZ); } return array; @@ -159,33 +189,33 @@ public abstract class RingComponent extends StructuralComponent { @Override public Collection getComponentBounds() { List bounds = new ArrayList(); - addBound(bounds,0,getOuterRadius()); - addBound(bounds,length,getOuterRadius()); + addBound(bounds, 0, getOuterRadius()); + addBound(bounds, length, getOuterRadius()); return bounds; } - + @Override public Coordinate getComponentCG() { - return new Coordinate(length/2, 0, 0, getComponentMass()); + return new Coordinate(length / 2, 0, 0, getComponentMass()); } - + @Override public double getComponentMass() { return ringMass(getOuterRadius(), getInnerRadius(), getLength(), getMaterial().getDensity()) * getClusterCount(); } - + @Override - public double getLongitudalUnitInertia() { - return ringLongitudalUnitInertia(getOuterRadius(), getInnerRadius(), getLength()); + public double getLongitudinalUnitInertia() { + return ringLongitudinalUnitInertia(getOuterRadius(), getInnerRadius(), getLength()); } - + @Override public double getRotationalUnitInertia() { return ringRotationalUnitInertia(getOuterRadius(), getInnerRadius()); } - + }