Merge pull request #655 from teyrana/show-cp-y

[fix] 2D Rocket Figure will now display off-axis CoM and CoP
This commit is contained in:
Daniel Williams 2020-05-08 11:02:59 -04:00 committed by GitHub
commit deed818fd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,6 +24,8 @@ import javax.swing.JPanel;
import javax.swing.JSlider; import javax.swing.JSlider;
import javax.swing.JViewport; import javax.swing.JViewport;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener; import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
@ -121,6 +123,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
private TreeSelectionModel selectionModel = null; private TreeSelectionModel selectionModel = null;
private BasicSlider rotationSlider; private BasicSlider rotationSlider;
private DoubleModel rotationModel;
private ScaleSelector scaleSelector; private ScaleSelector scaleSelector;
/* Calculation of CP and CG */ /* Calculation of CP and CG */
@ -323,9 +326,8 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
add(configComboBox, "wrap, width 16%, wmin 100"); add(configComboBox, "wrap, width 16%, wmin 100");
// Create slider and scroll pane // Create slider and scroll pane
DoubleModel theta = new DoubleModel(figure, "Rotation", rotationModel = new DoubleModel(figure, "Rotation", UnitGroup.UNITS_ANGLE, 0, 2 * Math.PI);
UnitGroup.UNITS_ANGLE, 0, 2 * Math.PI); UnitSelector us = new UnitSelector(rotationModel, true);
UnitSelector us = new UnitSelector(theta, true);
us.setHorizontalAlignment(JLabel.CENTER); us.setHorizontalAlignment(JLabel.CENTER);
add(us, "alignx 50%, growx"); add(us, "alignx 50%, growx");
@ -337,8 +339,14 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
JLabel l = new JLabel("360" + Chars.DEGREE); JLabel l = new JLabel("360" + Chars.DEGREE);
Dimension d = l.getPreferredSize(); Dimension d = l.getPreferredSize();
add(rotationSlider = new BasicSlider(theta.getSliderModel(0, 2 * Math.PI), JSlider.VERTICAL, true), add(rotationSlider = new BasicSlider(rotationModel.getSliderModel(0, 2 * Math.PI), JSlider.VERTICAL, true),
"ax 50%, wrap, width " + (d.width + 6) + "px:null:null, growy"); "ax 50%, wrap, width " + (d.width + 6) + "px:null:null, growy");
rotationSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
updateExtras();
}
});
//// <html>Click to select &nbsp;&nbsp; Shift+click to select other &nbsp;&nbsp; Double-click to edit &nbsp;&nbsp; Click+drag to move //// <html>Click to select &nbsp;&nbsp; Shift+click to select other &nbsp;&nbsp; Double-click to edit &nbsp;&nbsp; Click+drag to move
infoMessage = new JLabel(trans.get("RocketPanel.lbl.infoMessage")); infoMessage = new JLabel(trans.get("RocketPanel.lbl.infoMessage"));
@ -554,7 +562,11 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
private void updateExtras() { private void updateExtras() {
Coordinate cp, cg; Coordinate cp, cg;
double cpx, cgx; double cgx = Double.NaN;
double cgy = Double.NaN;
double cpx = Double.NaN;
double cpy = Double.NaN;
final double rotation = rotationModel.getValue();
FlightConfiguration curConfig = document.getSelectedConfiguration(); FlightConfiguration curConfig = document.getSelectedConfiguration();
// TODO: MEDIUM: User-definable conditions // TODO: MEDIUM: User-definable conditions
@ -594,14 +606,14 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
if (cp.weight > MathUtil.EPSILON){ if (cp.weight > MathUtil.EPSILON){
cpx = cp.x; cpx = cp.x;
}else{ // map the 3D value into the 2D Display Panel
cpx = Double.NaN; cpy = cp.y * Math.cos(rotation) + cp.z*Math.sin(rotation);
} }
if (cg.weight > MassCalculator.MIN_MASS){ if (cg.weight > MassCalculator.MIN_MASS){
cgx = cg.x; cgx = cg.x;
}else{ // map the 3D value into the 2D Display Panel
cgx = Double.NaN; cgy = cg.y * Math.cos(rotation) + cg.z*Math.sin(rotation);
} }
figure3d.setCG(cg); figure3d.setCG(cg);
@ -629,16 +641,11 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
extraText.setWarnings(warnings); extraText.setWarnings(warnings);
if (figure.getType() == RocketPanel.VIEW_TYPE.SideView && length > 0) { if (figure.getType() == RocketPanel.VIEW_TYPE.SideView && length > 0) {
extraCP.setPosition(cpx, cpy);
// TODO: LOW: Y-coordinate and rotation extraCG.setPosition(cgx, cgy);
extraCP.setPosition(cpx, 0);
extraCG.setPosition(cgx, 0);
} else { } else {
extraCP.setPosition(Double.NaN, Double.NaN); extraCP.setPosition(Double.NaN, Double.NaN);
extraCG.setPosition(Double.NaN, Double.NaN); extraCG.setPosition(Double.NaN, Double.NaN);
} }
//////// Flight simulation in background //////// Flight simulation in background