|
|
|
|
@ -521,16 +521,40 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|
|
|
|
*/
|
|
|
|
|
public void drawRaceLine(){
|
|
|
|
|
List<Leg> legs = this.visualiserRace.getLegs();
|
|
|
|
|
GPSCoordinate legStartPoint = legs.get(0).getStartCompoundMark().getAverageGPSCoordinate();
|
|
|
|
|
GPSCoordinate nextStartPoint;
|
|
|
|
|
for (int i = 0; i < legs.size() -1; i++) {
|
|
|
|
|
drawLineRounding(legs.get(i));
|
|
|
|
|
nextStartPoint = drawLineRounding(legs, i, legStartPoint);
|
|
|
|
|
legStartPoint = nextStartPoint;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void drawLineRounding(Leg leg){
|
|
|
|
|
//finds the direction of the leg as a bearing
|
|
|
|
|
GPSCoordinate startDirectionLinePoint = leg.getStartCompoundMark().getAverageGPSCoordinate();
|
|
|
|
|
GPSCoordinate endDirectionLinePoint = leg.getEndCompoundMark().getAverageGPSCoordinate();
|
|
|
|
|
Bearing bearingOfDirectionLine = GPSCoordinate.calculateBearing(startDirectionLinePoint, endDirectionLinePoint);
|
|
|
|
|
/**
|
|
|
|
|
* Draws a line around a course that shows where boats need to go. This method
|
|
|
|
|
* draws the line leg by leg
|
|
|
|
|
* @param legs the legs of a race
|
|
|
|
|
* @param index the index of the current leg to use
|
|
|
|
|
* @return the end point of the current leg that has been drawn
|
|
|
|
|
*/
|
|
|
|
|
private GPSCoordinate drawLineRounding(List<Leg> legs, int index, GPSCoordinate legStartPoint){
|
|
|
|
|
GPSCoordinate startDirectionLinePoint;
|
|
|
|
|
GPSCoordinate endDirectionLinePoint;
|
|
|
|
|
Bearing bearingOfDirectionLine;
|
|
|
|
|
|
|
|
|
|
GPSCoordinate startNextDirectionLinePoint;
|
|
|
|
|
GPSCoordinate endNextDirectionLinePoint;
|
|
|
|
|
Bearing bearingOfNextDirectionLine;
|
|
|
|
|
|
|
|
|
|
//finds the direction of the current leg as a bearing
|
|
|
|
|
startDirectionLinePoint = legStartPoint;
|
|
|
|
|
endDirectionLinePoint = legs.get(index).getEndCompoundMark().getMark1Position();
|
|
|
|
|
bearingOfDirectionLine = GPSCoordinate.calculateBearing(startDirectionLinePoint, endDirectionLinePoint);
|
|
|
|
|
|
|
|
|
|
//finds the direction of the next leg as a bearing
|
|
|
|
|
if (index < legs.size() -2){ // not last leg
|
|
|
|
|
startNextDirectionLinePoint = legs.get(index + 1).getStartCompoundMark().getMark1Position();
|
|
|
|
|
endNextDirectionLinePoint = legs.get(index + 1).getEndCompoundMark().getMark1Position();
|
|
|
|
|
bearingOfNextDirectionLine = GPSCoordinate.calculateBearing(startNextDirectionLinePoint, endNextDirectionLinePoint);
|
|
|
|
|
|
|
|
|
|
//use the direction line to find a point parallel to it by the mark
|
|
|
|
|
GPSCoordinate pointToStartCurve = GPSCoordinate.calculateNewPosition(endDirectionLinePoint,
|
|
|
|
|
@ -538,18 +562,18 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|
|
|
|
|
|
|
|
|
//use the direction line to find a point to curve too
|
|
|
|
|
GPSCoordinate pointToEndCurve = GPSCoordinate.calculateNewPosition(endDirectionLinePoint,
|
|
|
|
|
150, Azimuth.fromDegrees(bearingOfDirectionLine.degrees()));
|
|
|
|
|
150, Azimuth.fromDegrees(bearingOfNextDirectionLine.degrees()+90));
|
|
|
|
|
|
|
|
|
|
//use the curve points to find the two control points for the bezier curve
|
|
|
|
|
Bearing bearingOfCurveLine = GPSCoordinate.calculateBearing(pointToStartCurve, pointToEndCurve);
|
|
|
|
|
GPSCoordinate controlPoint1 = GPSCoordinate.calculateNewPosition(pointToStartCurve,
|
|
|
|
|
150, Azimuth.fromDegrees(bearingOfCurveLine.degrees()+ 50));
|
|
|
|
|
GPSCoordinate controlPoint = GPSCoordinate.calculateNewPosition(pointToStartCurve,
|
|
|
|
|
75, Azimuth.fromDegrees(bearingOfCurveLine.degrees()+ 50));
|
|
|
|
|
|
|
|
|
|
//change all gps into graph coordinate
|
|
|
|
|
GraphCoordinate startPath = this.map.convertGPS(startDirectionLinePoint);
|
|
|
|
|
GraphCoordinate curvePoint = this.map.convertGPS(pointToStartCurve);
|
|
|
|
|
GraphCoordinate curvePointEnd = this.map.convertGPS(pointToEndCurve);
|
|
|
|
|
GraphCoordinate c1 = this.map.convertGPS(controlPoint1);
|
|
|
|
|
GraphCoordinate c1 = this.map.convertGPS(controlPoint);
|
|
|
|
|
|
|
|
|
|
gc.setStroke(Color.RED);
|
|
|
|
|
gc.setLineWidth(1);
|
|
|
|
|
@ -562,7 +586,22 @@ public class ResizableRaceCanvas extends ResizableCanvas {
|
|
|
|
|
gc.closePath();
|
|
|
|
|
gc.save();
|
|
|
|
|
|
|
|
|
|
drawArrowHead(controlPoint1, pointToEndCurve);
|
|
|
|
|
drawArrowHead(controlPoint, pointToEndCurve);
|
|
|
|
|
|
|
|
|
|
return pointToEndCurve;
|
|
|
|
|
}else{//last leg so no curve
|
|
|
|
|
GraphCoordinate startPath = this.map.convertGPS(legStartPoint);
|
|
|
|
|
GraphCoordinate endPath = this.map.convertGPS(legs.get(index).getEndCompoundMark().getAverageGPSCoordinate());
|
|
|
|
|
|
|
|
|
|
gc.beginPath();
|
|
|
|
|
gc.moveTo(startPath.getX(), startPath.getY());
|
|
|
|
|
gc.lineTo(endPath.getX(), endPath.getY());
|
|
|
|
|
gc.stroke();
|
|
|
|
|
gc.closePath();
|
|
|
|
|
gc.save();
|
|
|
|
|
drawArrowHead(legStartPoint, legs.get(index).getEndCompoundMark().getAverageGPSCoordinate());
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void drawArrowHead(GPSCoordinate start, GPSCoordinate end){
|
|
|
|
|
|