Index: src/org/openstreetmap/josm/tools/Geometry.java
===================================================================
--- src/org/openstreetmap/josm/tools/Geometry.java	(revision 7774)
+++ src/org/openstreetmap/josm/tools/Geometry.java	(working copy)
@@ -413,7 +413,7 @@
     public static EastNorth closestPointToLine(EastNorth lineP1, EastNorth lineP2, EastNorth point) {
         return closestPointTo(lineP1, lineP2, point, false);
     }
-
+    
     /**
      * This method tests if secondNode is clockwise to first node.
      *
@@ -826,40 +826,36 @@
     }
 
     /**
-     * Returns the coordinate of intersection of segment sp1-sp2 and an altitude
-     * to it starting at point ap. If the line defined with sp1-sp2 intersects
-     * its altitude out of sp1-sp2, null is returned.
+     * Returns the coordinate of intersection of segment p1-p2 and an altitude
+     * to it starting at point p. If the line defined with p1-p2 intersects
+     * its altitude out of p1-p2, null is returned.
      *
-     * @param sp1
-     * @param sp2
-     * @param ap
+     * @param p1
+     * @param p2
+     * @param point
      * @return Intersection coordinate or null
      */
-    public static EastNorth getSegmentAltituteIntersection(EastNorth sp1, EastNorth sp2, EastNorth ap) {
+    public static EastNorth getSegmentAltituteIntersection(EastNorth p1, EastNorth p2, EastNorth point) {
 
-        CheckParameterUtil.ensureValidCoordinates(sp1, "sp1");
-        CheckParameterUtil.ensureValidCoordinates(sp2, "sp2");
-        CheckParameterUtil.ensureValidCoordinates(ap, "ap");
+        CheckParameterUtil.ensureParameterNotNull(p1, "p1");
+        CheckParameterUtil.ensureParameterNotNull(p2, "p2");
+        CheckParameterUtil.ensureParameterNotNull(point, "point");
 
-        Double segmentLenght = sp1.distance(sp2);
-        Double altitudeAngle = getSegmentAngle(sp1, sp2) + Math.PI / 2;
+        double ldx = p2.getX() - p1.getX();
+        double ldy = p2.getY() - p1.getY();
 
-        // Taking a random point on the altitude line (angle is known).
-        EastNorth ap2 = new EastNorth(ap.east() + 1000
-                * Math.cos(altitudeAngle), ap.north() + 1000
-                * Math.sin(altitudeAngle));
+        if (ldx == 0 && ldy == 0) //segment zero length
+            return p1;
 
-        // Finding the intersection of two lines
-        EastNorth resultCandidate = Geometry.getLineLineIntersection(sp1, sp2,
-                ap, ap2);
+        double pdx = point.getX() - p1.getX();
+        double pdy = point.getY() - p1.getY();
 
-        // Filtering result
-        if (resultCandidate != null
-                && resultCandidate.distance(sp1) * .999 < segmentLenght
-                && resultCandidate.distance(sp2) * .999 < segmentLenght) {
-            return resultCandidate;
+        double offset = (pdx * ldx + pdy * ldy) / (ldx * ldx + ldy * ldy);
+
+        if (offset < -1e-8 || offset > 1e-8) {
+            return null;
         } else {
-            return null;
+            return new EastNorth(p1.getX() + ldx * offset, p1.getY() + ldy * offset);
         }
     }
 
