Implemented wake visualisation for each boat

- Added and tested wake calculation for BoatInRace
- Draws boat in canvas between start and entering Finish leg
- Allow boat velocity to be set after initialisation for testing
#story [21]
main
Connor Taylor-Brown 9 years ago
parent f8147be4df
commit e8cd9b2ee8

@ -66,6 +66,7 @@ public class RaceController extends Controller{
BoatInRace[] boatInRaces = new BoatInRace[boats.size()]; BoatInRace[] boatInRaces = new BoatInRace[boats.size()];
raceMap.setBoats(boats.toArray(boatInRaces)); raceMap.setBoats(boats.toArray(boatInRaces));
raceMap.drawRaceMap(); raceMap.drawRaceMap();
raceMap.updateBoats();
} }
/** /**

@ -48,6 +48,10 @@ public class Boat {
return velocity; return velocity;
} }
public void setVelocity(double velocity) {
this.velocity = velocity;
}
/** /**
* *
* @return The Name of the boat. * @return The Name of the boat.

@ -6,6 +6,7 @@ import javafx.scene.paint.Color;
import org.geotools.referencing.GeodeticCalculator; import org.geotools.referencing.GeodeticCalculator;
import seng302.GPSCoordinate; import seng302.GPSCoordinate;
import java.awt.geom.Point2D;
/** /**
@ -147,7 +148,7 @@ public class BoatInRace extends Boat {
/** /**
* Converts an azimuth to a bearing * Converts an azimuth to a bearing
* @param azimuth azimuth valuye to be converted * @param azimuth azimuth value to be converted
* @return the bearings in degrees (0 to 360). * @return the bearings in degrees (0 to 360).
*/ */
public static double calculateHeading(double azimuth) { public static double calculateHeading(double azimuth) {
@ -167,4 +168,17 @@ public class BoatInRace extends Boat {
double azimuth = this.calculateAzimuth(); double azimuth = this.calculateAzimuth();
return calculateHeading(azimuth); 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());
}
} }

@ -66,8 +66,9 @@ public class ResizableRaceCanvas extends Canvas {
* @see Paint * @see Paint
*/ */
public void displayMark(GraphCoordinate graphCoordinate, Paint paint){ public void displayMark(GraphCoordinate graphCoordinate, Paint paint){
double d = 15;
gc.setFill(paint); gc.setFill(paint);
gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 15, 15); gc.fillOval(graphCoordinate.getX() - (d/2), graphCoordinate.getY() - (d/2), d, d);
} }
/** /**
@ -187,7 +188,6 @@ public class ResizableRaceCanvas extends Canvas {
if (boats != null) { if (boats != null) {
for (BoatInRace boat : boats) { for (BoatInRace boat : boats) {
if (boat != null) { if (boat != null) {
// System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour()); displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour());
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition())); displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
} }
@ -198,17 +198,16 @@ public class ResizableRaceCanvas extends Canvas {
displayArrow(new GraphCoordinate(500, 20), 100); displayArrow(new GraphCoordinate(500, 20), 100);
} }
/** public void updateBoats() {
* Draws a boat at a certain GPSCoordinate if (boats != null) {
* @param colour Colour to colour boat. for (BoatInRace boat : boats) {
* @param gpsCoordinates GPScoordinate that the boat is to be drawn at. if (boat != null && !boat.getCurrentLeg().getName().equals("Finish")) {
* @see GPSCoordinate GraphCoordinate wakeFrom = this.map.convertGPS(boat.getCurrentPosition());
* @see Color GraphCoordinate wakeTo = this.map.convertGPS(boat.getWake());
*/ displayLine(wakeFrom, wakeTo, boat.getColour());
public void drawBoat(Color colour, GPSCoordinate gpsCoordinates) { }
GraphCoordinate graphCoordinate = this.map.convertGPS(gpsCoordinates); }
//System.out.println("DrawingBoat" + gpsCoordinates.getLongitude()); }
displayPoint(graphCoordinate, colour);
} }
/** /**

@ -1,6 +1,7 @@
package seng302.Model; package seng302.Model;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import org.junit.Assert;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import seng302.GPSCoordinate; import seng302.GPSCoordinate;
@ -111,4 +112,43 @@ public class BoatInRaceTest {
assertEquals(testBoat.getVelocity(), 20.0); assertEquals(testBoat.getVelocity(), 20.0);
} }
@Test
public void getWakeAtProperHeading() throws Exception {
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
// Construct leg of 0 degrees
GPSCoordinate startPoint = new GPSCoordinate(0, 0);
GPSCoordinate endPoint = new GPSCoordinate(50, 0);
Leg leg0deg = new Leg("Start", startPoint, endPoint, 0);
boat.setCurrentLeg(leg0deg);
boat.setCurrentPosition(new GPSCoordinate(0,0));
assertEquals(0, boat.calculateHeading(), 1e-8);
// Construct leg from wake - heading should be 180 degrees
Leg leg180deg = new Leg("Start", startPoint, boat.getWake(), 0);
boat.setCurrentLeg(leg180deg);
assertEquals(180, boat.calculateHeading(), 1e-8);
}
@Test
public void getWakeProportionalToVelocity() throws Exception {
BoatInRace boat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
// Construct leg of 0 degrees at 0 N
GPSCoordinate startPoint = new GPSCoordinate(0, 0);
GPSCoordinate endPoint = new GPSCoordinate(50, 0);
Leg leg0deg = new Leg("Start", startPoint, endPoint, 0);
boat.setCurrentLeg(leg0deg);
boat.setCurrentPosition(new GPSCoordinate(0,0));
// Get latitude of endpoint of wake at 10 kn (longitude is 0)
double endpointAt10Kn = boat.getWake().getLatitude();
// Latitude of endpoint at 20 kn should be twice endpoint at 10 kn
boat.setVelocity(20);
assertEquals(2*endpointAt10Kn, boat.getWake().getLatitude(), 1e-8);
}
} }
Loading…
Cancel
Save