updated the race class to set heading based on the vmg not just the end of a leg
-race class now stores the boundary -updatePositions now checks if the boat is with the course -update positions now sets heading and speed based on the vmg -updated azimuth to now accept a start and finish gps rather that finding it itself -added a calculatebearingtodestination method that finds the azimuth to the dest from the boat -updated boat tests to use the new azimuth method #story[873]
This commit is contained in:
@@ -42,11 +42,9 @@ public class Boat {
|
||||
*
|
||||
* @return the direction that the boat is heading towards in degrees (-180 to 180).
|
||||
*/
|
||||
public double calculateAzimuth() {
|
||||
public double calculateAzimuth(GPSCoordinate start, GPSCoordinate end) {
|
||||
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
GPSCoordinate start = currentLeg.getStartMarker().getAverageGPSCoordinate();
|
||||
GPSCoordinate end = currentLeg.getEndMarker().getAverageGPSCoordinate();
|
||||
|
||||
calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude());
|
||||
calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude());
|
||||
@@ -59,7 +57,23 @@ public class Boat {
|
||||
* @return The azimuth value which is greater than 0
|
||||
*/
|
||||
public double calculateHeading() {
|
||||
double azimuth = this.calculateAzimuth();
|
||||
double azimuth = this.calculateAzimuth(currentLeg.getStartMarker().getAverageGPSCoordinate(),
|
||||
currentLeg.getEndMarker().getAverageGPSCoordinate());
|
||||
|
||||
if (azimuth >= 0) {
|
||||
return azimuth;
|
||||
} else {
|
||||
return azimuth + 360;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the heding depending on the calculated azimuth value
|
||||
* @return The azimuth value which is greater than 0
|
||||
*/
|
||||
public double calculateBearingToDestination() {
|
||||
double azimuth = this.calculateAzimuth(this.currentPosition,
|
||||
currentLeg.getEndMarker().getAverageGPSCoordinate());
|
||||
|
||||
if (azimuth >= 0) {
|
||||
return azimuth;
|
||||
|
||||
@@ -41,6 +41,7 @@ public class Race implements Runnable {
|
||||
private MockOutput mockOutput;
|
||||
private static int boatOffset = 0;
|
||||
private int finished = 0;
|
||||
private List<GPSCoordinate> boundary;
|
||||
|
||||
|
||||
/**
|
||||
@@ -50,7 +51,7 @@ public class Race implements Runnable {
|
||||
* @param legs Number of marks in order that the boats pass in order to complete the race.
|
||||
* @param scaleFactor for race
|
||||
*/
|
||||
public Race(List<Boat> boats, List<Leg> legs, int raceID, int scaleFactor, MockOutput mockOutput) {
|
||||
public Race(List<Boat> boats, List<Leg> legs, int raceID, int scaleFactor, MockOutput mockOutput, List<GPSCoordinate> boundary) {
|
||||
|
||||
this.startingBoats = FXCollections.observableArrayList(boats);
|
||||
this.legs = legs;
|
||||
@@ -58,6 +59,7 @@ public class Race implements Runnable {
|
||||
this.raceId = raceID;
|
||||
this.scaleFactor = scaleFactor;
|
||||
this.mockOutput = mockOutput;
|
||||
this.boundary = boundary;
|
||||
|
||||
//TODO refactor
|
||||
this.startTime = System.currentTimeMillis() + (this.PRERACE_TIME / this.scaleFactor);
|
||||
@@ -69,7 +71,7 @@ public class Race implements Runnable {
|
||||
}
|
||||
|
||||
public Race(RaceDataSource raceData, int scaleFactor, MockOutput mockOutput) {
|
||||
this(raceData.getBoats(), raceData.getLegs(), raceData.getRaceId(), scaleFactor, mockOutput);
|
||||
this(raceData.getBoats(), raceData.getLegs(), raceData.getRaceId(), scaleFactor, mockOutput, raceData.getBoundary());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -298,12 +300,21 @@ public class Race implements Runnable {
|
||||
|
||||
boolean finish = boat.getCurrentLeg().getName().equals("Finish");
|
||||
if (!finish) {
|
||||
boat.setHeading(boat.calculateHeading());
|
||||
//update boat's distance travelled
|
||||
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
||||
//Calculate boat's new position by adding the distance travelled onto the start point of the leg
|
||||
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartMarker().getAverageGPSCoordinate(),
|
||||
totalDistanceTravelled, boat.calculateAzimuth()));
|
||||
if(!GPSCoordinate.isInsideBoundary(boat.getCurrentPosition(), this.boundary)){
|
||||
//todo - find the acceptable values for direction
|
||||
} else{
|
||||
VMG newHeading = boat.getPolars().calculateVMG(180, 30,
|
||||
boat.calculateBearingToDestination());//todo - get the wind speed from somewhere
|
||||
boat.setHeading(newHeading.bearing);
|
||||
boat.setVelocity(newHeading.speed);
|
||||
// boat.setHeading(boat.calculateHeading());
|
||||
//update boat's distance travelled
|
||||
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
||||
//Calculate boat's new position by adding the distance travelled onto the start point of the leg
|
||||
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartMarker().getAverageGPSCoordinate(),
|
||||
totalDistanceTravelled, boat.getHeading()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class BoatTest {
|
||||
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()), 0, 1e-8);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -31,7 +31,7 @@ public class BoatTest {
|
||||
Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()), 180, 1e-8);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public class BoatTest {
|
||||
Marker endMarker = new Marker(new GPSCoordinate(0, 50));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()), 90, 1e-8);
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public class BoatTest {
|
||||
Marker endMarker = new Marker(new GPSCoordinate(0, -50));
|
||||
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||
TEST_BOAT.setCurrentLeg(start);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8);
|
||||
assertEquals(TEST_BOAT.calculateAzimuth(startMarker.getAverageGPSCoordinate(), endMarker.getAverageGPSCoordinate()), -90, 1e-8);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user