SignalK / signalk-derived-data

Generates deltas for values derived from signalk values
Apache License 2.0
18 stars 30 forks source link

drift and set formulas are incorrect #116

Open mgrouch opened 1 year ago

mgrouch commented 1 year ago

Math.cos (courseOverGroundTrue-headingMagnetic)

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

quantenschaum commented 6 months ago

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.

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

So you get

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

with

quantenschaum commented 6 months ago

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 commented 6 months ago

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

quantenschaum commented 6 months ago

for the calculations these formulas should be used

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