updated the race class to set heading for windward legs
#story[873]
This commit is contained in:
@@ -14,6 +14,8 @@ public class Boat {
|
|||||||
private int sourceID;
|
private int sourceID;
|
||||||
private Leg currentLeg;
|
private Leg currentLeg;
|
||||||
private double distanceTravelledInLeg;
|
private double distanceTravelledInLeg;
|
||||||
|
private double distanceTravelledInTack;
|
||||||
|
private double distanceForTack;
|
||||||
private GPSCoordinate currentPosition;
|
private GPSCoordinate currentPosition;
|
||||||
private long timeFinished = -1;
|
private long timeFinished = -1;
|
||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
@@ -139,6 +141,22 @@ public class Boat {
|
|||||||
this.distanceTravelledInLeg = distanceTravelledInLeg;
|
this.distanceTravelledInLeg = distanceTravelledInLeg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getDistanceTravelledInTack() {
|
||||||
|
return distanceTravelledInTack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDistanceTravelledInTack(double distanceTravelledInTack) {
|
||||||
|
this.distanceTravelledInTack = distanceTravelledInTack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getDistanceForTack() {
|
||||||
|
return distanceForTack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDistanceForTack(double distanceForTack) {
|
||||||
|
this.distanceForTack = distanceForTack;
|
||||||
|
}
|
||||||
|
|
||||||
public GPSCoordinate getCurrentPosition() {
|
public GPSCoordinate getCurrentPosition() {
|
||||||
return currentPosition;
|
return currentPosition;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import static java.lang.Math.cos;
|
||||||
|
import static java.lang.Math.max;
|
||||||
|
import static java.lang.Math.min;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parent class for races
|
* Parent class for races
|
||||||
@@ -300,25 +304,57 @@ public class Race implements Runnable {
|
|||||||
|
|
||||||
boolean finish = boat.getCurrentLeg().getName().equals("Finish");
|
boolean finish = boat.getCurrentLeg().getName().equals("Finish");
|
||||||
if (!finish) {
|
if (!finish) {
|
||||||
if(!GPSCoordinate.isInsideBoundary(boat.getCurrentPosition(), this.boundary)){
|
int windAngle = 360;//todo - get the wind speed from somewhere, using 360 for now
|
||||||
//todo - find the acceptable values for direction
|
if(boat.getCurrentLeg().getName().endsWith("to Windward Gate")){//todo something is broken in this if statement, not sure what
|
||||||
} else{
|
double totalDistanceTravelledInTack = distanceTravelled + boat.getDistanceTravelledInTack();
|
||||||
VMG newHeading = boat.getPolars().calculateVMG(180, 30,
|
|
||||||
boat.calculateBearingToDestination());//todo - get the wind speed from somewhere
|
double bound1 = (boat.calculateBearingToDestination()-90)%360;
|
||||||
|
double bound2 = (boat.calculateBearingToDestination()+90)%360;
|
||||||
|
|
||||||
|
VMG newHeading = boat.getPolars().calculateVMG(windAngle, 30,
|
||||||
|
boat.calculateBearingToDestination(), min(bound1, bound2), max(bound1,bound2));
|
||||||
|
|
||||||
|
|
||||||
|
double azimuth = newHeading.bearing;
|
||||||
|
if (newHeading.bearing > 180){
|
||||||
|
azimuth = newHeading.bearing -360;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (!GPSCoordinate.isInsideBoundary(calculatePosition(boat.getCurrentPosition(),
|
||||||
|
// 1, azimuth), boundary)){
|
||||||
|
// System.out.println("LDFSGSDFG");
|
||||||
|
// double tempHeading = (newHeading.bearing+90)%360;
|
||||||
|
// newHeading.bearing = tempHeading;
|
||||||
|
// }
|
||||||
|
|
||||||
boat.setHeading(newHeading.bearing);
|
boat.setHeading(newHeading.bearing);
|
||||||
boat.setVelocity(newHeading.speed);
|
boat.setVelocity(newHeading.speed);
|
||||||
// boat.setHeading(boat.calculateHeading());
|
|
||||||
|
//calc the distance travelled in a straight line to windward
|
||||||
|
double angleBetweenDestAndHeading = newHeading.bearing - boat.calculateBearingToDestination();
|
||||||
|
totalDistanceTravelled = cos(angleBetweenDestAndHeading)*totalDistanceTravelledInTack;
|
||||||
|
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
||||||
|
|
||||||
|
//Calculate boat's new position by adding the distance travelled onto the start point of the leg
|
||||||
|
boat.setCurrentPosition(calculatePosition(boat.getCurrentPosition(),
|
||||||
|
totalDistanceTravelledInTack, azimuth));
|
||||||
|
|
||||||
|
}else{
|
||||||
|
boat.setHeading(boat.calculateHeading());
|
||||||
//update boat's distance travelled
|
//update boat's distance travelled
|
||||||
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
||||||
//Calculate boat's new position by adding the distance travelled onto the start point of the leg
|
//Calculate boat's new position by adding the distance travelled onto the start point of the leg
|
||||||
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartMarker().getAverageGPSCoordinate(),
|
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartMarker().getAverageGPSCoordinate(),
|
||||||
totalDistanceTravelled, boat.getHeading()));
|
totalDistanceTravelled, boat.calculateAzimuth(boat.getCurrentLeg().getStartMarker().getAverageGPSCoordinate(),
|
||||||
|
boat.getCurrentLeg().getEndMarker().getAverageGPSCoordinate())));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkPosition(Boat boat, long timeElapsed) {
|
protected void checkPosition(Boat boat, long timeElapsed) {
|
||||||
|
System.out.println(boat.getDistanceTravelledInLeg());
|
||||||
|
System.out.println(boat.getCurrentLeg().getDistance());
|
||||||
|
System.out.println(" ");
|
||||||
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()) {
|
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()) {
|
||||||
//boat has passed onto new leg
|
//boat has passed onto new leg
|
||||||
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
if (boat.getCurrentLeg().getName().equals("Finish")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user