diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index 8941f299..d01e8692 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -16,7 +16,7 @@ public class App extends Application primaryStage.setTitle("RaceVision"); primaryStage.setScene(new Scene(root)); - //OldApp.main(); // Run this to show how positions are updated + seng302.models.OldApp.main(); // Run this to show how positions are updated primaryStage.show(); } diff --git a/src/main/java/seng302/models/Event.java b/src/main/java/seng302/models/Event.java index a08405d7..bc462af8 100644 --- a/src/main/java/seng302/models/Event.java +++ b/src/main/java/seng302/models/Event.java @@ -114,7 +114,7 @@ public class Event { if (this.isFinishingEvent) { return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " finished the race"); } - + System.out.println(this.getDistanceBetweenMarks()); return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " passed " + this.mark1.getName() + " going heading " + this.getBoatHeading() + "°"); } @@ -122,7 +122,17 @@ public class Event { * @return the distance between the two marks */ public double getDistanceBetweenMarks(){ - return Math.sqrt(Math.pow(mark1.getLatitude()-mark2.getLatitude(), 2) + Math.pow(mark1.getLongitude()-mark2.getLongitude(), 2)); + //return Math.sqrt(Math.pow(mark1.getLatitude()-mark2.getLatitude(), 2) + Math.pow(mark1.getLongitude()-mark2.getLongitude(), 2)); + double earth_radius = 6378.137; + double dLat = this.mark2.getLatitude() * Math.PI / 180 - this.mark1.getLatitude() * Math.PI / 180; + double dLon = this.mark2.getLongitude() * Math.PI / 180 - this.mark1.getLongitude() * Math.PI / 180; + + double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(this.mark1.getLatitude() * Math.PI / 180) * Math.sin(dLon/2) * Math.sin(dLon/2); + + double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); + double d = earth_radius * c; + + return d * 1000; } /** diff --git a/src/test/java/seng302/EventTest.java b/src/test/java/seng302/EventTest.java index 9751695b..3beb51e6 100644 --- a/src/test/java/seng302/EventTest.java +++ b/src/test/java/seng302/EventTest.java @@ -33,6 +33,6 @@ public class EventTest { Boat boat = new Boat("testBoat"); Event event = new Event(1231242.2, boat, new Mark("mark1", 142.5, 122.1), new Mark("mark2", 121.9,99.2)); - assertEquals(event.getDistanceBetweenMarks(), 30.80211031731429, 1e-15); + assertEquals(event.getDistanceBetweenMarks(), 339059.653830461, 1e-15); } } \ No newline at end of file