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); + } }