1 package net.sf.openrocket.gui.dialogs.motor.thrustcurve;
3 import net.sf.openrocket.unit.UnitGroup;
4 import net.sf.openrocket.util.BugException;
7 * NAR approved motor classes (http://www.nar.org/NARmotors.html).
9 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
11 public enum MotorClass {
13 A18("1/8A", 0, 0.3125),
14 A14("1/4A", 0.3125, 0.625),
15 A12("1/2A", 0.625, 1.25),
31 OVER("> O", 40960, Double.MAX_VALUE) {
33 public String getDescription(double impulse) {
38 public String getClassDescription() {
39 return "Over O-class (over " + UnitGroup.UNITS_IMPULSE.toStringUnit(40960) + ")";
44 private final String className;
45 private final double min;
46 private final double max;
49 private MotorClass(String className, double min, double max) {
50 this.className = className;
56 public String getDescription(double impulse) {
57 double percent = (impulse - min) / (max - min) * 100;
62 return String.format("%d%% %s", Math.round(percent), className);
65 public String getClassDescription() {
66 return "Class " + className + " (" + UnitGroup.UNITS_IMPULSE.toStringUnit(min) + " - " + UnitGroup.UNITS_IMPULSE.toStringUnit(max) + ")";
71 * Find the appropriate motor class for the provided impulse.
73 public static MotorClass getMotorClass(double impulse) {
74 double epsilon = 0.0000001;
76 // Round large values so 640.1 Ns (which is displayed as 640 Ns) is counted as I-class
78 impulse = Math.rint(impulse);
81 for (MotorClass m : MotorClass.values()) {
82 if (impulse <= m.max + epsilon) {
86 throw new BugException("Could not find motor class for impulse " + impulse);