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
main
Erika Savell 9 years ago
parent 2811a09784
commit 1284cac68e

@ -25,7 +25,7 @@
</list>
</option>
</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" />
</component>
<component name="SvnConfiguration">

@ -8,11 +8,6 @@
<name>app</name>
<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>
<dependency>
<groupId>junit</groupId>
@ -20,8 +15,40 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-referencing</artifactId>
<version>9.0</version>
</dependency>
</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>
<plugins>
<plugin>

@ -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();
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());
}

@ -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());
}
}

Loading…
Cancel
Save