From a9601eb760fbdb352bf1d22e09d6b6f05f24150b Mon Sep 17 00:00:00 2001 From: Erika Savell Date: Mon, 20 Mar 2017 16:40:32 +1300 Subject: [PATCH] Switched latitude/longitude around We were using latitude on the x plane and longitude on the y plane #story[9] #fix --- .../java/seng302/Controllers/RaceController.java | 6 +----- src/main/java/seng302/GPSCoordinate.java | 4 +--- src/main/java/seng302/Model/Boat.java | 4 ---- src/main/java/seng302/Model/BoatInRace.java | 11 ++++------- .../java/seng302/Model/ConstantVelocityRace.java | 8 ++++---- src/main/java/seng302/Model/Leg.java | 4 ++-- src/main/java/seng302/Model/Race.java | 3 --- .../java/seng302/Model/ResizableRaceCanvas.java | 2 +- src/main/java/seng302/RaceMap.java | 13 +++++++------ .../seng302/Model/ConstantVelocityRaceTest.java | 5 ++++- 10 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/main/java/seng302/Controllers/RaceController.java b/src/main/java/seng302/Controllers/RaceController.java index a5e5c4e2..20b85b77 100644 --- a/src/main/java/seng302/Controllers/RaceController.java +++ b/src/main/java/seng302/Controllers/RaceController.java @@ -53,11 +53,11 @@ public class RaceController extends Controller{ * @param boats boats that are to be displayed in the race * @see ResizableRaceCanvas */ + public void updateMap(ObservableList boats) { BoatInRace[] boatInRaces = new BoatInRace[boats.size()]; raceMap.setBoats(boats.toArray(boatInRaces)); raceMap.drawRaceMap(); - } /** @@ -103,7 +103,6 @@ public class RaceController extends Controller{ */ private ArrayList generateBermudaCourseLegs() { ArrayList legs = new ArrayList<>(); - Leg leg1 = new Leg("Start to Mark 1", Constants.startLineMarker1, Constants.mark1, 0); Leg leg2 = new Leg("Mark 1 to Leeward Gate", Constants.mark1, Constants.leewardGate1, 1); Leg leg3 = new Leg("Leeward Gate to Windward Gate", Constants.leewardGate1, Constants.windwardGate1, 2); @@ -134,7 +133,4 @@ public class RaceController extends Controller{ } - - - } diff --git a/src/main/java/seng302/GPSCoordinate.java b/src/main/java/seng302/GPSCoordinate.java index 4f55a037..13fa0231 100644 --- a/src/main/java/seng302/GPSCoordinate.java +++ b/src/main/java/seng302/GPSCoordinate.java @@ -28,9 +28,7 @@ public class GPSCoordinate { * Gets the Longitude that the Coordinate is at. * @return Returns the longitude of the Coordinate. */ - public double getLongitude() { - return longitude; - } + public double getLongitude() { return longitude; } /** * To String method of the Coordinate in the form Latitude: $f, Longitude: $f. diff --git a/src/main/java/seng302/Model/Boat.java b/src/main/java/seng302/Model/Boat.java index 3fedb34e..25d67520 100644 --- a/src/main/java/seng302/Model/Boat.java +++ b/src/main/java/seng302/Model/Boat.java @@ -27,10 +27,6 @@ public class Boat { return name; } - public void setName(String name) { - this.name = name; - } - /** * * @return returns the speed of the boat. diff --git a/src/main/java/seng302/Model/BoatInRace.java b/src/main/java/seng302/Model/BoatInRace.java index 6a7b9287..0c278222 100644 --- a/src/main/java/seng302/Model/BoatInRace.java +++ b/src/main/java/seng302/Model/BoatInRace.java @@ -128,17 +128,14 @@ 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. */ - public double calculateHeading(){ + public double calculateAzimuth(){ //to be changed to coordinates when used to match reality. GeodeticCalculator calc = new GeodeticCalculator(); - calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLatitude(), currentLeg.getStartGraphCoordinate().getLongitude()); - - calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLatitude(), currentLeg.getEndGraphCoordinate().getLongitude()); + calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLongitude(), currentLeg.getStartGraphCoordinate().getLatitude()); + calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLongitude(), currentLeg.getEndGraphCoordinate().getLatitude()); return calc.getAzimuth(); -// double thetaHat = Math.atan2((currentLeg.getEndGraphCoordinate().getLatitude() - currentLeg.getStartGraphCoordinate().getLongitude()), -// (currentLeg.getEndGraphCoordinate().getLatitude() - currentLeg.getStartGraphCoordinate().getLongitude())); -// return thetaHat >= 0 ? Math.toDegrees(thetaHat): Math.toDegrees(thetaHat + 2 * Math.PI); + } } diff --git a/src/main/java/seng302/Model/ConstantVelocityRace.java b/src/main/java/seng302/Model/ConstantVelocityRace.java index fe196bb6..db18b1e3 100644 --- a/src/main/java/seng302/Model/ConstantVelocityRace.java +++ b/src/main/java/seng302/Model/ConstantVelocityRace.java @@ -39,7 +39,7 @@ public class ConstantVelocityRace extends Race { boat.setDistanceTravelledInLeg(totalDistanceTravelled); boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartGraphCoordinate(), - totalDistanceTravelled, boat.calculateHeading())); + totalDistanceTravelled, boat.calculateAzimuth())); } } @@ -57,14 +57,14 @@ public class ConstantVelocityRace extends Race { GeodeticCalculator geodeticCalculator = new GeodeticCalculator(); - Point2D startPoint = new Point2D.Double(oldCoordinates.getLatitude(), oldCoordinates.getLongitude()); + Point2D startPoint = new Point2D.Double(oldCoordinates.getLongitude(), oldCoordinates.getLatitude()); geodeticCalculator.setStartingGeographicPoint(startPoint); - geodeticCalculator.setDirection(azimuth, distanceTravelled * Constants.NMToMetersConversion); + geodeticCalculator.setDirection(azimuth,distanceTravelled * Constants.NMToMetersConversion); Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint(); - return new GPSCoordinate(endPoint.getX(), endPoint.getY()); + return new GPSCoordinate(endPoint.getY(), endPoint.getX()); } } \ No newline at end of file diff --git a/src/main/java/seng302/Model/Leg.java b/src/main/java/seng302/Model/Leg.java index 84810448..0d1f5649 100644 --- a/src/main/java/seng302/Model/Leg.java +++ b/src/main/java/seng302/Model/Leg.java @@ -97,8 +97,8 @@ public class Leg { private double calculateDistance() { GeodeticCalculator calc = new GeodeticCalculator(); - calc.setStartingGeographicPoint(startGPSCoordinate.getLatitude(), startGPSCoordinate.getLongitude()); - calc.setDestinationGeographicPoint(endGPSCoordinate.getLatitude(), endGPSCoordinate.getLongitude()); + calc.setStartingGeographicPoint(startGPSCoordinate.getLongitude(), startGPSCoordinate.getLatitude()); + calc.setDestinationGeographicPoint(endGPSCoordinate.getLongitude(), endGPSCoordinate.getLatitude()); return calc.getOrthodromicDistance() / Constants.NMToMetersConversion; } } diff --git a/src/main/java/seng302/Model/Race.java b/src/main/java/seng302/Model/Race.java index 287540c4..0cc498ce 100644 --- a/src/main/java/seng302/Model/Race.java +++ b/src/main/java/seng302/Model/Race.java @@ -23,7 +23,6 @@ public abstract class Race implements Runnable { protected int boatsFinished = 0; protected long totalTimeElapsed; - private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop /** @@ -91,8 +90,6 @@ public abstract class Race implements Runnable { Platform.runLater(() -> {controller.setTimer(time);}); } - - /** * Starts the Race Simulation, playing the race start to finish with the timescale. * This prints the boats participating, the order that the events occur in time order, and the respective information of the events. diff --git a/src/main/java/seng302/Model/ResizableRaceCanvas.java b/src/main/java/seng302/Model/ResizableRaceCanvas.java index 9cbd403f..46c23f5a 100644 --- a/src/main/java/seng302/Model/ResizableRaceCanvas.java +++ b/src/main/java/seng302/Model/ResizableRaceCanvas.java @@ -134,7 +134,7 @@ public class ResizableRaceCanvas extends Canvas { gc.clearRect(0, 0, width, height); System.out.println("Race Map Canvas Width: "+ width + ", Height:" + height); - this.map = new RaceMap(32.320989, -64.863, 32.278, -64.821, (int)width, (int)height); + this.map = new RaceMap(32.278, -64.863, 32.320989, -64.821, (int)width, (int)height); if (map == null){ return; diff --git a/src/main/java/seng302/RaceMap.java b/src/main/java/seng302/RaceMap.java index 1ad374ab..cf924202 100644 --- a/src/main/java/seng302/RaceMap.java +++ b/src/main/java/seng302/RaceMap.java @@ -9,14 +9,14 @@ public class RaceMap { /** * Contructor Method. - * @param x1 Latitude of the top left point. - * @param y1 Longitude of the top left point. - * @param x2 Latitude of the top right point. - * @param y2 Longitude of the top right point. + * @param x1 Longitude of the top left point. + * @param y1 Latitude of the top left point. + * @param x2 Longitude of the top right point. + * @param y2 Latitude of the top right point. * @param width width that the Canvas the race is to be drawn on is. * @param height height that the Canvas the race is to be drawn on is. */ - public RaceMap(double x1, double y1, double x2, double y2, int width, int height) { + public RaceMap(double y1, double x1, double y2, double x2, int height, int width) { this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2; this.width = width; this.height = height; } @@ -28,7 +28,8 @@ public class RaceMap { * @see GraphCoordinate */ public GraphCoordinate convertGPS(double lat, double lon) { - return new GraphCoordinate((int) ((height * (lon - y1) / (y2 - y1))),(int) (width * (lat - x1) / (x2 - x1))); + + return new GraphCoordinate((int) (width * (lon - x1) / (x2 - x1)), (int) (height - (height * (lat - y1) / (y2 - y1)))); } /** diff --git a/src/test/java/seng302/Model/ConstantVelocityRaceTest.java b/src/test/java/seng302/Model/ConstantVelocityRaceTest.java index ab249ef9..19e57e7d 100644 --- a/src/test/java/seng302/Model/ConstantVelocityRaceTest.java +++ b/src/test/java/seng302/Model/ConstantVelocityRaceTest.java @@ -4,6 +4,8 @@ package seng302.Model; import org.junit.Test; import seng302.GPSCoordinate; +import java.awt.geom.Point2D; + import static org.junit.Assert.assertEquals; /** @@ -14,7 +16,8 @@ public class ConstantVelocityRaceTest { @Test public void travelling5nmNorthGivesCorrectNewCoordinates() { GPSCoordinate oldPos = new GPSCoordinate(0, 0); - System.out.println(ConstantVelocityRace.calculatePosition(oldPos, 5, 0).getLatitude()); + GPSCoordinate newPos = ConstantVelocityRace.calculatePosition(oldPos, 5, 0); +// assertEquals(newPos.getLatitude(), 0.08374461297528203, ); // assertEquals(ConstantVelocityRace.calculatePosition(oldPos, 5, 90).getLatitude(), 0.08, 1e-1); System.out.println(ConstantVelocityRace.calculatePosition(oldPos, 5, 0).getLongitude()); }