[fixes #565] Fixes display of canted fins

This commit is contained in:
Daniel_M_Williams 2020-02-16 14:14:16 -05:00
parent d23d25ed15
commit 465989f837
2 changed files with 45 additions and 129 deletions

View File

@ -71,7 +71,7 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab
/**
* Rotation about the x-axis by 2*PI/fins.
*/
private Transformation finRotation = Transformation.IDENTITY;
private Transformation finRotationIncrement = Transformation.IDENTITY;
/**
@ -164,13 +164,13 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab
n = 8;
finCount = n;
finRotation = Transformation.rotate_x(2 * Math.PI / finCount);
finRotationIncrement = Transformation.rotate_x(2 * Math.PI / finCount);
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
}
public Transformation getFinRotationTransformation() {
return finRotation;
return finRotationIncrement;
}
@Override
@ -210,19 +210,16 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab
if (MathUtil.equals(clampedCant, this.cantRadians))
return;
this.cantRadians = clampedCant;
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
}
public Transformation getCantRotation() {
if (cantRotation == null) {
if( null == cantRotation ) {
if (MathUtil.equals(this.cantRadians, 0)) {
cantRotation = Transformation.IDENTITY;
} else {
Transformation t = new Transformation(-length / 2, 0, 0);
t = Transformation.rotate_y(cantRadians).applyTransformation(t);
t = new Transformation(length / 2, 0, 0).applyTransformation(t);
cantRotation = t;
cantRotation = Transformation.rotate_y(cantRadians);
}
}
return cantRotation;
@ -944,6 +941,13 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab
if (MathUtil.equals(reducedAngle, firstFinOffsetRadians))
return;
firstFinOffsetRadians = reducedAngle;
if (MathUtil.equals(this.firstFinOffsetRadians, 0)) {
baseRotation = Transformation.IDENTITY;
} else {
baseRotation = Transformation.rotate_x(firstFinOffsetRadians);
}
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
}
@ -1024,7 +1028,7 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab
protected List<RocketComponent> copyFrom(RocketComponent c) {
FinSet src = (FinSet) c;
this.finCount = src.finCount;
this.finRotation = src.finRotation;
this.finRotationIncrement = src.finRotationIncrement;
this.firstFinOffsetRadians = src.firstFinOffsetRadians;
this.cantRadians = src.cantRadians;
this.cantRotation = src.cantRotation;
@ -1230,22 +1234,22 @@ public abstract class FinSet extends ExternalComponent implements RingInstanceab
checkState();
final double bodyRadius = this.getBodyRadius();
// already includes the base rotation
final double[] angles = getInstanceAngles();
final Transformation localCantRotation = getCantRotation();
final Transformation localCantRotation = new Transformation(length / 2, 0, 0)
.applyTransformation(getCantRotation())
.applyTransformation(new Transformation(-length / 2, 0, 0));
Coordinate[] toReturn = new Coordinate[finCount];
for (int instanceNumber = 0; instanceNumber < finCount; instanceNumber++) {
final double curY = bodyRadius * Math.cos(angles[instanceNumber]);
final double curZ = bodyRadius * Math.sin(angles[instanceNumber]);
final Coordinate naiveLocation = new Coordinate(0, curY, curZ);
final Coordinate adjustedLocation = baseRotation.transform(localCantRotation.transform( naiveLocation));
toReturn[instanceNumber] = adjustedLocation;
final Coordinate raw = new Coordinate( 0, bodyRadius, 0);
final Coordinate canted = localCantRotation.transform(raw);
final Coordinate rotated = Transformation.rotate_x(angles[instanceNumber]).transform(canted);
toReturn[instanceNumber] = rotated;
}
return toReturn;
}
}

View File

@ -30,7 +30,7 @@ public class FinSetShapes extends RocketComponentShape {
*/
final Transformation cantRotation = finset.getCantRotation();
final Transformation compositeTransform = cantRotation.applyTransformation( transformation);
final Transformation compositeTransform = transformation.applyTransformation(cantRotation);
Coordinate finPoints[] = finset.getFinPoints();
Coordinate tabPoints[] = finset.getTabPoints();
@ -117,47 +117,37 @@ public class FinSetShapes extends RocketComponentShape {
return new Shape[]{p};
}
// TODO: LOW: Jagged shapes from back draw incorrectly.
private static Shape[] cantedShapesBack(FinSet finset,
Transformation transformation) {
int i;
int fins = finset.getFinCount();
double thickness = finset.getThickness();
Transformation cantRotation = finset.getCantRotation();
Coordinate[] sidePoints;
Coordinate[] backPoints;
int maxIndex;
Coordinate[] points = finset.getFinPoints();
// this loop finds the index @ max-y, as visible from the back
for (maxIndex = points.length-1; maxIndex > 0; maxIndex--) {
if (points[maxIndex-1].y < points[maxIndex].y)
break;
}
points = cantRotation.transform( points );
// transformPoints(points,new Transformation(0,radius,0));
points = transformation.transform( points );
Transformation cantTransform = finset.getCantRotation();
final Transformation compositeTransform = transformation.applyTransformation(cantTransform);
sidePoints = new Coordinate[points.length];
backPoints = new Coordinate[2*(points.length-maxIndex)];
double sign;
if (finset.getCantAngle() > 0) {
sign = 1.0;
} else {
sign = -1.0;
}
// Calculate points for the side panel
for (i=0; i < points.length; i++) {
double sign = Math.copySign(1.0, finset.getCantAngle());
// Calculate points for the visible side panel
for (int i=0; i < points.length; i++) {
sidePoints[i] = points[i].add(0,0,sign*thickness/2);
}
// Calculate points for the back portion
i=0;
int i=0;
for (int j=points.length-1; j >= maxIndex; j--, i++) {
backPoints[i] = points[j].add(0,0,sign*thickness/2);
}
@ -168,35 +158,24 @@ public class FinSetShapes extends RocketComponentShape {
// Generate shapes
Shape[] s;
if (thickness > 0.0005) {
s = new Shape[fins*2];
for (int fin=0; fin<fins; fin++) {
s[2*fin] = makePolygonBack(sidePoints,finset,transformation);
s[2*fin+1] = makePolygonBack(backPoints,finset,transformation);
}
s = new Shape[2];
s[0] = makePolygonBack(sidePoints,compositeTransform);
s[1] = makePolygonBack(backPoints,compositeTransform);
} else {
s = new Shape[fins];
for (int fin=0; fin<fins; fin++) {
s[fin] = makePolygonBack(sidePoints,finset,transformation);
}
s = new Shape[1];
s[0] = makePolygonBack(sidePoints,compositeTransform);
}
return s;
}
private static Shape makePolygonBack(Coordinate[] array, FinSet finset, final Transformation t) {
private static Shape makePolygonBack(Coordinate[] array, final Transformation t) {
Path2D.Float p;
Coordinate compCenter = t.transform(Coordinate.ZERO);
// Make polygon
p = new Path2D.Float();
for (int i=0; i < array.length; i++) {
Coordinate a = t.transform(compCenter.add( array[i]) );
Coordinate a = t.transform(array[i] );
if (i==0)
p.moveTo(a.z, a.y);
else
@ -205,72 +184,5 @@ public class FinSetShapes extends RocketComponentShape {
p.closePath();
return p;
}
/* Side painting with thickness:
Coordinate c[] = new Coordinate[8];
c[0]=new Coordinate(0-position*rootChord,radius,thickness/2);
c[1]=new Coordinate(rootChord-position*rootChord,radius,thickness/2);
c[2]=new Coordinate(sweep+tipChord-position*rootChord,height+radius,thickness/2);
c[3]=new Coordinate(sweep-position*rootChord,height+radius,thickness/2);
c[4]=new Coordinate(0-position*rootChord,radius,-thickness/2);
c[5]=new Coordinate(rootChord-position*rootChord,radius,-thickness/2);
c[6]=new Coordinate(sweep+tipChord-position*rootChord,height+radius,-thickness/2);
c[7]=new Coordinate(sweep-position*rootChord,height+radius,-thickness/2);
if (rotation != 0) {
rot = Transformation.rotate_x(rotation);
for (int i=0; i<8; i++)
c[i] = rot.transform(c[i]);
}
Shape[] s = new Shape[fins*6];
rot = Transformation.rotate_x(2*Math.PI/fins);
for (int fin=0; fin<fins; fin++) {
Coordinate a,b;
Path2D.Float p;
// First polygon
p = new Path2D.Float();
a = finset.toAbsolute(c[0]);
p.moveTo(a.x(), a.y());
a = finset.toAbsolute(c[1]);
p.lineTo(a.x(), a.y());
a = finset.toAbsolute(c[2]);
p.lineTo(a.x(), a.y());
a = finset.toAbsolute(c[3]);
p.lineTo(a.x(), a.y());
p.closePath();
s[fin*6] = p;
// Second polygon
p = new Path2D.Float();
a = finset.toAbsolute(c[4]);
p.moveTo(a.x(), a.y());
a = finset.toAbsolute(c[5]);
p.lineTo(a.x(), a.y());
a = finset.toAbsolute(c[6]);
p.lineTo(a.x(), a.y());
a = finset.toAbsolute(c[7]);
p.lineTo(a.x(), a.y());
p.closePath();
s[fin*6+1] = p;
// Single lines
for (int i=0; i<4; i++) {
a = finset.toAbsolute(c[i]);
b = finset.toAbsolute(c[i+4]);
s[fin*6+2+i] = new Line2D.Float((float)a.x(),(float)a.y(),(float)b.x(),(float)b.y());
}
// Rotate fin coordinates
for (int i=0; i<8; i++)
c[i] = rot.transform(c[i]);
}
*/
}