Switched latitude/longitude around

We were using latitude on the x plane and longitude on the y plane

#story[9] #fix
main
Erika Savell 9 years ago
parent 3afa13d24b
commit a9601eb760

@ -53,11 +53,11 @@ public class RaceController extends Controller{
* @param boats boats that are to be displayed in the race * @param boats boats that are to be displayed in the race
* @see ResizableRaceCanvas * @see ResizableRaceCanvas
*/ */
public void updateMap(ObservableList<BoatInRace> boats) { public void updateMap(ObservableList<BoatInRace> boats) {
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();
} }
/** /**
@ -103,7 +103,6 @@ public class RaceController extends Controller{
*/ */
private ArrayList<Leg> generateBermudaCourseLegs() { private ArrayList<Leg> generateBermudaCourseLegs() {
ArrayList<Leg> legs = new ArrayList<>(); ArrayList<Leg> legs = new ArrayList<>();
Leg leg1 = new Leg("Start to Mark 1", Constants.startLineMarker1, Constants.mark1, 0); 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 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); Leg leg3 = new Leg("Leeward Gate to Windward Gate", Constants.leewardGate1, Constants.windwardGate1, 2);
@ -134,7 +133,4 @@ public class RaceController extends Controller{
} }
} }

@ -28,9 +28,7 @@ public class GPSCoordinate {
* Gets the Longitude that the Coordinate is at. * Gets the Longitude that the Coordinate is at.
* @return Returns the longitude of the Coordinate. * @return Returns the longitude of the Coordinate.
*/ */
public double getLongitude() { public double getLongitude() { return longitude; }
return longitude;
}
/** /**
* To String method of the Coordinate in the form Latitude: $f, Longitude: $f. * To String method of the Coordinate in the form Latitude: $f, Longitude: $f.

@ -27,10 +27,6 @@ public class Boat {
return name; return name;
} }
public void setName(String name) {
this.name = name;
}
/** /**
* *
* @return returns the speed of the boat. * @return returns the speed of the boat.

@ -128,17 +128,14 @@ public class BoatInRace extends Boat {
* Calculates the bearing of the travel via map coordinates of the raceMarkers * Calculates the bearing of the travel via map coordinates of the raceMarkers
* @return the heading that the boat is heading towards in degrees. * @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. //to be changed to coordinates when used to match reality.
GeodeticCalculator calc = new GeodeticCalculator(); GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLatitude(), currentLeg.getStartGraphCoordinate().getLongitude()); calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLongitude(), currentLeg.getStartGraphCoordinate().getLatitude());
calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLongitude(), currentLeg.getEndGraphCoordinate().getLatitude());
calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLatitude(), currentLeg.getEndGraphCoordinate().getLongitude());
return calc.getAzimuth(); 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);
} }
} }

@ -39,7 +39,7 @@ public class ConstantVelocityRace extends Race {
boat.setDistanceTravelledInLeg(totalDistanceTravelled); boat.setDistanceTravelledInLeg(totalDistanceTravelled);
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartGraphCoordinate(), 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(); 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.setStartingGeographicPoint(startPoint);
geodeticCalculator.setDirection(azimuth, distanceTravelled * Constants.NMToMetersConversion); geodeticCalculator.setDirection(azimuth,distanceTravelled * Constants.NMToMetersConversion);
Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint(); Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint();
return new GPSCoordinate(endPoint.getX(), endPoint.getY()); return new GPSCoordinate(endPoint.getY(), endPoint.getX());
} }
} }

@ -97,8 +97,8 @@ public class Leg {
private double calculateDistance() { private double calculateDistance() {
GeodeticCalculator calc = new GeodeticCalculator(); GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(startGPSCoordinate.getLatitude(), startGPSCoordinate.getLongitude()); calc.setStartingGeographicPoint(startGPSCoordinate.getLongitude(), startGPSCoordinate.getLatitude());
calc.setDestinationGeographicPoint(endGPSCoordinate.getLatitude(), endGPSCoordinate.getLongitude()); calc.setDestinationGeographicPoint(endGPSCoordinate.getLongitude(), endGPSCoordinate.getLatitude());
return calc.getOrthodromicDistance() / Constants.NMToMetersConversion; return calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
} }
} }

@ -23,7 +23,6 @@ public abstract class Race implements Runnable {
protected int boatsFinished = 0; protected int boatsFinished = 0;
protected long totalTimeElapsed; protected long totalTimeElapsed;
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop 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);}); Platform.runLater(() -> {controller.setTimer(time);});
} }
/** /**
* Starts the Race Simulation, playing the race start to finish with the timescale. * 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. * This prints the boats participating, the order that the events occur in time order, and the respective information of the events.

@ -134,7 +134,7 @@ public class ResizableRaceCanvas extends Canvas {
gc.clearRect(0, 0, width, height); gc.clearRect(0, 0, width, height);
System.out.println("Race Map Canvas Width: "+ width + ", Height:" + 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){ if (map == null){
return; return;

@ -9,14 +9,14 @@ public class RaceMap {
/** /**
* Contructor Method. * Contructor Method.
* @param x1 Latitude of the top left point. * @param x1 Longitude of the top left point.
* @param y1 Longitude of the top left point. * @param y1 Latitude of the top left point.
* @param x2 Latitude of the top right point. * @param x2 Longitude of the top right point.
* @param y2 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 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. * @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; 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 * @see GraphCoordinate
*/ */
public GraphCoordinate convertGPS(double lat, double lon) { 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))));
} }
/** /**

@ -4,6 +4,8 @@ package seng302.Model;
import org.junit.Test; import org.junit.Test;
import seng302.GPSCoordinate; import seng302.GPSCoordinate;
import java.awt.geom.Point2D;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
/** /**
@ -14,7 +16,8 @@ public class ConstantVelocityRaceTest {
@Test @Test
public void travelling5nmNorthGivesCorrectNewCoordinates() { public void travelling5nmNorthGivesCorrectNewCoordinates() {
GPSCoordinate oldPos = new GPSCoordinate(0, 0); 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); // assertEquals(ConstantVelocityRace.calculatePosition(oldPos, 5, 90).getLatitude(), 0.08, 1e-1);
System.out.println(ConstantVelocityRace.calculatePosition(oldPos, 5, 0).getLongitude()); System.out.println(ConstantVelocityRace.calculatePosition(oldPos, 5, 0).getLongitude());
} }

Loading…
Cancel
Save