Use FinSet.getBoundingBox() when computing bounds

Use the FinSet.getBoundingBox() when computing the bounds for the
current configuration in FlightConfiguration.calculateBounds().
The FinSet already contains a BoundingBox method, however it returns
a larger BoundingBox than necessary to encapsulate the component.

Change the FinSet.getBoundingBox() to create a bounding box of the
smallest size to ensure a tight bounds for the FinSet. This is done
by taking each of the locations for the component and determining
where the fin tip point is and updating the BoundingBox with this
location.

Signed-off-by: Billy Olsen <billy.olsen@gmail.com>
This commit is contained in:
Billy Olsen 2020-04-19 19:15:14 -07:00
parent 25475a92fb
commit 355bfb61c1
2 changed files with 29 additions and 8 deletions

View File

@ -714,11 +714,32 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab
final double finLength = singleFinBounds.max.x;
final double finHeight = singleFinBounds.max.y;
BoundingBox compBox = new BoundingBox().update(getComponentLocations());
Coordinate[] locations = getInstanceLocations();
double[] angles = getInstanceAngles();
BoundingBox finSetBox = new BoundingBox();
BoundingBox finSetBox = new BoundingBox( compBox.min.sub( 0, finHeight, finHeight ),
compBox.max.add( finLength, finHeight, finHeight ));
return finSetBox;
/*
* The fins themselves will be offset by the location itself to match
* the outside radius of a body tube. The bounds encapsulate the outer
* portion of all the tips of the fins.
*
* The height of each fin along the Y axis can be determined by:
* yHeight = cos(angle) * finHeight
*
* The height (depth?) of each fin along the Z axis can be determined by:
* zHeight = sin(angle) * finHeight
*
* The boundingBox should be that box which is the smallest box where
* a convex hull will contain all Coordinates.
*/
for (int i = 0; i < locations.length; i++) {
double y = Math.cos(angles[i]) * finHeight;
double z = Math.sin(angles[i]) * finHeight;
finSetBox.update(locations[i].add(0, y, z));
finSetBox.update(locations[i].add(finLength, y, z));
}
return finSetBox;
}
/**

View File

@ -565,11 +565,11 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
List<InstanceContext> contexts = entry.getValue();
Collection<Coordinate> coordinates = new ArrayList<Coordinate>();
/* FinSets are a bit different in how they store their bounds,
* so we'll use the fin points for calculations.
/* FinSets already provide a bounding box, so let's use that.
*/
if (component instanceof FinSet) {
coordinates.addAll(Arrays.asList(((FinSet) component).getFinPoints()));
bounds.update(((FinSet) component).getBoundingBox());
continue;
} else {
coordinates.addAll(component.getComponentBounds());
}
@ -614,7 +614,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
* inactive. Its possible that this shouldn't be allowed, but it is currently
* so we'll just adjust the length here.
*/
if (cachedLength == Double.POSITIVE_INFINITY || cachedLength == Double.NEGATIVE_INFINITY) {
if (getActiveStages().isEmpty()) {
cachedLength = 0;
}
cachedBounds.update( bounds );