Modify

Opened 8 years ago

Closed 8 years ago

#6541 closed defect (fixed)

[patch] bugfix in coordinate heading function

Reported by: anonymous Owned by: team
Priority: normal Milestone:
Component: Core Version: latest
Keywords: heading atan2 Cc:

Description

This fixes three bugs in LatLon.heading(LatLon other) .

  • The case of (d_lon==0) and (d_lat<0) was treated wrong. Instead of yielding pi which would smoothly bridge the neighbouring values, a value of 0 was returned in this special case. The usage of atan2 helps a lot in avoiding such problems.
  • The transition from 359° to 1° was not treated properly. Instead of 2° it would have assumed -358° for the horizontal distance which gives an unexpected heading.
  • a cosine factor was introduced to the difference of longitudes to account for the convercenge of meridians towards the pole. Please check if this functionality is exactly what calling functions expect!

Attachments (1)

heading.patch (1.4 KB) - added by anonymous 8 years ago.

Download all attachments as: .zip

Change History (6)

Changed 8 years ago by anonymous

Attachment: heading.patch added

comment:1 Changed 8 years ago by stoecker

Summary: bugfix in coordinate heading function[patch] bugfix in coordinate heading function

comment:2 Changed 8 years ago by bastiK

I remember, we had to introduce http://trac.openstreetmap.org/browser/applications/editors/josm/plugins/simplifyarea/src/sk/zdila/josm/plugin/simplify/SimplifyAreaAction.java#L435 because LatLon.heading was too inaccurate.

In particular: If you have 3 points a, b and c, then heading(b,a) - heading(c,b) should be the angle. With LatLon.heading, this angle varies a lot, when you rotate the 3 points. With SimplifyAreaAction.heading it should be constant when rotating.

Maybe we can just replace LatLon.heading by the version from simplifyarea?

comment:3 in reply to:  2 ; Changed 8 years ago by anonymous

Replying to bastiK:

Thanks for the link! I understand that the angle with the old LatLon.heading function must have varied a lot, since the longitude values were distorted by a factor of cos(latitude). My proposed version should be a correct linearisation which might yield reasonable results if max(delta_lat, delta_lon) << |90° - |lat| |.

The version from SimplifyAreaAction - although I don't see completely through it - seems to come from proper spherical geometry using great_circle arcs and therefore yielding exact results without any approximation. This is of course superior to my proposed linearised version and therefore LatLon.heading should be replaced by the version from simplifyarea.

I would be happy to see a short comment in the function about which consideration led to the formula.

comment:4 in reply to:  3 Changed 8 years ago by bastiK

Replying to anonymous:

I would be happy to see a short comment in the function about which consideration led to the formula.

A lot of sin & cos ... looks legit. :)

comment:5 Changed 8 years ago by bastiK

Resolution: fixed
Status: newclosed

In [4206] - change heading formula to something sane.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.