From 7e2804215beb174dbeb3796a974f14b856a9f2fc Mon Sep 17 00:00:00 2001 From: Erika Savell Date: Wed, 22 Mar 2017 11:38:57 +1300 Subject: [PATCH] Methods for calculating heading (instead of azimuth) added - Azimuth is necessary for geodetic calculator but is between -180 and 180 - Headings need to be displayed from 0 to 360 so conversions methods were necessary #implement #sory[24] --- src/main/java/seng302/Model/BoatInRace.java | 28 ++++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/seng302/Model/BoatInRace.java b/src/main/java/seng302/Model/BoatInRace.java index c20770ea..3e3a1065 100644 --- a/src/main/java/seng302/Model/BoatInRace.java +++ b/src/main/java/seng302/Model/BoatInRace.java @@ -98,7 +98,6 @@ public class BoatInRace extends Boat { if (currentLeg != null) { currentLegName.setValue(currentLeg.getName()); } - return currentLegName; } @@ -136,17 +135,38 @@ public class BoatInRace extends Boat { } /** - * Calculates the bearing of the travel via map coordinates of the raceMarkers - * @return the heading that the boat is heading towards in degrees. + * Calculates the azimuth of the travel via map coordinates of the raceMarkers + * @return the direction that the boat is heading towards in degrees (-180 to 180). */ public double calculateAzimuth(){ - //to be changed to coordinates when used to match reality. + GeodeticCalculator calc = new GeodeticCalculator(); calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLongitude(), currentLeg.getStartGraphCoordinate().getLatitude()); calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLongitude(), currentLeg.getEndGraphCoordinate().getLatitude()); return calc.getAzimuth(); + } + /** + * Converts an azimuth to a bearing + * @param azimuth azimuth valuye to be converted + * @return the bearings in degrees (0 to 360). + */ + public static double calculateHeading(double azimuth) { + if (azimuth >= 0) { + return azimuth; + } + else { + return azimuth + 360; + } } + /** + * Calculates the bearing of the travel via map coordinates of the raceMarkers + * @return the direction that the boat is heading towards in degrees (0 to 360). + */ + public double calculateHeading(){ + double azimuth = this.calculateAzimuth(); + return calculateHeading(azimuth); + } }