From: kruland2607 Date: Sun, 8 Jan 2012 00:47:37 +0000 (+0000) Subject: Added class with couple of helper methods to compute information about a rocket.... X-Git-Tag: upstream/12.03~1^2~193 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=64dd1081ccb5aa481ac7f3111e97cdd9562d4967;p=debian%2Fopenrocket Added class with couple of helper methods to compute information about a rocket. Includes getCG and getLength. git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@277 180e2498-e6e9-4542-8430-84ac67f01cd8 --- diff --git a/src/net/sf/openrocket/rocketcomponent/RocketUtils.java b/src/net/sf/openrocket/rocketcomponent/RocketUtils.java new file mode 100644 index 00000000..2e4b63b8 --- /dev/null +++ b/src/net/sf/openrocket/rocketcomponent/RocketUtils.java @@ -0,0 +1,34 @@ +package net.sf.openrocket.rocketcomponent; + +import java.util.Collection; + +import net.sf.openrocket.masscalc.BasicMassCalculator; +import net.sf.openrocket.masscalc.MassCalculator; +import net.sf.openrocket.masscalc.MassCalculator.MassCalcType; +import net.sf.openrocket.util.Coordinate; + +public abstract class RocketUtils { + + public static double getLength(Rocket rocket) { + double length = 0; + Collection bounds = rocket.getDefaultConfiguration().getBounds(); + if (!bounds.isEmpty()) { + double minX = Double.POSITIVE_INFINITY, maxX = Double.NEGATIVE_INFINITY; + for (Coordinate c : bounds) { + if (c.x < minX) + minX = c.x; + if (c.x > maxX) + maxX = c.x; + } + length = maxX - minX; + } + return length; + } + + public static Coordinate getCG(Rocket rocket) { + MassCalculator massCalculator = new BasicMassCalculator(); + Coordinate cg = massCalculator.getCG(rocket.getDefaultConfiguration(), MassCalcType.LAUNCH_MASS); + return cg; + } + +}