Importing geotools library to calculate next coordinate for boat
-Currently getting ClassDefNotFound error - I think one of th elibraries dependencies is visible and compile time not runtime #story[9] #implement
This commit is contained in:
@@ -23,6 +23,8 @@ public class App extends Application
|
||||
|
||||
public static void main( String[] args )
|
||||
{
|
||||
|
||||
|
||||
launch(args);
|
||||
/* SPRINT 1 Leftovers
|
||||
int timescale = 0; // Scale 5 min to 1 min, 1min = 200 5 min = 1000
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package seng302.Model;
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Point2D;
|
||||
|
||||
import org.geotools.geometry.DirectPosition1D;
|
||||
import org.geotools.referencing.GeodeticCalculator;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.GraphCoordinate;
|
||||
|
||||
@@ -28,30 +34,29 @@ public class ConstantVelocityRace extends Race {
|
||||
double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg();
|
||||
|
||||
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
||||
boat.setCurrentPosition(calculate_position(boat.getCurrentLeg().getStartGraphCoordinate(),
|
||||
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartGraphCoordinate(),
|
||||
totalDistanceTravelled, boat.calculateHeading()));
|
||||
//Calculate new coordinates based on boat's heading for the leg, and distance traveled
|
||||
}
|
||||
|
||||
protected static GPSCoordinate calculate_position(GPSCoordinate oldCoordinates, double distanceTravelled, double heading) {
|
||||
public static GPSCoordinate calculatePosition(GPSCoordinate oldCoordinates, double distanceTravelled, double heading) {
|
||||
|
||||
//Find new coordinate using current heading and distance
|
||||
|
||||
double oldLatitude = oldCoordinates.getLatitude();
|
||||
GeodeticCalculator geodeticCalculator = new GeodeticCalculator();
|
||||
|
||||
double EARTH_RADIUS = 6371; //km
|
||||
double oldLongitude = oldCoordinates.getLongitude();
|
||||
double angularDistance = distanceTravelled / EARTH_RADIUS;
|
||||
Point2D startPoint = new Point2D.Double(oldCoordinates.getLatitude(), oldCoordinates.getLongitude());
|
||||
geodeticCalculator.setStartingGeographicPoint(startPoint);
|
||||
|
||||
double azimuth = heading - 180;
|
||||
geodeticCalculator.setDirection(azimuth, distanceTravelled);
|
||||
|
||||
|
||||
double newLatitude = Math.asin( Math.sin(oldLatitude)*Math.cos(angularDistance) +
|
||||
Math.cos(oldLatitude)*Math.sin(angularDistance)*Math.cos(heading) );
|
||||
double newLongitude = oldLongitude + Math.atan2(Math.sin(heading)*Math.sin(angularDistance)*Math.cos(oldLatitude),
|
||||
Math.cos(angularDistance)-Math.sin(oldLatitude)*Math.sin(newLatitude));
|
||||
|
||||
|
||||
return new GPSCoordinate(newLatitude, newLongitude);
|
||||
Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint();
|
||||
|
||||
return new GPSCoordinate(endPoint.getX(), endPoint.getY());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@ public abstract class Race {
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
||||
|
||||
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){
|
||||
@@ -83,6 +82,7 @@ public abstract class Race {
|
||||
finishingBoats.add(boat);
|
||||
} else {
|
||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
||||
|
||||
Leg nextLeg = legs[boat.getCurrentLeg().getLegNumber() + 1];
|
||||
boat.setCurrentLeg(nextLeg);
|
||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package seng302.Model;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
@@ -11,7 +12,7 @@ public class ConstantVelocityRaceTest {
|
||||
@Test
|
||||
public void travelling5nmNorthGivesCorrectNewCoordinates() {
|
||||
GPSCoordinate oldPos = new GPSCoordinate(0, 0);
|
||||
System.out.print(ConstantVelocityRace.calculate_position(oldPos, 1, 0).getLatitude());
|
||||
|
||||
System.out.println(ConstantVelocityRace.calculatePosition(oldPos, 18520, 90).getLatitude());
|
||||
System.out.println(ConstantVelocityRace.calculatePosition(oldPos, 18520, 90).getLongitude());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user