1 package com.billkuker.rocketry.motorsim.grain;
\r
3 import java.awt.Shape;
\r
4 import java.awt.geom.Area;
\r
5 import java.awt.geom.Ellipse2D;
\r
6 import java.awt.geom.GeneralPath;
\r
7 import java.beans.PropertyVetoException;
\r
9 import javax.measure.quantity.Length;
\r
10 import javax.measure.unit.SI;
\r
12 import org.jscience.physics.amount.Amount;
\r
14 import com.billkuker.rocketry.motorsim.Validating;
\r
15 import com.billkuker.rocketry.motorsim.grain.util.BurningShape;
\r
16 import com.billkuker.rocketry.motorsim.grain.util.ExtrudedShapeGrain;
\r
17 import com.billkuker.rocketry.motorsim.visual.Editor;
\r
18 import com.billkuker.rocketry.motorsim.visual.GrainPanel;
\r
20 public class Star extends ExtrudedShapeGrain implements Validating {
\r
21 private Amount<Length> oD = Amount.valueOf(30, SI.MILLIMETER);
\r
22 private Amount<Length> iD = Amount.valueOf(5, SI.MILLIMETER);
\r
23 private Amount<Length> pD = Amount.valueOf(15, SI.MILLIMETER);
\r
24 private int pointCount = 5;
\r
28 setLength(Amount.valueOf(70, SI.MILLIMETER));
\r
29 } catch (PropertyVetoException e) {
\r
30 e.printStackTrace();
\r
35 private void generateGeometry(){
\r
36 double odmm = oD.doubleValue(SI.MILLIMETER);
\r
37 double idmm = iD.doubleValue(SI.MILLIMETER)/2.0;
\r
38 double pdmm = pD.doubleValue(SI.MILLIMETER)/2.0;
\r
40 xsection = new BurningShape();
\r
41 Shape outside = new Ellipse2D.Double(-odmm/2, -odmm/2, odmm, odmm);
\r
42 xsection.add(outside);
\r
43 xsection.inhibit(outside);
\r
44 //xsection.subtract(new Ellipse2D.Double(-idmm/2, -idmm/2, idmm, idmm));
\r
45 webThickness = null;
\r
47 GeneralPath p = new GeneralPath();
\r
49 double dTheta = (2.0 * Math.PI) / ( pointCount * 2.0 );
\r
51 for ( int i = 0; i < pointCount; i++ ){
\r
53 p.lineTo(pdmm*Math.sin(theta), pdmm*Math.cos(theta));
\r
55 p.lineTo(idmm*Math.sin(theta), idmm*Math.cos(theta));
\r
58 xsection.subtract(new Area(p));
\r
61 public Amount<Length> getOD() {
\r
65 public void setOD(Amount<Length> od) throws PropertyVetoException {
\r
66 if (od.equals(this.oD))
\r
72 public Amount<Length> getID() {
\r
76 public void setID(Amount<Length> id) throws PropertyVetoException {
\r
77 if (id.equals(this.iD))
\r
83 public Amount<Length> getPointDiameter() {
\r
87 public void setPointDiameter(Amount<Length> pd) throws PropertyVetoException {
\r
88 if (pd.equals(this.pD))
\r
94 public int getPointCount(){
\r
98 public void setPointCount(final int points) throws PropertyVetoException{
\r
99 if ( points < 2 || points > 8 )
\r
100 throw new PropertyVetoException("Invalid number of points", null);
\r
101 pointCount = points;
\r
102 generateGeometry();
\r
106 public static void main(String args[]) throws Exception {
\r
107 Star e = new Star();
\r
108 new Editor(e).showAsWindow();
\r
109 new GrainPanel(e).showAsWindow();
\r
113 public void validate() throws ValidationException{
\r
114 if ( iD.equals(Amount.ZERO) )
\r
115 throw new ValidationException(this, "Invalid iD");
\r
116 if ( oD.equals(Amount.ZERO) )
\r
117 throw new ValidationException(this, "Invalid oD");
\r
118 if ( getLength().equals(Amount.ZERO) )
\r
119 throw new ValidationException(this, "Invalid Length");
\r
120 if ( iD.isGreaterThan(oD) )
\r
121 throw new ValidationException(this, "iD > oD");
\r
122 if ( iD.isGreaterThan(pD) )
\r
123 throw new ValidationException(this, "iD > pD");
\r
124 if ( pD.isGreaterThan(oD) )
\r
125 throw new ValidationException(this, "pD > oD");
\r