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:
Generated
+1
-1
@@ -25,7 +25,7 @@
|
|||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
<component name="SvnConfiguration">
|
<component name="SvnConfiguration">
|
||||||
|
|||||||
@@ -8,11 +8,6 @@
|
|||||||
<name>app</name>
|
<name>app</name>
|
||||||
<url>https://eng-git.canterbury.ac.nz/SENG302-2016/team-7</url>
|
<url>https://eng-git.canterbury.ac.nz/SENG302-2016/team-7</url>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
@@ -20,8 +15,40 @@
|
|||||||
<version>4.12</version>
|
<version>4.12</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.geotools</groupId>
|
||||||
|
<artifactId>gt-referencing</artifactId>
|
||||||
|
<version>9.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>maven2-repository.dev.java.net</id>
|
||||||
|
<name>Java.net repository</name>
|
||||||
|
<url>http://download.java.net/maven/2</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>osgeo</id>
|
||||||
|
<name>Open Source Geospatial Foundation Repository</name>
|
||||||
|
<url>http://download.osgeo.org/webdav/geotools/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
<id>opengeo</id>
|
||||||
|
<name>OpenGeo Maven Repository</name>
|
||||||
|
<url>http://repo.opengeo.org</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ public class App extends Application
|
|||||||
|
|
||||||
public static void main( String[] args )
|
public static void main( String[] args )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
launch(args);
|
launch(args);
|
||||||
/* SPRINT 1 Leftovers
|
/* SPRINT 1 Leftovers
|
||||||
int timescale = 0; // Scale 5 min to 1 min, 1min = 200 5 min = 1000
|
int timescale = 0; // Scale 5 min to 1 min, 1min = 200 5 min = 1000
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
package seng302.Model;
|
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.GPSCoordinate;
|
||||||
import seng302.GraphCoordinate;
|
import seng302.GraphCoordinate;
|
||||||
|
|
||||||
@@ -28,30 +34,29 @@ public class ConstantVelocityRace extends Race {
|
|||||||
double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg();
|
double totalDistanceTravelled = distanceTravelled + boat.getDistanceTravelledInLeg();
|
||||||
|
|
||||||
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
||||||
boat.setCurrentPosition(calculate_position(boat.getCurrentLeg().getStartGraphCoordinate(),
|
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartGraphCoordinate(),
|
||||||
totalDistanceTravelled, boat.calculateHeading()));
|
totalDistanceTravelled, boat.calculateHeading()));
|
||||||
//Calculate new coordinates based on boat's heading for the leg, and distance traveled
|
//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
|
//Find new coordinate using current heading and distance
|
||||||
|
|
||||||
double oldLatitude = oldCoordinates.getLatitude();
|
GeodeticCalculator geodeticCalculator = new GeodeticCalculator();
|
||||||
|
|
||||||
double EARTH_RADIUS = 6371; //km
|
Point2D startPoint = new Point2D.Double(oldCoordinates.getLatitude(), oldCoordinates.getLongitude());
|
||||||
double oldLongitude = oldCoordinates.getLongitude();
|
geodeticCalculator.setStartingGeographicPoint(startPoint);
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ public abstract class Race {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
protected void checkPosition(BoatInRace boat, long timeElapsed) {
|
||||||
|
|
||||||
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){
|
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){
|
||||||
@@ -83,6 +82,7 @@ public abstract class Race {
|
|||||||
finishingBoats.add(boat);
|
finishingBoats.add(boat);
|
||||||
} else {
|
} else {
|
||||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
||||||
|
|
||||||
Leg nextLeg = legs[boat.getCurrentLeg().getLegNumber() + 1];
|
Leg nextLeg = legs[boat.getCurrentLeg().getLegNumber() + 1];
|
||||||
boat.setCurrentLeg(nextLeg);
|
boat.setCurrentLeg(nextLeg);
|
||||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
|
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ 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.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