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]
This commit is contained in:
@@ -98,7 +98,6 @@ public class BoatInRace extends Boat {
|
|||||||
if (currentLeg != null) {
|
if (currentLeg != null) {
|
||||||
currentLegName.setValue(currentLeg.getName());
|
currentLegName.setValue(currentLeg.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentLegName;
|
return currentLegName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,17 +135,38 @@ public class BoatInRace extends Boat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the bearing of the travel via map coordinates of the raceMarkers
|
* Calculates the azimuth of the travel via map coordinates of the raceMarkers
|
||||||
* @return the heading that the boat is heading towards in degrees.
|
* @return the direction that the boat is heading towards in degrees (-180 to 180).
|
||||||
*/
|
*/
|
||||||
public double calculateAzimuth(){
|
public double calculateAzimuth(){
|
||||||
//to be changed to coordinates when used to match reality.
|
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLongitude(), currentLeg.getStartGraphCoordinate().getLatitude());
|
calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLongitude(), currentLeg.getStartGraphCoordinate().getLatitude());
|
||||||
calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLongitude(), currentLeg.getEndGraphCoordinate().getLatitude());
|
calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLongitude(), currentLeg.getEndGraphCoordinate().getLatitude());
|
||||||
|
|
||||||
return calc.getAzimuth();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user