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
18 public class Star extends ExtrudedShapeGrain implements Validating {
\r
19 private Amount<Length> oD = Amount.valueOf(30, SI.MILLIMETER);
\r
20 private Amount<Length> iD = Amount.valueOf(5, SI.MILLIMETER);
\r
21 private Amount<Length> pD = Amount.valueOf(15, SI.MILLIMETER);
\r
22 private int pointCount = 5;
\r
26 setLength(Amount.valueOf(70, SI.MILLIMETER));
\r
27 } catch (PropertyVetoException e) {
\r
28 e.printStackTrace();
\r
33 private void generateGeometry(){
\r
34 double odmm = oD.doubleValue(SI.MILLIMETER);
\r
35 double idmm = iD.doubleValue(SI.MILLIMETER)/2.0;
\r
36 double pdmm = pD.doubleValue(SI.MILLIMETER)/2.0;
\r
38 xsection = new BurningShape();
\r
39 Shape outside = new Ellipse2D.Double(-odmm/2, -odmm/2, odmm, odmm);
\r
40 xsection.add(outside);
\r
41 xsection.inhibit(outside);
\r
42 //xsection.subtract(new Ellipse2D.Double(-idmm/2, -idmm/2, idmm, idmm));
\r
43 webThickness = null;
\r
45 GeneralPath p = new GeneralPath();
\r
47 double dTheta = (2.0 * Math.PI) / ( pointCount * 2.0 );
\r
49 for ( int i = 0; i < pointCount; i++ ){
\r
51 p.lineTo(pdmm*Math.sin(theta), pdmm*Math.cos(theta));
\r
53 p.lineTo(idmm*Math.sin(theta), idmm*Math.cos(theta));
\r
56 xsection.subtract(new Area(p));
\r
59 public Amount<Length> getOD() {
\r
63 public void setOD(Amount<Length> od) throws PropertyVetoException {
\r
64 if (od.equals(this.oD))
\r
70 public Amount<Length> getID() {
\r
74 public void setID(Amount<Length> id) throws PropertyVetoException {
\r
75 if (id.equals(this.iD))
\r
81 public Amount<Length> getPointDiameter() {
\r
85 public void setPointDiameter(Amount<Length> pd) throws PropertyVetoException {
\r
86 if (pd.equals(this.pD))
\r
92 public int getPointCount(){
\r
96 public void setPointCount(final int points) throws PropertyVetoException{
\r
97 if ( points < 2 || points > 8 )
\r
98 throw new PropertyVetoException("Invalid number of points", null);
\r
99 pointCount = points;
\r
100 generateGeometry();
\r
104 public void validate() throws ValidationException{
\r
105 if ( iD.equals(Amount.ZERO) )
\r
106 throw new ValidationException(this, "Invalid iD");
\r
107 if ( oD.equals(Amount.ZERO) )
\r
108 throw new ValidationException(this, "Invalid oD");
\r
109 if ( getLength().equals(Amount.ZERO) )
\r
110 throw new ValidationException(this, "Invalid Length");
\r
111 if ( iD.isGreaterThan(oD) )
\r
112 throw new ValidationException(this, "iD > oD");
\r
113 if ( iD.isGreaterThan(pD) )
\r
114 throw new ValidationException(this, "iD > pD");
\r
115 if ( pD.isGreaterThan(oD) )
\r
116 throw new ValidationException(this, "pD > oD");
\r