From 1284cac68ebc79c1acb9bd57cd600d13e6dc405c Mon Sep 17 00:00:00 2001 From: Erika Savell Date: Fri, 17 Mar 2017 13:03:27 +1300 Subject: [PATCH] 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 --- .idea/misc.xml | 2 +- pom.xml | 37 ++++++++++++++++--- src/main/java/seng302/App.java | 2 + .../seng302/Model/ConstantVelocityRace.java | 27 ++++++++------ src/main/java/seng302/Model/Race.java | 2 +- .../Model/ConstantVelocityRaceTest.java | 5 ++- 6 files changed, 55 insertions(+), 20 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 096e7479..5629a5af 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -25,7 +25,7 @@ - + diff --git a/pom.xml b/pom.xml index 69af7436..7daf513a 100644 --- a/pom.xml +++ b/pom.xml @@ -8,11 +8,6 @@ app https://eng-git.canterbury.ac.nz/SENG302-2016/team-7 - - 1.8 - 1.8 - - junit @@ -20,8 +15,40 @@ 4.12 test + + + org.geotools + gt-referencing + 9.0 + + + + maven2-repository.dev.java.net + Java.net repository + http://download.java.net/maven/2 + + + osgeo + Open Source Geospatial Foundation Repository + http://download.osgeo.org/webdav/geotools/ + + + + true + + opengeo + OpenGeo Maven Repository + http://repo.opengeo.org + + + + + 1.8 + 1.8 + + diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index 830d436a..6bc4fd3b 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -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 diff --git a/src/main/java/seng302/Model/ConstantVelocityRace.java b/src/main/java/seng302/Model/ConstantVelocityRace.java index ce312785..523b40a4 100644 --- a/src/main/java/seng302/Model/ConstantVelocityRace.java +++ b/src/main/java/seng302/Model/ConstantVelocityRace.java @@ -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(); + + Point2D startPoint = new Point2D.Double(oldCoordinates.getLatitude(), oldCoordinates.getLongitude()); + geodeticCalculator.setStartingGeographicPoint(startPoint); - double EARTH_RADIUS = 6371; //km - double oldLongitude = oldCoordinates.getLongitude(); - double angularDistance = distanceTravelled / EARTH_RADIUS; + 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()); } diff --git a/src/main/java/seng302/Model/Race.java b/src/main/java/seng302/Model/Race.java index df27f6f1..2cae90b9 100644 --- a/src/main/java/seng302/Model/Race.java +++ b/src/main/java/seng302/Model/Race.java @@ -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()); diff --git a/src/test/java/seng302/Model/ConstantVelocityRaceTest.java b/src/test/java/seng302/Model/ConstantVelocityRaceTest.java index 50f1c978..8701d988 100644 --- a/src/test/java/seng302/Model/ConstantVelocityRaceTest.java +++ b/src/test/java/seng302/Model/ConstantVelocityRaceTest.java @@ -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()); } }