diff --git a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java index 007f3a296..294a7c27a 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java @@ -311,16 +311,41 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial @Override public Collection getComponentBounds() { Collection bounds = new ArrayList(8); - // not exact, but should *usually* give the right bounds - Coordinate ref = this.getLocation()[0]; - double r = getOuterRadius(); - addBound(bounds, ref.x, r); - addBound(bounds, ref.x + length, r); + double x_min_shape = 0; + double x_max_shape = this.length; + double r_max_shape = getOuterRadius(); + + Coordinate[] locs = this.getLocation(); + // not strictly accurate, but this should provide an acceptable estimate for total vehicle size + double x_min_inst = Double.MAX_VALUE; + double x_max_inst = Double.MIN_VALUE; + double r_max_inst = 0.0; + + // refactor: get component inherent bounds + for (Coordinate cur : locs) { + double x_cur = cur.x; + double r_cur = MathUtil.hypot(cur.y, cur.z); + if (x_min_inst > x_cur) { + x_min_inst = x_cur; + } + if (x_max_inst < x_cur) { + x_max_inst = x_cur; + } + if (r_cur > r_max_inst) { + r_max_inst = r_cur; + } + } + + // combine the position bounds with the inherent shape bounds + double x_min = x_min_shape + x_min_inst; + double x_max = x_max_shape + x_max_inst; + double r_max = r_max_shape + r_max_inst; + + addBoundingBox(bounds, x_min, x_max, r_max); return bounds; } - /** * Check whether the given type can be added to this component. BodyTubes allow any * InternalComponents or ExternalComponents, excluding BodyComponents, to be added. diff --git a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java index 8de1142ca..50b111150 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FinSet.java @@ -615,23 +615,41 @@ public abstract class FinSet extends ExternalComponent { } + /** - * Adds the fin set's bounds to the collection. + * Adds bounding coordinates to the given set. The body tube will fit within the + * convex hull of the points. + * + * Currently the points are simply a rectangular box around the body tube. */ @Override public Collection getComponentBounds() { - List bounds = new ArrayList(); - double refx = this.getLocation()[0].x; - double r = getBodyRadius(); + Collection bounds = new ArrayList(8); + + // should simply return this component's bounds in this component's body frame. + + double x_min = Double.MAX_VALUE; + double x_max = Double.MIN_VALUE; + double r_max = 0.0; for (Coordinate point : getFinPoints()) { - addFinBound(bounds, refx + point.x, point.y + r); + double hypot = MathUtil.hypot(point.y, point.z); + double x_cur = point.x; + if (x_min > x_cur) { + x_min = x_cur; + } + if (x_max < x_cur) { + x_max = x_cur; + } + if (r_max < hypot) { + r_max = hypot; + } } + addBoundingBox(bounds, x_min, x_max, r_max); return bounds; } - /** * Adds the 2d-coordinate bound (x,y) to the collection for both z-components and for * all fin rotations. diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java index 0df623409..fd2e5c8c0 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java @@ -1831,6 +1831,13 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab + /** + * Helper method to add eight bounds in a box around the rocket centerline. This box will be (x_max - x_min) long, and 2*r wide/high. + */ + protected static final void addBoundingBox(Collection bounds, double x_min, double x_max, double r) { + addBound(bounds, x_min, r); + addBound(bounds, x_max, r); + } /** * Helper method to add four bounds rotated around the given x coordinate at radius 'r', and 90deg between each. diff --git a/swing/src/net/sf/openrocket/gui/rocketfigure/LaunchLugShapes.java b/swing/src/net/sf/openrocket/gui/rocketfigure/LaunchLugShapes.java index 0527f92d0..8beba4e86 100644 --- a/swing/src/net/sf/openrocket/gui/rocketfigure/LaunchLugShapes.java +++ b/swing/src/net/sf/openrocket/gui/rocketfigure/LaunchLugShapes.java @@ -13,13 +13,13 @@ public class LaunchLugShapes extends RocketComponentShape { public static RocketComponentShape[] getShapesSide( net.sf.openrocket.rocketcomponent.RocketComponent component, Transformation transformation, - Coordinate instanceOffset) { + Coordinate componentAbsoluteLocation) { net.sf.openrocket.rocketcomponent.LaunchLug lug = (net.sf.openrocket.rocketcomponent.LaunchLug)component; double length = lug.getLength(); double radius = lug.getOuterRadius(); - Coordinate[] start = transformation.transform(lug.toAbsolute(instanceOffset)); + Coordinate[] start = transformation.transform( lug.getLocation()); Shape[] s = new Shape[start.length]; for (int i=0; i < start.length; i++) {