|
|
|
|
@ -8,7 +8,6 @@ import seng302.GPSCoordinate;
|
|
|
|
|
|
|
|
|
|
import java.awt.geom.Point2D;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Boat in the Race extends Boat.
|
|
|
|
|
* Created by esa46 on 15/03/17.
|
|
|
|
|
@ -16,6 +15,7 @@ import java.awt.geom.Point2D;
|
|
|
|
|
public class BoatInRace extends Boat {
|
|
|
|
|
|
|
|
|
|
private Leg currentLeg;
|
|
|
|
|
private double scaledVelocity;
|
|
|
|
|
private double distanceTravelledInLeg;
|
|
|
|
|
private GPSCoordinate currentPosition;
|
|
|
|
|
private long timeFinished;
|
|
|
|
|
@ -25,6 +25,7 @@ public class BoatInRace extends Boat {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor method.
|
|
|
|
|
*
|
|
|
|
|
* @param name Name of the boat.
|
|
|
|
|
* @param velocity Speed that the boat travels.
|
|
|
|
|
* @param colour Colour the boat will be displayed as on the map
|
|
|
|
|
@ -36,7 +37,72 @@ public class BoatInRace extends Boat {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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() {
|
|
|
|
|
|
|
|
|
|
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 value 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GPSCoordinate getWake() {
|
|
|
|
|
double reverseHeading = calculateHeading() - 180;
|
|
|
|
|
double distance = getVelocity();
|
|
|
|
|
|
|
|
|
|
GeodeticCalculator calc = new GeodeticCalculator();
|
|
|
|
|
calc.setStartingGeographicPoint(
|
|
|
|
|
new Point2D.Double(getCurrentPosition().getLongitude(), getCurrentPosition().getLatitude())
|
|
|
|
|
);
|
|
|
|
|
calc.setDirection(reverseHeading, distance);
|
|
|
|
|
Point2D endpoint = calc.getDestinationGeographicPoint();
|
|
|
|
|
return new GPSCoordinate(endpoint.getY(), endpoint.getX());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Scaled velocity of the boat
|
|
|
|
|
*/
|
|
|
|
|
public double getScaledVelocity() {
|
|
|
|
|
return scaledVelocity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the boat's scaled velocity
|
|
|
|
|
* @param velocity
|
|
|
|
|
*/
|
|
|
|
|
public void setScaledVelocity(double velocity) {
|
|
|
|
|
this.scaledVelocity = velocity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Returns the current position of the boat in a GPSCoordinate Class.
|
|
|
|
|
* @see GPSCoordinate
|
|
|
|
|
*/
|
|
|
|
|
@ -45,7 +111,16 @@ public class BoatInRace extends Boat {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the current position on the GPS that the boat.
|
|
|
|
|
*
|
|
|
|
|
* @param position GPSCoordinate of the position that the boat is currently on.
|
|
|
|
|
* @see GPSCoordinate
|
|
|
|
|
*/
|
|
|
|
|
public void setCurrentPosition(GPSCoordinate position) {
|
|
|
|
|
this.currentPosition = position;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Returns the time that the boat finished the race.
|
|
|
|
|
*/
|
|
|
|
|
public long getTimeFinished() {
|
|
|
|
|
@ -53,7 +128,15 @@ public class BoatInRace extends Boat {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the time that the boat finished the race.
|
|
|
|
|
*
|
|
|
|
|
* @param timeFinished Time the boat finished the race.
|
|
|
|
|
*/
|
|
|
|
|
public void setTimeFinished(long timeFinished) {
|
|
|
|
|
this.timeFinished = timeFinished;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Returns the colour of the boat.
|
|
|
|
|
*/
|
|
|
|
|
public Color getColour() {
|
|
|
|
|
@ -62,6 +145,7 @@ public class BoatInRace extends Boat {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the colour that boat will be shown as when drawn on the ResizableRaceCanvas.
|
|
|
|
|
*
|
|
|
|
|
* @param colour Colour that the boat is to be set to.
|
|
|
|
|
* @see ResizableRaceCanvas
|
|
|
|
|
*/
|
|
|
|
|
@ -69,16 +153,9 @@ public class BoatInRace extends Boat {
|
|
|
|
|
this.colour = colour;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the time that the boat finished the race.
|
|
|
|
|
* @param timeFinished Time the boat finished the race.
|
|
|
|
|
*/
|
|
|
|
|
public void setTimeFinished(long timeFinished) {
|
|
|
|
|
this.timeFinished = timeFinished;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the current leg that the boat is on.
|
|
|
|
|
*
|
|
|
|
|
* @return returns the leg the boat is on in a Leg class
|
|
|
|
|
* @see Leg
|
|
|
|
|
*/
|
|
|
|
|
@ -87,7 +164,8 @@ public class BoatInRace extends Boat {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the current Leg of that the boat is on.
|
|
|
|
|
* Sets the boat's current leg.
|
|
|
|
|
*
|
|
|
|
|
* @param currentLeg Leg class that the boat is currently on.
|
|
|
|
|
* @see Leg
|
|
|
|
|
*/
|
|
|
|
|
@ -96,89 +174,44 @@ public class BoatInRace extends Boat {
|
|
|
|
|
this.currentLegName.setValue(currentLeg.getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public StringProperty getCurrentLegName(){
|
|
|
|
|
/**
|
|
|
|
|
* @return Name of boat's current leg
|
|
|
|
|
*/
|
|
|
|
|
public StringProperty getCurrentLegName() {
|
|
|
|
|
return currentLegName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the distance travelled by the boat in the leg.
|
|
|
|
|
*
|
|
|
|
|
* @return Returns the value in nautical miles (1.852km) that the boat has traversed.
|
|
|
|
|
*/
|
|
|
|
|
public double getDistanceTravelledInLeg() {
|
|
|
|
|
return distanceTravelledInLeg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the current position on the GPS that the boat.
|
|
|
|
|
* @param position GPSCoordinate of the position that the boat is currently on.
|
|
|
|
|
* @see GPSCoordinate
|
|
|
|
|
*/
|
|
|
|
|
public void setCurrentPosition(GPSCoordinate position) {
|
|
|
|
|
this.currentPosition = position;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the distance travelled by the boat in the leg in nautical miles (1.852km)
|
|
|
|
|
*
|
|
|
|
|
* @param distanceTravelledInLeg Distance travelled by the boat in nautical miles.
|
|
|
|
|
*/
|
|
|
|
|
public void setDistanceTravelledInLeg(double distanceTravelledInLeg) {
|
|
|
|
|
this.distanceTravelledInLeg = distanceTravelledInLeg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isFinished() {
|
|
|
|
|
return this.finished;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setFinished(boolean bool) {
|
|
|
|
|
this.finished = bool;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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).
|
|
|
|
|
* @return true if boat has finished, fals eif not
|
|
|
|
|
*/
|
|
|
|
|
public double calculateAzimuth(){
|
|
|
|
|
|
|
|
|
|
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 value 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;
|
|
|
|
|
}
|
|
|
|
|
public boolean isFinished() {
|
|
|
|
|
return this.finished;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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).
|
|
|
|
|
* Sets whether boat is finished or not
|
|
|
|
|
* @param bool
|
|
|
|
|
*/
|
|
|
|
|
public double calculateHeading(){
|
|
|
|
|
double azimuth = this.calculateAzimuth();
|
|
|
|
|
return calculateHeading(azimuth);
|
|
|
|
|
public void setFinished(boolean bool) {
|
|
|
|
|
this.finished = bool;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GPSCoordinate getWake() {
|
|
|
|
|
double reverseHeading = calculateHeading() - 180;
|
|
|
|
|
double distance = getVelocity();
|
|
|
|
|
|
|
|
|
|
GeodeticCalculator calc = new GeodeticCalculator();
|
|
|
|
|
calc.setStartingGeographicPoint(
|
|
|
|
|
new Point2D.Double(getCurrentPosition().getLongitude(), getCurrentPosition().getLatitude())
|
|
|
|
|
);
|
|
|
|
|
calc.setDirection(reverseHeading, distance);
|
|
|
|
|
Point2D endpoint = calc.getDestinationGeographicPoint();
|
|
|
|
|
return new GPSCoordinate(endpoint.getY(), endpoint.getX());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|