2bc112fbb11624924fcd699307157bde8764c3b1
[debian/openrocket] / src / net / sf / openrocket / rocketcomponent / BodyComponent.java
1 package net.sf.openrocket.rocketcomponent;
2
3
4 /**
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).
8  *
9  * It defines the methods getRadius(x,theta) and getInnerRadius(x,theta), as well
10  * as get/setLength().
11  *
12  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
13  */
14
15 public abstract class BodyComponent extends ExternalComponent {
16
17         /**
18          * Default constructor.  Sets the relative position to POSITION_RELATIVE_AFTER,
19          * i.e. body components come after one another.
20          */
21         public BodyComponent() {
22                 super(RocketComponent.Position.AFTER);
23         }
24
25
26         /**
27          * Get the outer radius of the component at cylindrical coordinate (x,theta).
28          *
29          * Note that the return value may be negative for a slanted object.
30          *
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
34          */
35         public abstract double getRadius(double x, double theta);
36
37
38         /**
39          * Get the inner radius of the component at cylindrical coordinate (x,theta).
40          *
41          * Note that the return value may be negative for a slanted object.
42          *
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
46          */
47         public abstract double getInnerRadius(double x, double theta);
48
49
50
51         /**
52          * Sets the length of the body component.
53          */
54         public void setLength(double length) {
55                 if (this.length == length)
56                         return;
57                 this.length = Math.max(length, 0);
58                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
59         }
60
61         @Override
62         public boolean allowsChildren() {
63                 return true;
64         }
65
66 }