[fix] fixes rotation issues in TubeFinSet 2d rendering.

This commit is contained in:
Daniel_M_Williams 2020-07-25 10:35:59 -04:00 committed by Billy Olsen
parent 74ec0be340
commit ac7d606423
2 changed files with 11 additions and 51 deletions

View File

@ -68,7 +68,7 @@ public class TubeFinSet extends ExternalComponent implements RingInstanceable, A
} }
/** /**
* Return the outer radius of the body tube. * Return the outer radius of the tube-fin
* *
* @return the outside radius of the tube * @return the outside radius of the tube
*/ */
@ -104,7 +104,7 @@ public class TubeFinSet extends ExternalComponent implements RingInstanceable, A
} }
/** /**
* Set the outer radius of the body tube. If the radius is less than the wall thickness, * Set the outer radius of the tube-fin. If the radius is less than the wall thickness,
* the wall thickness is decreased accordingly of the value of the radius. * the wall thickness is decreased accordingly of the value of the radius.
* This method sets the automatic radius off. * This method sets the automatic radius off.
* *

View File

@ -25,19 +25,16 @@ public class TubeFinSetShapes extends RocketComponentShape {
* *
* @param component the TubeFinSet to get the shapes for * @param component the TubeFinSet to get the shapes for
* @param transformation the transformation to apply to the shapes * @param transformation the transformation to apply to the shapes
* @return an array of RocketComponentShapes that are used to draw the * @return an array of RocketComponentShapes that are used to draw the TubeFinSet from the side.
* TubeFinSet from the side.
*/ */
public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) { public static RocketComponentShape[] getShapesSide( final RocketComponent component, final Transformation transformation) {
final TubeFinSet finSet = (TubeFinSet) component;
TubeFinSet finSet = (TubeFinSet) component;
final double outerRadius = finSet.getOuterRadius(); final double outerRadius = finSet.getOuterRadius();
final double length = finSet.getLength(); final double length = finSet.getLength();
Coordinate[] locations = transformLocations(finSet, transformation); final Coordinate location = transformation.transform(new Coordinate(0, outerRadius, 0));
Shape[] shapes = new Shape[] { final Shape[] shapes = new Shape[] {
new Rectangle2D.Double(locations[0].x, (locations[0].y-outerRadius), length, 2*outerRadius) new Rectangle2D.Double(location.x, (location.y-outerRadius), length, 2*outerRadius)
}; };
return RocketComponentShape.toArray(shapes, component); return RocketComponentShape.toArray(shapes, component);
@ -54,51 +51,14 @@ public class TubeFinSetShapes extends RocketComponentShape {
* TubeFinSet from the back * TubeFinSet from the back
*/ */
public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) { public static RocketComponentShape[] getShapesBack( final RocketComponent component, final Transformation transformation) {
final TubeFinSet finSet = (TubeFinSet) component;
TubeFinSet finSet = (TubeFinSet) component;
final double outerRadius = finSet.getOuterRadius(); final double outerRadius = finSet.getOuterRadius();
Coordinate[] locations = transformLocations(finSet, transformation); final Coordinate location = transformation.transform(new Coordinate(0, outerRadius, 0));
Shape[] shapes = new Shape[] { final Shape[] shapes = new Shape[] {
new Ellipse2D.Double((locations[0].z - outerRadius), (locations[0].y - outerRadius), (2 * outerRadius), (2 * outerRadius)) new Ellipse2D.Double((location.z - outerRadius), (location.y - outerRadius), (2 * outerRadius), (2 * outerRadius))
}; };
return RocketComponentShape.toArray(shapes, component); return RocketComponentShape.toArray(shapes, component);
} }
/**
* Translates and rotates the coordinates as follows:
*
* 1. Ensure the coordinate accounts for the body and outer radius. This
* adjusts the Y value of the coordinate to place it in the correct
* position relative to the body tube.
*
* 2. Perform a linear transformation of the coordinate using the supplied
* transform. Using the linear transform ensures the coordinate is
* rotated per the view, but avoids applying an offset translation
* since that is already applied in the locations retrieved from the
* TubeFinSet.
*
* 3. Apply the base rotational transform described by the TubeFinSet
* component itself.
*
* @param finSet the TubeFinSet to apply the transformation to
* @param transformation the Transformation to apply to the TubeFinSet
*/
private static Coordinate[] transformLocations(final TubeFinSet finSet, final Transformation transformation) {
final double outerRadius = finSet.getOuterRadius();
final double bodyRadius = finSet.getBodyRadius();
Coordinate[] locations = finSet.getInstanceLocations();
for (int i=0; i < locations.length; i++) {
Coordinate c = locations[i].setX(0.);
c = c.sub(0, (bodyRadius - outerRadius), 0);
c = transformation.transform(c);
locations[i] = c;
}
return locations;
}
} }