Weather routing: Difference between revisions

m
edit docs
m (edit docs)
Line 52:
function getpolardata(filename)
 
Read a sailing polar CSV file and return a SailingPolar containgcontaining the file data.
 
A sailing polar file is a CSV file, with ';' used as the comma separator instead of a comma.
Line 160:
sailingspeed(sp::SailingPolar, azimuth, dir, ws)
 
Calculate the expected net boat speed in a desired direction versus the wind (azimuth).
This is generally different from the actual boat speed in its actual direction.
Directions are in degrees (dirpointos is windpoint direction)of sail, velocitythe ofship direction from wind (ws) is in knots.,
and velocity of wind (ws) is in knots.
"""
sailingspeed(sp, azimuth, dirpointos, ws) = boatspeed(sp, dirpointos, ws) * cosd(abs(dirpointos - azimuth))
 
 
Line 177 ⟶ 178:
"""
function bestvectorspeed(sp::SailingPolar, dirtravel, dirwind, windspeed, dircur, velcur)
pointofsailazimuth = (dirtravel - dirwind) % 360.0
pointofsailazimuth = pointofsailazimuth < 0 ? pointofsailazimuth + 360.0 : pointofsailazimuth
pointofsailazimuth = pointofsailazimuth > 180.0 ? 360.0 - pointofsailazimuth : pointofsailazimuth
VMG = boatspeed(sp, pointofsailazimuth, windspeed)
other, idx = findmax([sailingspeed(sp, pointofsailazimuth, x, windspeed) for x in sp.degrees])
if other > VMG
pointofsailazimuth = sp.degrees[idx]
VMG = other
end
dirchosen = deg2rad(dirwind + pointofsailazimuth)
wx, wy = VMG * sin(dirchosen), VMG * cos(dirchosen)
curx, cury = velcur * sin(deg2rad(dircur)), velcur * cos(deg2rad(dircur))
Line 201 ⟶ 202:
distance, dir = haversine(lat1, lon1, lat2, lon2)
dir2, vel = bestvectorspeed(sp, dir, p.winddeg, p.windkts, p.currentdeg, p.currentkts)
endlat2, endlon2 = inverse_haversine(lat1, lon1, distance, dir2)
# minutes/s * m / (knots * (m/s / knot)) = minutes
return (1 / 60) * distance / (vel * 1.94384)
4,105

edits