Index: /trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/coor/LatLon.java	(revision 9795)
+++ /trunk/src/org/openstreetmap/josm/data/coor/LatLon.java	(revision 9796)
@@ -327,5 +327,9 @@
 
     /**
-     * Returns the heading, in radians, that you have to use to get from this lat/lon to another.
+     * Returns the heading that you have to use to get from this lat/lon to another.
+     *
+     * Angle starts from north and increases counterclockwise (!), PI/2 means west.
+     * You can get usual clockwise angle from {@link #bearing(LatLon)} method.
+     * This method is kept as deprecated because it is called from many plugins.
      *
      * (I don't know the original source of this formula, but see
@@ -333,7 +337,9 @@
      * for some hints how it is derived.)
      *
+     * @deprecated see bearing method
      * @param other the "destination" position
-     * @return heading in the range 0 &lt;= hd &lt; 2*PI
-     */
+     * @return heading in radians in the range 0 &lt;= hd &lt; 2*PI
+     */
+    @Deprecated
     public double heading(LatLon other) {
         double hd = atan2(sin(toRadians(this.lon() - other.lon())) * cos(toRadians(other.lat())),
@@ -348,4 +354,34 @@
 
     /**
+     * Returns bearing from this point to another.
+     *
+     * Angle starts from north and increases clockwise, PI/2 means east.
+     * Old deprecated method {@link #heading(LatLon)} used unusual reverse angle.
+     *
+     * Please note that reverse bearing (from other point to this point) should NOT be
+     * calculated from return value of this method, because great circle path
+     * between the two points have different bearings at each position.
+     *
+     * To get bearing from another point to this point call other.bearing(this)
+     *
+     * @param other the "destination" position
+     * @return heading in radians in the range 0 &lt;= hd &lt; 2*PI
+     */
+    public double bearing(LatLon other) {
+        double lat1 = toRadians(this.lat());
+        double lat2 = toRadians(other.lat());
+        double dlon = toRadians(other.lon() - this.lon());
+        double bearing = atan2(
+            sin(dlon) * cos(lat2),
+            cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dlon)
+        );
+        bearing %= 2 * PI;
+        if (bearing < 0) {
+            bearing += 2 * PI;
+        }
+        return bearing;
+    }
+
+    /**
      * Returns this lat/lon pair in human-readable format.
      *
Index: /trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java	(revision 9795)
+++ /trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java	(revision 9796)
@@ -89,8 +89,9 @@
     private static final int sl9 = 3;
     private static final int[][] dir = {
-        {+sl4, +ll0, +ll0, +sl4}, {-sl9, +ll0, +sl9, +ll0}, {-ll0, +sl4, -sl4, +ll0},
-        {-ll0, -sl9, -ll0, +sl9}, {-sl4, -ll0, -ll0, -sl4}, {+sl9, -ll0, -sl9, -ll0},
-        {+ll0, -sl4, +sl4, -ll0}, {+ll0, +sl9, +ll0, -sl9}, {+sl4, +ll0, +ll0, +sl4},
-        {-sl9, +ll0, +sl9, +ll0}, {-ll0, +sl4, -sl4, +ll0}, {-ll0, -sl9, -ll0, +sl9}};
+        {+sl4, +ll0, +ll0, +sl4}, {-sl9, +ll0, +sl9, +ll0},
+        {-ll0, +sl4, -sl4, +ll0}, {-ll0, -sl9, -ll0, +sl9},
+        {-sl4, -ll0, -ll0, -sl4}, {+sl9, -ll0, -sl9, -ll0},
+        {+ll0, -sl4, +sl4, -ll0}, {+ll0, +sl9, +ll0, -sl9}
+    };
 
     private void setupColors() {
@@ -333,5 +334,5 @@
                         break;
                     case DIRECTION:
-                        double dirColor = oldWp.getCoor().heading(trkPnt.getCoor());
+                        double dirColor = oldWp.getCoor().bearing(trkPnt.getCoor());
                         color = directionScale.getColor(dirColor);
                         break;
@@ -348,5 +349,6 @@
                     if (!noDraw && (maxLineLength == -1 || dist <= maxLineLength)) {
                         trkPnt.drawLine = true;
-                        trkPnt.dir = (int) oldWp.getCoor().heading(trkPnt.getCoor());
+                        double bearing = oldWp.getCoor().bearing(trkPnt.getCoor());
+                        trkPnt.dir = ((int) (bearing / Math.PI * 4 + 1.5)) % 8;
                     } else {
                         trkPnt.drawLine = false;
Index: /trunk/src/org/openstreetmap/josm/tools/ColorScale.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/tools/ColorScale.java	(revision 9795)
+++ /trunk/src/org/openstreetmap/josm/tools/ColorScale.java	(revision 9796)
@@ -45,5 +45,5 @@
         for (int i = 0; i < sc.colors.length; i++) {
 
-            float angle = 4 - i / 256f * 4;
+            float angle = i / 256f * 4;
             int quadrant = (int) angle;
             angle -= quadrant;
