From: Bill Kuker Date: Wed, 15 Apr 2009 18:51:22 +0000 (+0000) Subject: Cleaned up warnings X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=f2e17480e720215f1573e4a4315277251b0074d8;p=sw%2Fmotorsim Cleaned up warnings Removed burn main() junk, test specific motors --- diff --git a/src/QuadTest.java b/src/QuadTest.java new file mode 100644 index 0000000..76a000c --- /dev/null +++ b/src/QuadTest.java @@ -0,0 +1,283 @@ +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.Area; +import java.awt.geom.FlatteningPathIterator; +import java.awt.geom.GeneralPath; +import java.awt.geom.PathIterator; + +import javax.swing.JFrame; +import javax.swing.JPanel; + + +public class QuadTest extends JPanel { + + + public void paint(Graphics g){ + super.paint(g); + Graphics2D g2d = (Graphics2D)g; + + g2d.scale(30, 30); + + Area a; + GeneralPath p; + + g2d.setStroke(new BasicStroke(.02f)); + + + /* + a = new Area(new Rectangle2D.Double(0,0,1,1)); + //a.transform(AffineTransform.getRotateInstance(Math.PI/4.0)); + g2d.setColor(Color.black); + g2d.draw(a); + g2d.setColor(Color.red); + + g2d.draw(square( a )); + System.out.println( + yRotatedVolume(a) + ", " + + yRotatedSurfaceArea(a) + "\n" + ); + + + a = new Area( new Ellipse2D.Double(2, 5, 4, 4)); + g2d.setColor(Color.black); + g2d.draw(a); + g2d.setColor(Color.red); + + g2d.draw(square( a )); + System.out.println( + yRotatedVolume(a) + ", " + + yRotatedSurfaceArea(a) + "\n" + ); + + + */ + p = new GeneralPath(); + p.moveTo(0,0); + p.lineTo(1, 1); + p.lineTo(0,1); + p.closePath(); + a = new Area(p); + g2d.translate(0, 8); + g2d.setColor(Color.black); + g2d.draw(a); + g2d.setColor(Color.red); + + g2d.draw(square( a )); + System.out.println( + yRotatedVolume(a) + ", " + + yRotatedSurfaceArea(a) + "\n" + ); + + p = new GeneralPath(); + p.moveTo(0,0); + p.lineTo(2, 2); + p.lineTo(0,2); + p.closePath(); + a = new Area(p); + g2d.translate(0, 2); + g2d.setColor(Color.black); + g2d.draw(a); + g2d.setColor(Color.red); + + g2d.draw(square( a )); + System.out.println( + yRotatedVolume(a) + ", " + + yRotatedSurfaceArea(a) + "\n" + ); + + p = new GeneralPath(); + p.moveTo(0,1); + p.lineTo(1,1); + p.lineTo(2, 2); + p.lineTo(0,2); + p.closePath(); + a = new Area(p); + g2d.translate(0, 2); + g2d.setColor(Color.black); + g2d.draw(a); + g2d.setColor(Color.red); + + g2d.draw(square( a )); + System.out.println( + yRotatedVolume(a) + ", " + + yRotatedSurfaceArea(a) + "\n" + ); + + + } + + + private double yRotatedVolume(Area a){ + return Math.PI * area(new Area(square(a))); + } + + private Shape square(java.awt.geom.Area a) { + PathIterator i = a.getPathIterator(new AffineTransform(), 0.0001); + GeneralPath cur = new GeneralPath(); + + double last[] = {0,0}; + while (!i.isDone()) { + double coords[] = new double[6]; + int type = i.currentSegment(coords); + switch (type) { + case PathIterator.SEG_CLOSE: + cur.closePath(); + break; + case PathIterator.SEG_MOVETO: + cur.moveTo(Math.pow(coords[0],2), coords[1]); + last[0] = coords[0]; + last[1] = coords[1]; + break; + case PathIterator.SEG_CUBICTO: + throw new Error("Non-flattened geometry!"); + case PathIterator.SEG_LINETO: + double x = last[0]; + double y = last[1]; + double len = Math.sqrt(Math.pow(last[0]-coords[0], 2) + Math.pow(last[1]-coords[1], 2)); + int steps = (int)(len / .01) + 5; + for (int s = 0; s < steps; s++) { + x += (coords[0] - last[0]) / steps; + y += (coords[1] - last[1]) / steps; + cur.lineTo(Math.pow(x, 2), y); + } + last[0] = coords[0]; + last[1] = coords[1]; + break; + case PathIterator.SEG_QUADTO: + throw new Error("Non-flattened geometry!"); + + } + i.next(); + } + return cur; + } + + private double yRotatedSurfaceArea(java.awt.geom.Area a) { + //TODO: I think I need to handle seg_close!! + PathIterator i = a.getPathIterator(new AffineTransform(), .001); + double x = 0, y = 0; + double mx = 0, my = 0; + double len = 0; + while (!i.isDone()) { + double coords[] = new double[6]; + int type = i.currentSegment(coords); + if (type == PathIterator.SEG_LINETO || type == PathIterator.SEG_CLOSE) { + + + double nx = coords[0]; + double ny = coords[1]; + + if ( type == PathIterator.SEG_CLOSE ){ + nx = mx; + ny = my; + } + + double dy = Math.abs(y-ny); + double dx = Math.abs(x-nx); + double xl = x>nx?x:nx; + double xs = x pressure(Amount time){ return data.get(time).chamberPressure; } @@ -216,74 +219,4 @@ public class Burn { return motor.getGrain().surfaceArea(regression).divide(motor.getNozzle().throatArea()).to(Dimensionless.UNIT); } - public static void main( String args[]) throws Exception{ - Motor m = new Motor(); - m.setFuel(new KNSB()); - - CylindricalChamber c = new CylindricalChamber(); - c.setLength(Amount.valueOf(300, SI.MILLIMETER)); - c.setID(Amount.valueOf(30, SI.MILLIMETER)); - m.setChamber(c); - - CoredCylindricalGrain g = new CoredCylindricalGrain(); - g.setLength(Amount.valueOf(35, SI.MILLIMETER)); - g.setOD(Amount.valueOf(30, SI.MILLIMETER)); - g.setID(Amount.valueOf(10, SI.MILLIMETER)); - m.setGrain(g); - - CoredCylindricalGrain g1 = new CoredCylindricalGrain(); - g1.setLength(Amount.valueOf(70, SI.MILLIMETER)); - g1.setOD(Amount.valueOf(30, SI.MILLIMETER)); - g1.setID(Amount.valueOf(18, SI.MILLIMETER)); - g1.inhibit(false, true, true); - - CoredCylindricalGrain g2 = new CoredCylindricalGrain(); - g2.setLength(Amount.valueOf(70, SI.MILLIMETER)); - g2.setOD(Amount.valueOf(12, SI.MILLIMETER)); - g2.setID(Amount.valueOf(0, SI.MILLIMETER)); - g2.inhibit(true, false, true); - - CompoundGrain cg = new CompoundGrain(); - cg.add(g1); - cg.add(g2); - - //m.setGrain( new MultiGrain(cg, 2) ); - - //g.setAftEndInhibited(true); - //g.setForeEndInhibited(true); - m.setGrain(new MultiGrain(g,3)); - - //m.setGrain(new ExtrudedGrain()); - - ConvergentDivergentNozzle n = new ConvergentDivergentNozzle(); - n.setThroatDiameter(Amount.valueOf(5.500, SI.MILLIMETER)); - n.setExitDiameter(Amount.valueOf(20.87, SI.MILLIMETER)); - n.setEfficiency(.87); - m.setNozzle(n); - - Burn b = new Burn(m); - - b.burn(); - - new BurnPanel(b).show(); - /* - Chart r = new Chart( - SI.SECOND, - SI.MEGA(SI.PASCAL), - b, - "pressure"); - r.setDomain(b.data.keySet()); - r.show(); - - Chart t = new Chart( - SI.SECOND, - SI.NEWTON, - b, - "thrust"); - t.setDomain(b.data.keySet()); - t.show(); - - new GrainPanel( m.getGrain() ).show();*/ - - } } diff --git a/src/com/billkuker/rocketry/motorsim/motors/kuker/PVC9.java b/src/com/billkuker/rocketry/motorsim/motors/kuker/PVC9.java index 8b29075..ddac0b9 100644 --- a/src/com/billkuker/rocketry/motorsim/motors/kuker/PVC9.java +++ b/src/com/billkuker/rocketry/motorsim/motors/kuker/PVC9.java @@ -1,6 +1,5 @@ package com.billkuker.rocketry.motorsim.motors.kuker; -import javax.measure.unit.NonSI; import javax.measure.unit.SI; import org.jscience.physics.amount.Amount; diff --git a/src/com/billkuker/rocketry/motorsim/motors/nakka/KappaSB.java b/src/com/billkuker/rocketry/motorsim/motors/nakka/KappaSB.java index e8b2c13..eaaf5fa 100644 --- a/src/com/billkuker/rocketry/motorsim/motors/nakka/KappaSB.java +++ b/src/com/billkuker/rocketry/motorsim/motors/nakka/KappaSB.java @@ -1,7 +1,6 @@ package com.billkuker.rocketry.motorsim.motors.nakka; import javax.measure.unit.NonSI; -import javax.measure.unit.SI; import org.jscience.physics.amount.Amount; diff --git a/src/com/billkuker/rocketry/motorsim/test/CoredCylindricalGrainTest.java b/src/com/billkuker/rocketry/motorsim/test/CoredCylindricalGrainTest.java index ca7d804..30324a0 100644 --- a/src/com/billkuker/rocketry/motorsim/test/CoredCylindricalGrainTest.java +++ b/src/com/billkuker/rocketry/motorsim/test/CoredCylindricalGrainTest.java @@ -3,7 +3,6 @@ package com.billkuker.rocketry.motorsim.test; import java.beans.PropertyVetoException; import javax.measure.quantity.Area; -import javax.measure.quantity.Length; import javax.measure.quantity.Volume; import javax.measure.unit.SI; diff --git a/src/com/billkuker/rocketry/motorsim/test/RocketTest.java b/src/com/billkuker/rocketry/motorsim/test/RocketTest.java index 5c06288..149c47e 100644 --- a/src/com/billkuker/rocketry/motorsim/test/RocketTest.java +++ b/src/com/billkuker/rocketry/motorsim/test/RocketTest.java @@ -13,10 +13,12 @@ public class RocketTest { protected static final Unit cubeMM = SI.MILLIMETER.pow(3).asType(javax.measure.quantity.Volume.class); + @SuppressWarnings("unchecked") protected void assertApproximate(Amount a, Amount b){ Assert.assertTrue("" + a.to(b.getUnit()) + " !~ " + b , a.approximates(b)); } + @SuppressWarnings("unchecked") protected void assertApproximate(Amount a, Amount b, Amount diff){ Assert.assertTrue("" + a.to(b.getUnit()) + " !~~ " + b , a.minus(b).abs().isLessThan(diff)); } diff --git a/src/com/billkuker/rocketry/motorsim/test/ShapeUtilTest.java b/src/com/billkuker/rocketry/motorsim/test/ShapeUtilTest.java index d8a2be4..8a413b0 100644 --- a/src/com/billkuker/rocketry/motorsim/test/ShapeUtilTest.java +++ b/src/com/billkuker/rocketry/motorsim/test/ShapeUtilTest.java @@ -4,9 +4,6 @@ import java.awt.geom.Area; import java.awt.geom.Ellipse2D; import java.awt.geom.Rectangle2D; -import javax.measure.unit.SI; -import javax.measure.unit.Unit; - import org.jscience.physics.amount.Amount; import org.junit.Test;