Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drift and set formulas are incorrect #116

Open
mgrouch opened this issue May 13, 2023 · 4 comments
Open

drift and set formulas are incorrect #116

mgrouch opened this issue May 13, 2023 · 4 comments

Comments

@mgrouch
Copy link

mgrouch commented May 13, 2023

Math.cos (courseOverGroundTrue-headingMagnetic)

Should be difference of either true or magnetic (can't mix both)

@mgrouch mgrouch changed the title drift and set formulas as incorrect drift and set formulas are incorrect May 13, 2023
@quantenschaum
Copy link

quantenschaum commented Feb 5, 2024

IMHO one should never use magnetic directions in any of the calculations. The only place the where magnetic stuff is involved is when converting a compass reading to true: true heading = compass heading + deviation + variation. If the compass is self-calibrating for deviation then deviation=0. That's it. From there one always use true directions. Saves a lot of headache. If you want to go back to magnetic for output purposes, you can always convert back after the actual calculation.

set/drift must not depend on magnetic variation!

How to calculate set and drift correctly?

SOG and COG follow this equation

(COG,SOG) = (set,drift) + (HDT+leeway,STW)

with (phi,r) being a vector in polar form and + denotes the sum of polar vectors. I would not actually calculate this sum that way. I would rather transform the vectors to cartesian space, add them, transform to polar space.

❗ The angle in the nautical system starts north and goes clockwise!

So you get

(set,drift) = (COG,SOG) - (HDT+leeway,STW)

with

  • COG/SOG - course and speed over ground from GPS
  • HDT - true heading from compass + variation
  • leeway - leeway angle, we can only estimate that based on wind speed and angle or set it to zero (set/drift will then yield a virtual current that causes leeway) see True wind with leeway. #5
  • STW - water speed from paddle wheel log

@quantenschaum
Copy link

Python version of addition of polar vectors

def add_polar(a, b):
    "sum of polar vectors (phi,r)"
    # to cartesian with phi going clock-wise from north
    a = a[1] * sin(radians(a[0])), a[1] * cos(radians(a[0]))
    b = b[1] * sin(radians(b[0])), b[1] * cos(radians(b[0]))
    # sum of cartesian vectors
    s = a[0] + b[0], a[1] + b[1]
    # back to polar with phi going clock-wise from north
    r = sqrt(s[0] ** 2 + s[1] ** 2)
    phi = (90 - degrees(atan2(s[1], s[0])) + 360) % 360
    return phi, r

@quantenschaum
Copy link

quantenschaum commented Feb 5, 2024

The output vales do not have any units associated with them in SignalK.

@quantenschaum
Copy link

for the calculations these formulas should be used

https://github.com/quantenschaum/mapping/blob/master/coursedata.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants