+++ /dev/null
-import java.awt.BasicStroke;\r
-import java.awt.Color;\r
-import java.awt.Graphics;\r
-import java.awt.Graphics2D;\r
-import java.awt.Shape;\r
-import java.awt.geom.AffineTransform;\r
-import java.awt.geom.Area;\r
-import java.awt.geom.FlatteningPathIterator;\r
-import java.awt.geom.GeneralPath;\r
-import java.awt.geom.PathIterator;\r
-\r
-import javax.swing.JFrame;\r
-import javax.swing.JPanel;\r
-\r
-\r
-public class QuadTest extends JPanel {\r
-\r
-\r
- public void paint(Graphics g){\r
- super.paint(g);\r
- Graphics2D g2d = (Graphics2D)g;\r
-\r
- g2d.scale(30, 30);\r
-\r
- Area a;\r
- GeneralPath p;\r
-\r
- g2d.setStroke(new BasicStroke(.02f));\r
- \r
- \r
- /*\r
- a = new Area(new Rectangle2D.Double(0,0,1,1));\r
- //a.transform(AffineTransform.getRotateInstance(Math.PI/4.0));\r
- g2d.setColor(Color.black);\r
- g2d.draw(a);\r
- g2d.setColor(Color.red);\r
- \r
- g2d.draw(square( a ));\r
- System.out.println(\r
- yRotatedVolume(a) + ", " +\r
- yRotatedSurfaceArea(a) + "\n"\r
- );\r
-\r
- \r
- a = new Area( new Ellipse2D.Double(2, 5, 4, 4));\r
- g2d.setColor(Color.black);\r
- g2d.draw(a);\r
- g2d.setColor(Color.red);\r
- \r
- g2d.draw(square( a ));\r
- System.out.println(\r
- yRotatedVolume(a) + ", " +\r
- yRotatedSurfaceArea(a) + "\n"\r
- );\r
- \r
- \r
- */\r
- p = new GeneralPath();\r
- p.moveTo(0,0);\r
- p.lineTo(1, 1);\r
- p.lineTo(0,1);\r
- p.closePath();\r
- a = new Area(p);\r
- g2d.translate(0, 8);\r
- g2d.setColor(Color.black);\r
- g2d.draw(a);\r
- g2d.setColor(Color.red);\r
- \r
- g2d.draw(square( a ));\r
- System.out.println(\r
- yRotatedVolume(a) + ", " +\r
- yRotatedSurfaceArea(a) + "\n"\r
- );\r
- \r
- p = new GeneralPath();\r
- p.moveTo(0,0);\r
- p.lineTo(2, 2);\r
- p.lineTo(0,2);\r
- p.closePath();\r
- a = new Area(p);\r
- g2d.translate(0, 2);\r
- g2d.setColor(Color.black);\r
- g2d.draw(a);\r
- g2d.setColor(Color.red);\r
- \r
- g2d.draw(square( a ));\r
- System.out.println(\r
- yRotatedVolume(a) + ", " +\r
- yRotatedSurfaceArea(a) + "\n"\r
- );\r
-\r
- p = new GeneralPath();\r
- p.moveTo(0,1);\r
- p.lineTo(1,1);\r
- p.lineTo(2, 2);\r
- p.lineTo(0,2);\r
- p.closePath();\r
- a = new Area(p);\r
- g2d.translate(0, 2);\r
- g2d.setColor(Color.black);\r
- g2d.draw(a);\r
- g2d.setColor(Color.red);\r
- \r
- g2d.draw(square( a ));\r
- System.out.println(\r
- yRotatedVolume(a) + ", " +\r
- yRotatedSurfaceArea(a) + "\n"\r
- );\r
- \r
-\r
- }\r
- \r
- \r
- private double yRotatedVolume(Area a){\r
- return Math.PI * area(new Area(square(a)));\r
- }\r
- \r
- private Shape square(java.awt.geom.Area a) {\r
- PathIterator i = a.getPathIterator(new AffineTransform(), 0.0001);\r
- GeneralPath cur = new GeneralPath();\r
-\r
- double last[] = {0,0};\r
- while (!i.isDone()) {\r
- double coords[] = new double[6];\r
- int type = i.currentSegment(coords);\r
- switch (type) {\r
- case PathIterator.SEG_CLOSE:\r
- cur.closePath();\r
- break;\r
- case PathIterator.SEG_MOVETO:\r
- cur.moveTo(Math.pow(coords[0],2), coords[1]);\r
- last[0] = coords[0];\r
- last[1] = coords[1];\r
- break;\r
- case PathIterator.SEG_CUBICTO:\r
- throw new Error("Non-flattened geometry!");\r
- case PathIterator.SEG_LINETO:\r
- double x = last[0];\r
- double y = last[1];\r
- double len = Math.sqrt(Math.pow(last[0]-coords[0], 2) + Math.pow(last[1]-coords[1], 2));\r
- int steps = (int)(len / .01) + 5;\r
- for (int s = 0; s < steps; s++) {\r
- x += (coords[0] - last[0]) / steps;\r
- y += (coords[1] - last[1]) / steps;\r
- cur.lineTo(Math.pow(x, 2), y);\r
- }\r
- last[0] = coords[0];\r
- last[1] = coords[1];\r
- break;\r
- case PathIterator.SEG_QUADTO:\r
- throw new Error("Non-flattened geometry!");\r
-\r
- }\r
- i.next();\r
- }\r
- return cur;\r
- }\r
- \r
- private double yRotatedSurfaceArea(java.awt.geom.Area a) {\r
- //TODO: I think I need to handle seg_close!!\r
- PathIterator i = a.getPathIterator(new AffineTransform(), .001);\r
- double x = 0, y = 0;\r
- double mx = 0, my = 0;\r
- double len = 0;\r
- while (!i.isDone()) {\r
- double coords[] = new double[6];\r
- int type = i.currentSegment(coords);\r
- if (type == PathIterator.SEG_LINETO || type == PathIterator.SEG_CLOSE) {\r
-\r
-\r
- double nx = coords[0];\r
- double ny = coords[1];\r
- \r
- if ( type == PathIterator.SEG_CLOSE ){\r
- nx = mx;\r
- ny = my;\r
- }\r
- \r
- double dy = Math.abs(y-ny);\r
- double dx = Math.abs(x-nx);\r
- double xl = x>nx?x:nx;\r
- double xs = x<nx?x:nx; \r
- \r
- double add = 0;\r
- if ( dx == 0 ){\r
- add = 2 * Math.PI * xl * dy;\r
- } else if ( dy == 0 ){\r
- add = Math.PI * xl * xl - Math.PI * xs * xs;\r
- }else{\r
- double h = xl/dx * dy;\r
- double s1 = Math.sqrt(xl*xl + h*h);\r
- double s2 = Math.sqrt(xs*xs + (h-dy)*(h-dy));\r
- add = Math.PI * (xl*s1 - xs*s2);\r
- }\r
- \r
- len += add;\r
-\r
- x = nx;\r
- y = ny;\r
- } else if (type == PathIterator.SEG_MOVETO) {\r
- mx = x = coords[0];\r
- my = y = coords[1];\r
- } else {\r
- throw new Error("Non-flattened geometry!");\r
- }\r
- i.next();\r
- }\r
- return len;\r
- }\r
- \r
-\r
- \r
- private double area(java.awt.geom.Area a) {\r
- if ( !a.isSingular() )\r
- throw new IllegalArgumentException("Can not calculate area of non-singular shape!");\r
- PathIterator i = a.getPathIterator(new AffineTransform(), .001);\r
- \r
- \r
- double x = 0, y = 0, sx = 0, sy = 0;\r
- double nx, ny;\r
- double area = 0;\r
- while (!i.isDone()) {\r
- double coords[] = new double[6];\r
- int type = i.currentSegment(coords);\r
- switch( type ){\r
- case PathIterator.SEG_CLOSE:\r
- //Go back to the start\r
- nx = sx;\r
- ny = sy;\r
- area += x * ny;\r
- area -= y * nx;\r
- break;\r
- case PathIterator.SEG_LINETO:\r
- nx = coords[0];\r
- ny = coords[1];\r
- area += x * ny;\r
- area -= y * nx;\r
-\r
- //Remember the last points\r
- x = nx;\r
- y = ny;\r
- \r
- break;\r
- case PathIterator.SEG_MOVETO:\r
- //Remember the starting point\r
- x = sx = coords[0];\r
- y = sy = coords[1];\r
- break;\r
- default:\r
- throw new Error("Bad segment type from Flattening Path Iterator");\r
- }\r
- i.next();\r
- }\r
- \r
- area = area / 2.0; // Result so far is double the signed area\r
- \r
- if ( area < 0 ) //Depending on winding it could be negative\r
- area = area * -1.0;\r
- \r
- \r
- return area;\r
- }\r
-\r
- \r
- public class FancyPathIterator extends FlatteningPathIterator{\r
-\r
- public FancyPathIterator(PathIterator path, double error) {\r
- super(path, error);\r
- }\r
- \r
- \r
- \r
- }\r
- \r
- public static void main(String args[]){\r
- JFrame f = new JFrame();\r
- f.setContentPane(new QuadTest());\r
- f.setDefaultCloseOperation(f.DISPOSE_ON_CLOSE);\r
- f.setSize(1500,800);\r
- f.setLocation(1600, 100);\r
- f.show();\r
- }\r
-}\r
+++ /dev/null
-import java.awt.BorderLayout;\r
-import java.awt.Color;\r
-import java.awt.Graphics;\r
-import java.awt.Graphics2D;\r
-import java.awt.Shape;\r
-import java.awt.geom.AffineTransform;\r
-import java.awt.geom.Area;\r
-import java.awt.geom.Ellipse2D;\r
-import java.awt.geom.GeneralPath;\r
-import java.awt.geom.PathIterator;\r
-\r
-import javax.swing.JFrame;\r
-import javax.swing.JPanel;\r
-import javax.swing.JSlider;\r
-import javax.swing.event.ChangeEvent;\r
-import javax.swing.event.ChangeListener;\r
-\r
-\r
-public class TriTest extends JPanel {\r
- \r
- private class RegressableShape {\r
- private Area a;\r
- public RegressableShape( Shape s ){\r
- if ( s instanceof Area )\r
- a = (Area)s;\r
- a = new Area(s);\r
- }\r
- \r
- public Area getRegressedShape(double regression){\r
- if ( regression == 0 )\r
- return a;\r
- \r
- //Build these separatly because intersecting the line\r
- //with the circle creates a small amount of error which\r
- //shows up when the resulting edge is no longer exactly\r
- //colinear with the original edge.\r
- Area rRect = new Area(); \r
- Area rCirc = new Area();\r
- \r
- PathIterator i = a.getPathIterator(new AffineTransform(), .001);\r
- double last[] = {0,0};\r
- double first[] = {0,0};\r
-\r
- while (!i.isDone()) {\r
- double coords[] = new double[6];\r
- int type = i.currentSegment(coords);\r
- switch (type){\r
- case PathIterator.SEG_MOVETO:\r
- first[0] = last[0] = coords[0];\r
- first[1] = last[1] = coords[1];\r
- break;\r
- case PathIterator.SEG_CLOSE:\r
- coords[0] = first[0];\r
- coords[1] = first[1];\r
- case PathIterator.SEG_LINETO:\r
- //Calculate the normal to this edge\r
- double dx = coords[0]-last[0];\r
- double dy = coords[1]-last[1];\r
- double len = Math.sqrt(dx*dx + dy*dy); \r
- double normal[] = {-dy/len,dx/len};\r
- \r
- //Calculate the displacement of the endpoints\r
- //to create a rect\r
- double displacement[] = {regression*normal[0], regression*normal[1]};\r
-\r
- //Create that rect. Winding does not seem to matter...\r
- GeneralPath p = new GeneralPath();\r
- p.moveTo(last[0], last[1]);\r
- p.lineTo(last[0]+displacement[0], last[1]+displacement[1]);\r
- p.lineTo(coords[0]+displacement[0], coords[1]+displacement[1]);\r
- p.lineTo(coords[0], coords[1]);\r
- p.closePath();\r
- rRect.add( new Area(p));\r
-\r
- double er = Math.abs(regression);\r
- rCirc.add(new Area(new Ellipse2D.Double(coords[0]-er, coords[1]-er, 2*er, 2*er)));\r
- \r
- last[0] = coords[0];\r
- last[1] = coords[1];\r
- break;\r
- case PathIterator.SEG_CUBICTO:\r
- case PathIterator.SEG_QUADTO:\r
- throw new Error("Unflattend Geometry!");\r
- }\r
- i.next();\r
- }\r
- \r
-\r
- if ( regression > 0 ){\r
- //Combine all together\r
- rRect.add(a);\r
- rRect.add(rCirc);\r
- }else{\r
- Area acp = (Area)a.clone();\r
- acp.subtract(rRect);\r
- acp.subtract(rCirc);\r
- rRect = acp;\r
- }\r
- return rRect;\r
- }\r
- }\r
- \r
- double r = 0;\r
- \r
- RegressableShape shape;\r
- {\r
- GeneralPath p = new GeneralPath();\r
- p.moveTo(100,100);\r
- p.lineTo(200, 200);\r
- p.lineTo(100, 300);\r
- p.closePath();\r
- shape = new RegressableShape(p);\r
- }\r
- \r
- @Override\r
- public void paint(Graphics gg){\r
- Graphics2D g = (Graphics2D)gg;\r
- \r
- g.clearRect(0, 0, 600, 600);\r
-\r
-\r
- g.setColor(Color.black);\r
- g.fill(shape.getRegressedShape(r));\r
- g.setColor(Color.yellow); \r
- g.draw(shape.getRegressedShape(0));\r
- g.setColor(Color.red);\r
- g.draw(shape.getRegressedShape(r));\r
-\r
- \r
- }\r
- \r
- \r
- public static void main( String args[] ){\r
- JFrame f = new JFrame();\r
- f.setDefaultCloseOperation(f.DISPOSE_ON_CLOSE);\r
- final TriTest t = new TriTest();\r
- f.getContentPane().setLayout(new BorderLayout());\r
- f.getContentPane().add(t, BorderLayout.CENTER);\r
- f.getContentPane().add(new JSlider(){{\r
- setMinimum(-100);\r
- setMaximum(100);\r
- addChangeListener(new ChangeListener(){\r
- { setValue(0); }\r
- public void stateChanged(ChangeEvent arg0) {\r
- t.r = getValue();\r
- t.repaint();\r
- }\r
- });\r
- }}, BorderLayout.SOUTH);\r
-\r
- f.setSize(400,400);\r
- f.setLocation(600,600);\r
- f.show();\r
- \r
- }\r
-}\r
//log.debug("Mass Gen Rate: " + mGenRate);\r
\r
//Calculate specific gas constant\r
- Amount specificGasConstant = Constants.R.divide(motor.getFuel().getCombustionProduct().getEffectiveMolarWeight());\r
+ Amount<?> specificGasConstant = Constants.R.divide(motor.getFuel().getCombustionProduct().getEffectiveMolarWeight());\r
//This unit conversion helps JScience to convert nozzle flow rate to\r
//kg/s a little later on I verified the conversion by hand and\r
//JScience checks it too.\r
Amount<Area> aStar = motor.getNozzle().throatArea();\r
double k = motor.getFuel().getCombustionProduct().getRatioOfSpecificHeats();\r
double kSide = Math.sqrt(k) * Math.pow((2/(k+1)) , (((k+1)/2)/(k-1)));\r
- Amount sqrtPart = specificGasConstant.times(chamberTemp).sqrt();\r
+ Amount<?> sqrtPart = specificGasConstant.times(chamberTemp).sqrt();\r
mNozzle = pDiff.times(aStar).times(kSide).divide(sqrtPart).to(MassFlowRate.UNIT);\r
//log.debug("Mass Exit Rate: " + mNozzle.to(MassFlowRate.UNIT)); \r
}\r
declare parents: Motor || Grain || Chamber || Nozzle || Fuel extends Checked;
+ @SuppressWarnings("unchecked")
void around(Checked c, Amount amt):
execution(void Checked+.set*(Amount)) && target(c) && args(amt) {
System.out.println(thisJoinPointStaticPart.getSignature().getName()
\r
MotorIO.writeMotor(m, f);\r
\r
- Motor r = MotorIO.readMotor(f);\r
+ MotorIO.readMotor(f);\r
\r
}\r
}\r
tp.setResizeWeight(.5);\r
\r
grain = new GrainPanel(burn.getMotor().getGrain()){\r
+ private static final long serialVersionUID = 1L;\r
@Override protected void addComponents(java.awt.Component crossSection, java.awt.Component slider, java.awt.Component label, java.awt.Component area, java.awt.Component volume) {\r
JSplitPane h = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, crossSection, area); \r
add(h, BorderLayout.CENTER);\r
import com.billkuker.rocketry.motorsim.motors.example.EndBurner;\r
\r
public class CrappyEditor extends JFrame {\r
+ private static final long serialVersionUID = 1L;\r
JTabbedPane tabs;\r
\r
public CrappyEditor() {\r
}\r
\r
private class Editor extends JPanel {\r
+ private static final long serialVersionUID = 1L;\r
RSyntaxTextArea text = new RSyntaxTextArea();\r
\r
Editor(Motor m) {\r
JPanel buttons = new JPanel(new FlowLayout());\r
\r
buttons.add(new JButton("Burn!") {\r
+ private static final long serialVersionUID = 1L;\r
{\r
addActionListener(new ActionListener() {\r
public void actionPerformed(ActionEvent arg0) {\r
});\r
\r
buttons.add(new JButton("End Burner Example") {\r
+ private static final long serialVersionUID = 1L;\r
{\r
addActionListener(new ActionListener() {\r
public void actionPerformed(ActionEvent arg0) {\r
});\r
\r
buttons.add(new JButton("C-Slot Example") {\r
+ private static final long serialVersionUID = 1L;\r
{\r
addActionListener(new ActionListener() {\r
public void actionPerformed(ActionEvent arg0) {\r
\r
\r
public static void main(String args[]) {\r
- new CrappyEditor().show();\r
+ new CrappyEditor().setVisible(true);\r
}\r
}\r
\r
public static class AmountPropertyEditor extends PropertyEditorSupport {\r
JTextField editor = new JTextField();\r
- Unit oldUnit;\r
+ Unit<?> oldUnit;\r
\r
@Override\r
public boolean supportsCustomEditor() {\r
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));\r
\r
p.add(new Chooser<Fuel>(fuelTypes) {\r
+ private static final long serialVersionUID = 1L;\r
@Override\r
protected void choiceMade(Fuel o) {\r
motor.setFuel(o);\r
setRightComponent(new NozzlePanel(n));\r
\r
parts.add(new JTextField(motor.getName()){\r
+ private static final long serialVersionUID = 1L;\r
{\r
final JTextField t = this;\r
addFocusListener(new FocusListener() {\r
}
+ @SuppressWarnings("unchecked")
public void removeMotor(Motor m){
Enumeration<TreeNode> e = getRoot().children();
while ( e.hasMoreElements() ){