Boat moves between legs and finishes
- Have hard coded in first two legs -Possibly found problem with lat and longitude coordinate system being switched #story[9]
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
package seng302;
|
||||||
|
|
||||||
|
import seng302.Model.Leg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Erika on 19-Mar-17.
|
||||||
|
*/
|
||||||
|
public class Constants {
|
||||||
|
|
||||||
|
public static final int NMToMetersConversion = 1852; //nautical miles
|
||||||
|
|
||||||
|
public static final GPSCoordinate startLineMarker1 = new GPSCoordinate(32.296577, -64.854304);
|
||||||
|
public static final GPSCoordinate startLineMarker2 = new GPSCoordinate(32.293771, -64.855242);
|
||||||
|
|
||||||
|
public static final GPSCoordinate mark1 = new GPSCoordinate(32.293039, -64.843983);
|
||||||
|
|
||||||
|
public static final GPSCoordinate leewardGate1 = new GPSCoordinate(32.284680, -64.850045);
|
||||||
|
public static final GPSCoordinate leewardGate2 = new GPSCoordinate(32.280164, -64.847591);
|
||||||
|
public static final GPSCoordinate windwardGate1 = new GPSCoordinate(32.309693, -64.835249);
|
||||||
|
public static final GPSCoordinate windwardGate2 = new GPSCoordinate(32.308046, -64.831785);
|
||||||
|
|
||||||
|
//public static final Leg bermudaCourseStartToMark1 = new Leg(0, , new )
|
||||||
|
}
|
||||||
@@ -13,11 +13,13 @@ import javafx.scene.layout.AnchorPane;
|
|||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
import org.geotools.referencing.GeodeticCalculator;
|
import org.geotools.referencing.GeodeticCalculator;
|
||||||
|
import seng302.Constants;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
import seng302.Model.ResizableRaceCanvas;
|
import seng302.Model.ResizableRaceCanvas;
|
||||||
import seng302.Model.*;
|
import seng302.Model.*;
|
||||||
import seng302.RaceMap;
|
import seng302.RaceMap;
|
||||||
|
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
@@ -68,7 +70,7 @@ public class RaceController extends Controller{
|
|||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
|
||||||
BoatInRace boat = new BoatInRace("NZ", 100);
|
BoatInRace boat = new BoatInRace("NZ", 400);
|
||||||
boat.setColour(Color.DARKVIOLET);
|
boat.setColour(Color.DARKVIOLET);
|
||||||
boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||||
BoatInRace[] boats = new BoatInRace[] {boat};
|
BoatInRace[] boats = new BoatInRace[] {boat};
|
||||||
@@ -90,14 +92,9 @@ public class RaceController extends Controller{
|
|||||||
private ArrayList<Leg> bermudaCourseLegs() {
|
private ArrayList<Leg> bermudaCourseLegs() {
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
ArrayList<Leg> legs = new ArrayList<>();
|
||||||
|
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
Leg leg1 = new Leg("Start to Mark 1", Constants.startLineMarker1, Constants.mark1, 0);
|
||||||
calc.setStartingGeographicPoint(32.296577, -64.854304);
|
Leg leg2 = new Leg("Mark 1 to Leeward Gate", Constants.mark1, Constants.leewardGate1, 1);
|
||||||
calc.setDestinationGeographicPoint(32.293039, -64.843983);
|
legs.add(leg1); legs.add(leg2);
|
||||||
double distance = calc.getOrthodromicDistance();
|
|
||||||
Leg leg1 = new Leg("Start to Mark 1", distance, new GPSCoordinate(32.296577, -64.854304),
|
|
||||||
new GPSCoordinate(32.293039, -64.843983), 0);
|
|
||||||
|
|
||||||
legs.add(leg1);
|
|
||||||
return legs;
|
return legs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
|
import seng302.Constants;
|
||||||
import seng302.Controllers.RaceController;
|
import seng302.Controllers.RaceController;
|
||||||
|
|
||||||
|
|
||||||
@@ -36,13 +37,23 @@ public class ConstantVelocityRace extends Race {
|
|||||||
double distanceTravelled = boat.getVelocity() * millisecondsElapsed/3600000;
|
double distanceTravelled = boat.getVelocity() * millisecondsElapsed/3600000;
|
||||||
double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg();
|
double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg();
|
||||||
|
|
||||||
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
if (!boat.getCurrentLeg().getName().equals("Finish")) {
|
||||||
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartGraphCoordinate(),
|
|
||||||
totalDistanceTravelled, boat.calculateHeading()));
|
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
||||||
|
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartGraphCoordinate(),
|
||||||
|
totalDistanceTravelled, boat.calculateHeading()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GPSCoordinate calculatePosition(GPSCoordinate oldCoordinates, double distanceTravelled, double heading) {
|
/**
|
||||||
|
*
|
||||||
|
* @param oldCoordinates GPS coordinates of the boat's starting position
|
||||||
|
* @param distanceTravelled distance in nautical miles
|
||||||
|
* @param azimuth boat's current direction. Value between -180 and 180
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static GPSCoordinate calculatePosition(GPSCoordinate oldCoordinates, double distanceTravelled, double azimuth) {
|
||||||
|
|
||||||
//Find new coordinate using current heading and distance
|
//Find new coordinate using current heading and distance
|
||||||
|
|
||||||
@@ -51,7 +62,7 @@ public class ConstantVelocityRace extends Race {
|
|||||||
Point2D startPoint = new Point2D.Double(oldCoordinates.getLatitude(), oldCoordinates.getLongitude());
|
Point2D startPoint = new Point2D.Double(oldCoordinates.getLatitude(), oldCoordinates.getLongitude());
|
||||||
geodeticCalculator.setStartingGeographicPoint(startPoint);
|
geodeticCalculator.setStartingGeographicPoint(startPoint);
|
||||||
|
|
||||||
geodeticCalculator.setDirection(heading, distanceTravelled * 1852);
|
geodeticCalculator.setDirection(azimuth, distanceTravelled * Constants.NMToMetersConversion);
|
||||||
|
|
||||||
Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint();
|
Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
|
import org.geotools.referencing.Console;
|
||||||
|
import org.geotools.referencing.GeodeticCalculator;
|
||||||
|
import seng302.Constants;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
import seng302.GraphCoordinate;
|
import seng302.GraphCoordinate;
|
||||||
|
|
||||||
@@ -18,22 +21,17 @@ public class Leg {
|
|||||||
/**
|
/**
|
||||||
* Leg Initialiser
|
* Leg Initialiser
|
||||||
* @param name Name of the Leg
|
* @param name Name of the Leg
|
||||||
* @param distance Total Distance located in the Race
|
|
||||||
*/
|
*/
|
||||||
public Leg(String name, double distance, GPSCoordinate start, GPSCoordinate end, int number) {
|
public Leg(String name, GPSCoordinate start, GPSCoordinate end, int number) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.distance = distance;
|
|
||||||
this.startGPSCoordinate = start;
|
this.startGPSCoordinate = start;
|
||||||
this.endGPSCoordinate = end;
|
this.endGPSCoordinate = end;
|
||||||
this.legNumber = number;
|
this.legNumber = number;
|
||||||
|
this.distance = calculateDistance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Leg(String name) {
|
public Leg(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.distance = 0;
|
|
||||||
this.startGPSCoordinate = new GPSCoordinate(0,0);
|
|
||||||
this.endGPSCoordinate = new GPSCoordinate(0,0);
|
|
||||||
this.legNumber = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,4 +78,12 @@ public class Leg {
|
|||||||
public int getLegNumber() {
|
public int getLegNumber() {
|
||||||
return legNumber;
|
return legNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double calculateDistance() {
|
||||||
|
|
||||||
|
GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
|
calc.setStartingGeographicPoint(startGPSCoordinate.getLatitude(), startGPSCoordinate.getLongitude());
|
||||||
|
calc.setDestinationGeographicPoint(endGPSCoordinate.getLatitude(), endGPSCoordinate.getLongitude());
|
||||||
|
return calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ public abstract class Race implements Runnable {
|
|||||||
/**
|
/**
|
||||||
* Initailiser for Race
|
* Initailiser for Race
|
||||||
* @param boats Takes in an array of boats that are participating in the race.
|
* @param boats Takes in an array of boats that are participating in the race.
|
||||||
* @param marks Number of marks in order that the boats pass in order to complete the race.
|
* @param legs Number of marks in order that the boats pass in order to complete the race.
|
||||||
*/
|
*/
|
||||||
public Race(BoatInRace[] boats, ArrayList<Leg> marks, RaceController controller) {
|
public Race(BoatInRace[] boats, ArrayList<Leg> legs, RaceController controller) {
|
||||||
this.startingBoats = boats;
|
this.startingBoats = boats;
|
||||||
this.legs = marks;
|
this.legs = legs;
|
||||||
this.legs.add(new Leg("Finish"));
|
this.legs.add(new Leg("Finish"));
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
|
import com.sun.xml.internal.bind.v2.runtime.reflect.opt.Const;
|
||||||
import javafx.scene.canvas.Canvas;
|
import javafx.scene.canvas.Canvas;
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.paint.Paint;
|
import javafx.scene.paint.Paint;
|
||||||
import javafx.scene.transform.Rotate;
|
import javafx.scene.transform.Rotate;
|
||||||
|
import seng302.Constants;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
import seng302.GraphCoordinate;
|
import seng302.GraphCoordinate;
|
||||||
import seng302.RaceMap;
|
import seng302.RaceMap;
|
||||||
@@ -92,17 +94,17 @@ public class ResizableRaceCanvas extends Canvas {
|
|||||||
GraphCoordinate finishLineCoord2 = this.map.convertGPS(32.317257, -64.836260);
|
GraphCoordinate finishLineCoord2 = this.map.convertGPS(32.317257, -64.836260);
|
||||||
displayLine(finishLineCoord1, finishLineCoord2, Color.DARKRED);
|
displayLine(finishLineCoord1, finishLineCoord2, Color.DARKRED);
|
||||||
//marks
|
//marks
|
||||||
GraphCoordinate markCoord = this.map.convertGPS(32.293039, -64.843983);
|
GraphCoordinate markCoord = this.map.convertGPS(Constants.mark1);
|
||||||
GraphCoordinate southGate1 = this.map.convertGPS(32.284680, -64.850045);
|
GraphCoordinate windwardGate1 = this.map.convertGPS(Constants.windwardGate1);
|
||||||
GraphCoordinate southGate2 = this.map.convertGPS(32.280164, -64.847591);
|
GraphCoordinate windwardGate2 = this.map.convertGPS(Constants.windwardGate2);
|
||||||
GraphCoordinate northGate1 = this.map.convertGPS(32.309693, -64.835249);
|
GraphCoordinate leewardGate1 = this.map.convertGPS(Constants.leewardGate1);
|
||||||
GraphCoordinate northGate2 = this.map.convertGPS(32.308046, -64.831785);
|
GraphCoordinate leewardGate2 = this.map.convertGPS(Constants.leewardGate2);
|
||||||
displayMark(markCoord, Color.GOLD);
|
displayMark(markCoord, Color.GOLD);
|
||||||
displayLine(southGate1, southGate2, Color.DARKCYAN);
|
displayLine(windwardGate1, windwardGate2, Color.DARKCYAN);
|
||||||
displayLine(northGate1, northGate2, Color.DARKVIOLET);
|
displayLine(leewardGate1, leewardGate2, Color.DARKVIOLET);
|
||||||
//start line
|
//start line
|
||||||
GraphCoordinate startline1 = this.map.convertGPS(32.296577, -64.854304);
|
GraphCoordinate startline1 = this.map.convertGPS(Constants.startLineMarker1);
|
||||||
GraphCoordinate startline2 = this.map.convertGPS(32.293771, -64.855242);
|
GraphCoordinate startline2 = this.map.convertGPS(Constants.startLineMarker2);
|
||||||
|
|
||||||
displayLine(startline1, startline2, Color.GREEN);
|
displayLine(startline1, startline2, Color.GREEN);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ package seng302.Model;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by esa46 on 16/03/17.
|
* Created by esa46 on 16/03/17.
|
||||||
*/
|
*/
|
||||||
@@ -12,7 +14,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, 18520, 90).getLatitude());
|
System.out.println(ConstantVelocityRace.calculatePosition(oldPos, 5, 0).getLatitude());
|
||||||
System.out.println(ConstantVelocityRace.calculatePosition(oldPos, 18520, 90).getLongitude());
|
// assertEquals(ConstantVelocityRace.calculatePosition(oldPos, 5, 90).getLatitude(), 0.08, 1e-1);
|
||||||
|
System.out.println(ConstantVelocityRace.calculatePosition(oldPos, 5, 0).getLongitude());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class RaceTest {
|
|||||||
BoatInRace boat = new BoatInRace("NZ", 240);
|
BoatInRace boat = new BoatInRace("NZ", 240);
|
||||||
BoatInRace[] boats = new BoatInRace[] {boat};
|
BoatInRace[] boats = new BoatInRace[] {boat};
|
||||||
ArrayList<Leg> legs = new ArrayList<>();
|
ArrayList<Leg> legs = new ArrayList<>();
|
||||||
legs.add(new Leg("Start", 1, new GPSCoordinate(0,0), new GPSCoordinate(1,1), 0));
|
legs.add(new Leg("Start", new GPSCoordinate(0,0), new GPSCoordinate(1,1), 0));
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs);
|
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs);
|
||||||
race.run();
|
race.run();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user