Fixed x and y coordinates #fix #story[9]

This commit is contained in:
Michael Rausch
2017-03-20 21:13:30 +13:00
parent ed577fad6a
commit 3d4d5a3dab
2 changed files with 37 additions and 14 deletions
+6 -6
View File
@@ -4,31 +4,31 @@
<team> <team>
<name>Oracle Team USA</name> <name>Oracle Team USA</name>
<alias>USA</alias> <alias>USA</alias>
<velocity>23.4</velocity> <velocity>10.0</velocity>
</team> </team>
<team> <team>
<name>Artemis Racing</name> <name>Artemis Racing</name>
<alias>ART</alias> <alias>ART</alias>
<velocity>12.9</velocity> <velocity>10.0</velocity>
</team> </team>
<team> <team>
<name>Emirates Team New Zealand</name> <name>Emirates Team New Zealand</name>
<alias>NZL</alias> <alias>NZL</alias>
<velocity>25.2</velocity> <velocity>10.0</velocity>
</team> </team>
<team> <team>
<name>Land Rover BAR</name> <name>Land Rover BAR</name>
<alias>BAR</alias> <alias>BAR</alias>
<velocity>16.4</velocity> <velocity>10.0</velocity>
</team> </team>
<team> <team>
<name>SoftBank Team Japan</name> <name>SoftBank Team Japan</name>
<alias>JAP</alias> <alias>JAP</alias>
<velocity>19.22</velocity> <velocity>10.0</velocity>
</team> </team>
<team> <team>
<name>Groupama Team France</name> <name>Groupama Team France</name>
<alias>FRC</alias> <alias>FRC</alias>
<velocity>28.8</velocity> <velocity>10</velocity>
</team> </team>
</teams> </teams>
@@ -40,7 +40,7 @@ public class CanvasController {
public void initialize() { public void initialize() {
gc = canvas.getGraphicsContext2D(); gc = canvas.getGraphicsContext2D();
gc.scale(5, 5); gc.scale(22, 22);
RaceController raceController = new RaceController(); RaceController raceController = new RaceController();
raceController.initializeRace(); raceController.initializeRace();
race = raceController.getRace(); race = raceController.getRace();
@@ -53,6 +53,7 @@ public class CanvasController {
gc.clearRect(0, 0, 760, 360); gc.clearRect(0, 0, 760, 360);
drawCourse(); drawCourse();
drawBoats(); drawBoats();
} }
}; };
@@ -71,6 +72,7 @@ public class CanvasController {
*/ */
private void generateTimeline() { private void generateTimeline() {
HashMap<Boat, List> boat_events = race.getEvents(); HashMap<Boat, List> boat_events = race.getEvents();
for (Boat boat : boat_events.keySet()) { for (Boat boat : boat_events.keySet()) {
// x, y are the real time coordinates // x, y are the real time coordinates
DoubleProperty x = new SimpleDoubleProperty(); DoubleProperty x = new SimpleDoubleProperty();
@@ -103,6 +105,22 @@ public class CanvasController {
} }
} }
/**
* @return the distance between the two marks
*/
public double getDistanceBetweenMarks(Mark mark1, Mark mark2) {
double earth_radius = 6378.137;
double dLat = mark2.getLatitude() * Math.PI / 180 - mark1.getLatitude() * Math.PI / 180;
double dLon = mark2.getLongitude() * Math.PI / 180 - mark1.getLongitude() * Math.PI / 180;
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(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;
}
/** /**
* Draws a boat with given (x, y) position in the given color * Draws a boat with given (x, y) position in the given color
* *
@@ -110,11 +128,15 @@ public class CanvasController {
* @param y * @param y
* @param color * @param color
*/ */
private void drawBoat(double x, double y, Color color) { private void drawBoat(double lat, double lon, Color color) {
x = abs(x - 32.313291) * 1000; // to prevent negative longitude // Latitude
y = abs(y + 64.887057) * 1000; // to prevent negative latitude //Double x = (MAP_WIDTH / 360.0) * (180 + lon);
//Double y = (MAP_HEIGHT / 180.0) * (80 - lat);
int diameter = 2; double x = abs(lat - 32.283808) * 1000; // to prevent negative longitude
double y = abs(lon + 64.854401) * 1000; // to prevent negative latitude
double diameter = 0.5;
gc.setFill(color); gc.setFill(color);
gc.fillOval(x, y, diameter, diameter); gc.fillOval(x, y, diameter, diameter);
} }
@@ -138,10 +160,11 @@ public class CanvasController {
* @param singleMark * @param singleMark
*/ */
private void drawSingleMark(SingleMark singleMark) { private void drawSingleMark(SingleMark singleMark) {
double x = abs(singleMark.getLatitude() - 32.313291) * 1000; // to prevent negative longitude double x = abs(singleMark.getLatitude() - 32.283808) * 1000; // to prevent negative longitude
double y = abs(singleMark.getLongitude() + 64.887057) * 1000; // to prevent negative latitude double y = abs(singleMark.getLongitude() + 64.854401) * 1000; // to prevent negative latitude
gc.setFill(Color.BLACK); gc.setFill(Color.BLACK);
gc.fillOval(x, y, 2, 2); gc.fillOval(x, y, 0.5, 0.5);
} }
/** /**