Switched bearing calculation from formula to using the geodectic calcultor -this abstracts a lot of the complexity -more accurate heading, and it is return as an azimuth rather than bearing making lat and long calculations easier #story[9]

This commit is contained in:
Erika
2017-03-19 13:09:49 +13:00
parent 05c7af4abf
commit 8ae540a6b9
6 changed files with 33 additions and 28 deletions
-2
View File
@@ -20,8 +20,6 @@ public class App extends Application
public static void main( String[] args )
{
launch(args);
}
@@ -12,6 +12,7 @@ import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.util.Callback;
import org.geotools.referencing.GeodeticCalculator;
import seng302.GPSCoordinate;
import seng302.Model.ResizableRaceCanvas;
import seng302.Model.*;
@@ -80,14 +81,25 @@ public class RaceController extends Controller{
canvasBase.getChildren().add(raceMap);
ArrayList<Leg> legs = new ArrayList<>();
legs.add(new Leg("Start", 10, new GPSCoordinate(32.296577, -64.854304), new GPSCoordinate(32.296576, -64.854304), 0));
legs.add(new Leg("Mark", 50, new GPSCoordinate(32.296577, -64.854304), new GPSCoordinate(32.308046, -64.831785), 1));
ArrayList<Leg> legs = bermudaCourseLegs();
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this);
(new Thread(race)).start();
}
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);
return legs;
}
}
+10 -3
View File
@@ -1,6 +1,7 @@
package seng302.Model;
import javafx.scene.paint.Color;
import org.geotools.referencing.GeodeticCalculator;
import seng302.GPSCoordinate;
@@ -68,9 +69,15 @@ public class BoatInRace extends Boat {
*/
public double calculateHeading(){
//to be changed to coordinates when used to match reality.
double thetaHat = Math.atan2((currentLeg.getEndGraphCoordinate().getLatitude() - currentLeg.getStartGraphCoordinate().getLongitude()),
(currentLeg.getEndGraphCoordinate().getLatitude() - currentLeg.getStartGraphCoordinate().getLongitude()));
return thetaHat >= 0 ? Math.toDegrees(thetaHat): Math.toDegrees(thetaHat + 2 * Math.PI);
GeodeticCalculator calc = new GeodeticCalculator();
calc.setStartingGeographicPoint(currentLeg.getStartGraphCoordinate().getLatitude(), currentLeg.getStartGraphCoordinate().getLongitude());
calc.setDestinationGeographicPoint(currentLeg.getEndGraphCoordinate().getLatitude(), currentLeg.getEndGraphCoordinate().getLongitude());
return calc.getAzimuth();
// double thetaHat = Math.atan2((currentLeg.getEndGraphCoordinate().getLatitude() - currentLeg.getStartGraphCoordinate().getLongitude()),
// (currentLeg.getEndGraphCoordinate().getLatitude() - currentLeg.getStartGraphCoordinate().getLongitude()));
// return thetaHat >= 0 ? Math.toDegrees(thetaHat): Math.toDegrees(thetaHat + 2 * Math.PI);
}
}
@@ -2,16 +2,13 @@ package seng302.Model;
import seng302.Controllers.RaceController;
import java.awt.*;
import java.awt.geom.Point2D;
import org.geotools.geometry.DirectPosition1D;
import org.geotools.referencing.GeodeticCalculator;
import seng302.GPSCoordinate;
import seng302.GraphCoordinate;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
/**
* Created by cbt24 on 6/03/17.
@@ -53,23 +50,12 @@ public class ConstantVelocityRace extends Race {
Point2D startPoint = new Point2D.Double(oldCoordinates.getLatitude(), oldCoordinates.getLongitude());
geodeticCalculator.setStartingGeographicPoint(startPoint);
heading = 1;
double azimuth = 180 - heading;
System.out.println(heading);
geodeticCalculator.setDirection(azimuth, distanceTravelled * 1852 );
geodeticCalculator.setDirection(heading, distanceTravelled * 1852);
Point2D endPoint = geodeticCalculator.getDestinationGeographicPoint();
return new GPSCoordinate(endPoint.getX(), endPoint.getY());
}
}
}