David Wu 9 years ago
commit b5496b07de

@ -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<BoatInRace> 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<Leg> generateBermudaCourseLegs() {
ArrayList<Leg> 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{
}
}

@ -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.

@ -27,10 +27,6 @@ public class Boat {
return name;
}
public void setName(String name) {
this.name = name;
}
/**
*
* @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
* @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);
}
}

@ -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);
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() {
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;
}
}

@ -122,8 +122,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.

@ -144,7 +144,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;

@ -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))));
}
/**

@ -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());
}

Loading…
Cancel
Save