Convert a bearing in degrees to compass point

Hello

I have a gps tracking system in a vehicle. It provides the position of the vehicle as a latitide and longitude coordinate using wgs84. Apparently the unit can provide a heading for the vehicle in degrees.

Firstly, how does it calculate the heading? I know you won't know for definite but you will probably have an intelligent idea. Perhaps it stores the previous gps position and then compares this to the current gps position and uses this to calculate a bearing?

Secondly, if I have a heading in degrees, how could i convert this into one of the 8 compass points from N, NE, E, SE, S, SW, W, NW

Many thanks
andiejeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jaime OlivaresSoftware ArchitectCommented:
>>Apparently the unit can provide a heading for the vehicle in degrees.
Every GPS can provide you the rhumb (it is not always the same as the heading, specially for air/sea vehicles), but calculating by yourself is not a trivial stuff, because GPS use to give inaccurate positions that causes false heading calculations. For this, there is an algorithm named "Kalman Filter" that eliminates the error by providing many samples as input to have a stable heading value as output.
Besides this, calculating compass coordinates is quiet easy. Which programming language?
0
andiejeAuthor Commented:
Hi

I dont know what a rhumb is. I looked it up on google but it doesnt seem to be possible to get a laymans explanation. However, I'm not sure I need to know exactly what it is but I would like to convert it to a compass bearing. I am using vb.net 2005.

Many thanks
0
Jaime OlivaresSoftware ArchitectCommented:
don't worry about rhumb versus heading, it should be the same for terrestrial applications. About compass algorithm, here is some implementation of my own:

Public Function Quadrant(ByVal degrees As Single) As String
    Dim AllQuadrants As String = "NNE,NE,NEE,E,SEE,SE,SSE,S,SSO,SO,SOO,O,NOO,NO,NNO"
    Dim Quadrants As String() = AllQuadrants.Split(","c)
   
    If degrees > 348.75 OrElse degrees <= 11.25 Then
        Return "N"
    End If
    Dim q As Integer = CInt(Math.Floor((degrees - 11.25) / 22.5))
    Return Quadrantes(q)
End Function
0
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

andiejeAuthor Commented:
Thats brilliant. However I only need the 8 compass points in my question. I don't know how to modify the code you have supplied to restrict it to just those compass points.

I could do something 'rough' like assigning the more detailed compass points to a more general one
e.g. if function returns NNE then convert it to NE but it would be nicer and easier to read if i could modif the function ou supplied
0
Jaime OlivaresSoftware ArchitectCommented:
ok, downgrading my function:

Public Function Quadrant(ByVal degrees As Single) As String
    Dim AllQuadrants As String = "NE,E,SE,S,SW,W,NW"
    Dim Quadrants As String() = AllQuadrants.Split(","c)
   
    If degrees > 337.5 OrElse degrees <= 22.5 Then
        Return "N"
    End If
    Dim q As Integer = CInt(Math.Floor((degrees - 22.5) / 45.0))
    Return Quadrantes(q)
End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andiejeAuthor Commented:
many thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
GIS/GPS Programming

From novice to tech pro — start learning today.