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.util.Callback;
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import seng302.Constants;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.Model.ResizableRaceCanvas;
|
||||
import seng302.Model.*;
|
||||
import seng302.RaceMap;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ResourceBundle;
|
||||
@@ -68,7 +70,7 @@ public class RaceController extends Controller{
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
||||
BoatInRace boat = new BoatInRace("NZ", 100);
|
||||
BoatInRace boat = new BoatInRace("NZ", 400);
|
||||
boat.setColour(Color.DARKVIOLET);
|
||||
boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||
BoatInRace[] boats = new BoatInRace[] {boat};
|
||||
@@ -90,14 +92,9 @@ public class RaceController extends Controller{
|
||||
private ArrayList<Leg> bermudaCourseLegs() {
|
||||
ArrayList<Leg> legs = new ArrayList<>();
|
||||
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
calc.setStartingGeographicPoint(32.296577, -64.854304);
|
||||
calc.setDestinationGeographicPoint(32.293039, -64.843983);
|
||||
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);
|
||||
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);
|
||||
legs.add(leg1); legs.add(leg2);
|
||||
return legs;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package seng302.Model;
|
||||
|
||||
import seng302.Constants;
|
||||
import seng302.Controllers.RaceController;
|
||||
|
||||
|
||||
@@ -36,13 +37,23 @@ public class ConstantVelocityRace extends Race {
|
||||
double distanceTravelled = boat.getVelocity() * millisecondsElapsed/3600000;
|
||||
double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg();
|
||||
|
||||
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
||||
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartGraphCoordinate(),
|
||||
totalDistanceTravelled, boat.calculateHeading()));
|
||||
if (!boat.getCurrentLeg().getName().equals("Finish")) {
|
||||
|
||||
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
|
||||
|
||||
@@ -51,7 +62,7 @@ public class ConstantVelocityRace extends Race {
|
||||
Point2D startPoint = new Point2D.Double(oldCoordinates.getLatitude(), oldCoordinates.getLongitude());
|
||||
geodeticCalculator.setStartingGeographicPoint(startPoint);
|
||||
|
||||
geodeticCalculator.setDirection(heading, distanceTravelled * 1852);
|
||||
geodeticCalculator.setDirection(azimuth, distanceTravelled * Constants.NMToMetersConversion);
|
||||
|
||||
Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint();
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package seng302.Model;
|
||||
|
||||
import org.geotools.referencing.Console;
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import seng302.Constants;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.GraphCoordinate;
|
||||
|
||||
@@ -18,22 +21,17 @@ public class Leg {
|
||||
/**
|
||||
* Leg Initialiser
|
||||
* @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.distance = distance;
|
||||
this.startGPSCoordinate = start;
|
||||
this.endGPSCoordinate = end;
|
||||
this.legNumber = number;
|
||||
this.distance = calculateDistance();
|
||||
}
|
||||
|
||||
public Leg(String 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() {
|
||||
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
|
||||
* @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.legs = marks;
|
||||
this.legs = legs;
|
||||
this.legs.add(new Leg("Finish"));
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package seng302.Model;
|
||||
|
||||
import com.sun.xml.internal.bind.v2.runtime.reflect.opt.Const;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Paint;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import seng302.Constants;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.GraphCoordinate;
|
||||
import seng302.RaceMap;
|
||||
@@ -92,17 +94,17 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
GraphCoordinate finishLineCoord2 = this.map.convertGPS(32.317257, -64.836260);
|
||||
displayLine(finishLineCoord1, finishLineCoord2, Color.DARKRED);
|
||||
//marks
|
||||
GraphCoordinate markCoord = this.map.convertGPS(32.293039, -64.843983);
|
||||
GraphCoordinate southGate1 = this.map.convertGPS(32.284680, -64.850045);
|
||||
GraphCoordinate southGate2 = this.map.convertGPS(32.280164, -64.847591);
|
||||
GraphCoordinate northGate1 = this.map.convertGPS(32.309693, -64.835249);
|
||||
GraphCoordinate northGate2 = this.map.convertGPS(32.308046, -64.831785);
|
||||
GraphCoordinate markCoord = this.map.convertGPS(Constants.mark1);
|
||||
GraphCoordinate windwardGate1 = this.map.convertGPS(Constants.windwardGate1);
|
||||
GraphCoordinate windwardGate2 = this.map.convertGPS(Constants.windwardGate2);
|
||||
GraphCoordinate leewardGate1 = this.map.convertGPS(Constants.leewardGate1);
|
||||
GraphCoordinate leewardGate2 = this.map.convertGPS(Constants.leewardGate2);
|
||||
displayMark(markCoord, Color.GOLD);
|
||||
displayLine(southGate1, southGate2, Color.DARKCYAN);
|
||||
displayLine(northGate1, northGate2, Color.DARKVIOLET);
|
||||
displayLine(windwardGate1, windwardGate2, Color.DARKCYAN);
|
||||
displayLine(leewardGate1, leewardGate2, Color.DARKVIOLET);
|
||||
//start line
|
||||
GraphCoordinate startline1 = this.map.convertGPS(32.296577, -64.854304);
|
||||
GraphCoordinate startline2 = this.map.convertGPS(32.293771, -64.855242);
|
||||
GraphCoordinate startline1 = this.map.convertGPS(Constants.startLineMarker1);
|
||||
GraphCoordinate startline2 = this.map.convertGPS(Constants.startLineMarker2);
|
||||
|
||||
displayLine(startline1, startline2, Color.GREEN);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user