From 64dd1081ccb5aa481ac7f3111e97cdd9562d4967 Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Sun, 8 Jan 2012 00:47:37 +0000 Subject: [PATCH] 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 --- .../rocketcomponent/RocketUtils.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/net/sf/openrocket/rocketcomponent/RocketUtils.java 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; + } + +} -- 2.39.5