1 package net.sf.openrocket.rocketcomponent;
5 * Class to represent a body object. The object can be described as a function of
6 * the cylindrical coordinates x and angle theta as r = f(x,theta). The component
7 * need not be symmetrical in any way (e.g. square tube, slanted cone etc).
9 * It defines the methods getRadius(x,theta) and getInnerRadius(x,theta), as well
12 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
15 public abstract class BodyComponent extends ExternalComponent {
18 * Default constructor. Sets the relative position to POSITION_RELATIVE_AFTER,
19 * i.e. body components come after one another.
21 public BodyComponent() {
22 super(RocketComponent.Position.AFTER);
27 * Get the outer radius of the component at cylindrical coordinate (x,theta).
29 * Note that the return value may be negative for a slanted object.
31 * @param x Distance in x direction
32 * @param theta Angle about the x-axis
33 * @return Distance to the outer edge of the object
35 public abstract double getRadius(double x, double theta);
39 * Get the inner radius of the component at cylindrical coordinate (x,theta).
41 * Note that the return value may be negative for a slanted object.
43 * @param x Distance in x direction
44 * @param theta Angle about the x-axis
45 * @return Distance to the inner edge of the object
47 public abstract double getInnerRadius(double x, double theta);
52 * Sets the length of the body component.
54 public void setLength(double length) {
55 if (this.length == length)
57 this.length = Math.max(length,0);
58 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
63 * Check whether the given type can be added to this component. BodyComponents allow any
64 * InternalComponents or ExternalComponents, excluding BodyComponents, to be added.
66 * @param type The RocketComponent class type to add.
67 * @return Whether such a component can be added.
70 public boolean isCompatible(Class<? extends RocketComponent> type) {
71 if (InternalComponent.class.isAssignableFrom(type))
73 if (ExternalComponent.class.isAssignableFrom(type) &&
74 !BodyComponent.class.isAssignableFrom(type))
80 * Accept a visitor to this BodyComponent in the component hierarchy.
82 * @param theVisitor the visitor that will be called back with a reference to this BodyComponent
85 public void accept (final ComponentVisitor theVisitor) {
86 theVisitor.visit(this);