all paths now join up

#story[1087]
main
hba56 8 years ago
parent ef3f468b19
commit 22722286ef

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

Loading…
Cancel
Save