Started adding functionality to calculate yacht velocity from the wind speed and direction using polar tables. Also began writing tests to cover this functionality, as it can't currently be tested within the game itself.

#story[986]
This commit is contained in:
Alistair McIntyre
2017-07-20 14:30:13 +12:00
parent e317de7562
commit da7a34fc55
4 changed files with 80 additions and 9 deletions
+30 -4
View File
@@ -2,12 +2,12 @@ package seng302.models;
import static seng302.utilities.GeoUtility.getGeoCoordinate;
import javafx.scene.paint.Color;
import seng302.models.mark.Mark;
import seng302.controllers.RaceViewController;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Map;
import javafx.scene.paint.Color;
import seng302.controllers.RaceViewController;
import seng302.models.mark.Mark;
import seng302.utilities.GeoPoint;
/**
@@ -96,6 +96,32 @@ public class Yacht {
location = getGeoCoordinate(location, heading, metersCovered);
}
/**
* Adjusts the yachts velocity based on the wind direction and speed from the polar table.
*
* @param windDir current wind Direction TODO: 20/07/17 ajm412: (TWA or AWA, not 100% sure?)
* @param windSpd current wind Speed
*/
public void updateYachtVelocity(Double windDir, Double windSpd) {
Double closestSpd = PolarTable.getClosestMatch(windSpd);
Map<Double, Double> polarsFromClosestSpd = PolarTable.getPolarTable().get(closestSpd);
Double closest = 0d;
Double closest_key = 0d;
for (Double key : polarsFromClosestSpd.keySet()) {
Double difference = Math.abs(key - windDir);
if (difference <= closest) {
closest = difference;
closest_key = key;
}
}
// System.out.println("Closest angle " + closest_key);
// System.out.println("WindDir " + windDir);
velocity = polarsFromClosestSpd.get(closest_key);
}
public String getBoatType() {
return boatType;
}