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]

main
Erika 9 years ago
parent 05c7af4abf
commit 8ae540a6b9

@ -10,7 +10,6 @@
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="app" target="1.8" />
<module name="team-7" target="1.8" />
</bytecodeTargetLevel>
</component>

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="JavadocGenerationManager">
<option name="OUTPUT_DIRECTORY" />
<option name="OPTION_SCOPE" value="protected" />
@ -25,7 +28,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="SvnConfiguration">

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

@ -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());
}
}
Loading…
Cancel
Save