From 2ac3b51109009bba18371c26801061582dc435ac Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Tue, 17 Jul 2012 17:11:58 +0200 Subject: [PATCH] fixing bug 865: VMG for reaching legs is now computed along leg direction --- .../impl/TrackedLegOfCompetitorImpl.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegOfCompetitorImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegOfCompetitorImpl.java index 0d4d9e98a43..0793d9f3940 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegOfCompetitorImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackedLegOfCompetitorImpl.java @@ -213,24 +213,30 @@ public class TrackedLegOfCompetitorImpl implements TrackedLegOfCompetitor { } /** - * Projects speed onto the wind direction to see how fast a boat travels - * "along the wind's direction." + * Projects speed onto the wind direction for upwind/downwind legs to see how fast a boat travels + * "along the wind's direction." For reaching legs (neither upwind nor downwind), the speed is projected onto + * the leg's direction. * * @throws NoWindException in case the wind direction is not known */ private SpeedWithBearing getWindwardSpeed(SpeedWithBearing speed, TimePoint at) throws NoWindException { SpeedWithBearing result = null; if (speed != null) { - Wind wind = getWind(getTrackedRace().getTrack(getCompetitor()).getEstimatedPosition(at, false), at); - if (wind == null) { - throw new NoWindException("Need at least wind direction to determine windward speed"); + Bearing projectToBearing; + if (getTrackedLeg().isUpOrDownwindLeg(at)) { + Wind wind = getWind(getTrackedRace().getTrack(getCompetitor()).getEstimatedPosition(at, false), at); + if (wind == null) { + throw new NoWindException("Need at least wind direction to determine windward speed"); + } + projectToBearing = wind.getBearing(); + } else { + projectToBearing = getTrackedLeg().getLegBearing(at); } - Bearing bearing = wind.getBearing(); - double cos = Math.cos(speed.getBearing().getRadians() - wind.getBearing().getRadians()); + double cos = Math.cos(speed.getBearing().getRadians() - projectToBearing.getRadians()); if (cos < 0) { - bearing = bearing.reverse(); + projectToBearing = projectToBearing.reverse(); } - result = new KnotSpeedWithBearingImpl(Math.abs(speed.getKnots() * cos), bearing); + result = new KnotSpeedWithBearingImpl(Math.abs(speed.getKnots() * cos), projectToBearing); } return result; }