1 package net.sf.openrocket.rocketcomponent;
6 * Class to represent a body object. The object can be described as a function of
7 * the cylindrical coordinates x and angle theta as r = f(x,theta). The component
8 * need not be symmetrical in any way (e.g. square tube, slanted cone etc).
10 * It defines the methods getRadius(x,theta) and getInnerRadius(x,theta), as well
13 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
16 public abstract class BodyComponent extends ExternalComponent {
19 * Default constructor. Sets the relative position to POSITION_RELATIVE_AFTER,
20 * i.e. body components come after one another.
22 public BodyComponent() {
23 super(RocketComponent.Position.AFTER);
28 * Get the outer radius of the component at cylindrical coordinate (x,theta).
30 * Note that the return value may be negative for a slanted object.
32 * @param x Distance in x direction
33 * @param theta Angle about the x-axis
34 * @return Distance to the outer edge of the object
36 public abstract double getRadius(double x, double theta);
40 * Get the inner radius of the component at cylindrical coordinate (x,theta).
42 * Note that the return value may be negative for a slanted object.
44 * @param x Distance in x direction
45 * @param theta Angle about the x-axis
46 * @return Distance to the inner edge of the object
48 public abstract double getInnerRadius(double x, double theta);
52 protected void loadFromPreset(RocketComponent preset) {
53 BodyComponent c = (BodyComponent) preset;
54 this.setLength(c.getLength());
56 super.loadFromPreset(preset);
62 * Sets the length of the body component.
64 * Note: This should be overridden by the subcomponents which need to call
65 * clearPreset(). (BodyTube allows changing length without resetting the preset.)
67 public void setLength(double length) {
68 if (this.length == length)
70 this.length = Math.max(length, 0);
71 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
75 public boolean allowsChildren() {