Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Average bearing

  • 14-06-2006 1:27pm
    #1
    Registered Users, Registered Users 2 Posts: 7,541 ✭✭✭


    Heya, I'm trying to write a bit of code that calculates the average bearing (direction of travel) over a period of time. It does by determining the current bearing (in deg, ie North =0 deg, East = 90 deg, etc) and storing this, then at certain periods using the last three bearings stored to calc the average.

    Now obviously if the last three bearings recorded were 80,90 and 100, then the average is 90. No problem there. ;)

    But my problem is when the bearings are around 0 or 360 deg (north). If for example I have 350, 0 and 10 then the average bearing should be 0. But the maths gives 120.

    So how can I calculate average bearings when bearings are on either side of a full rotation?

    I hope this makes sense.

    R


Comments

  • Registered Users, Registered Users 2 Posts: 642 ✭✭✭red_fox


    I think if you calculate the differance between the first bearing and the second and third by setting the first to zero, so for the 350, 0, 10 you have you'd have

    350-350=0
    0-350=-350
    10-350=-340

    then get the sum of those modulo 360 so -690 = 30 and then one third of that is 10.

    Now add back the 350 you took away at the start for 360, and modulo 360 to get your zero.

    *Edit, I just realised that this method would cause problems in otherwise problem free situations and would need to be broken down into a number of cases (assuming that's even possible!) sorry!


  • Registered Users, Registered Users 2 Posts: 7,541 ✭✭✭irlrobins


    Thanks Red Fox.

    Actually did some thinking out of the box and realised that trying to find the average wind direction has the same problem and this through up more hits under google then looking for "average bearing".

    Eventually got this solution which works perfectly for me. Thanks anyway

    http://mathforum.org/library/drmath/view/53924.html


  • Registered Users, Registered Users 2 Posts: 642 ✭✭✭red_fox


    I would say that approach would be more computationally difficult as it involves sin, cos and tan^{-1}, but it will, of course, still work quite simply!


  • Registered Users, Registered Users 2 Posts: 7,541 ✭✭✭irlrobins


    Well compared to the rest of it, that's the easy part! ;)


Advertisement