File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Heading/Bearing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Heading/Bearing" Watch "Heading/Bearing" New topic


Robert James Liguori
Ranch Hand

Joined: Nov 27, 2007
Posts: 550

I have two coordinates (original and new).

I need to get the bearing/heading from these two coordinates (e.g., NORTH, NORTHEAST, etc).

Can anyone point me in the right direction so I can code this up in Java. I'm using Math.atan2(), but am missing a bunch of logic.

Thanks, Robert

My Blog (I frequently post on Java, JSF and NetBeans)
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33098

How accurate do you need to be? If the answer is it needs to be one of north, south, east, west, northeast, northwest, southeast, southwest - it seems like this could be done without any trig.

If the x is smaller on the first one than the second, you know it is north, northeast or northwest. If the y is smaller, ....

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Heading/Bearing
It's not a secret anymore!