Changeset 30836 in osm for applications/editors/josm


Ignore:
Timestamp:
2014-12-09T18:44:44+01:00 (10 years ago)
Author:
akks
Message:

[josm-NanoLog] update after core changes

Location:
applications/editors/josm/plugins/NanoLog
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/NanoLog/src/nanolog/Correlator.java

    r30737 r30836  
    234234                                EastNorth c2 = Main.getProjection().latlon2eastNorth(curWp.getCoor());
    235235                                if( !c1.equals(c2) ) {
    236                                     EastNorth middle = Geometry.getSegmentAltituteIntersection(c1, c2, en);
     236                                    EastNorth middle = getSegmentAltitudeIntersection(c1, c2, en);
    237237                                    if( middle != null && en.distance(middle) < 1 ) {
    238238                                        // found our point, no further search is neccessary
     
    264264        return 0;
    265265    }
     266
     267    /**
     268     * Returns the coordinate of intersection of segment p1-p2 and an altitude
     269     * to it starting at point p. If the line defined with p1-p2 intersects
     270     * its altitude out of p1-p2, null is returned.
     271     * @param p1
     272     * @param p2
     273     * @param point
     274     * @return Intersection coordinate or null
     275     **/
     276     public static EastNorth getSegmentAltitudeIntersection(EastNorth p1, EastNorth p2, EastNorth point) {
     277        double ldx = p2.getX() - p1.getX();
     278        double ldy = p2.getY() - p1.getY();
     279
     280        if (ldx == 0 && ldy == 0) //segment zero length
     281            return p1;
     282
     283        double pdx = point.getX() - p1.getX();
     284        double pdy = point.getY() - p1.getY();
     285
     286        double offset = (pdx * ldx + pdy * ldy) / (ldx * ldx + ldy * ldy);
     287
     288        if (offset < -1e-8 || offset > 1+1e-8) return null;
     289        if (offset < 1e-8)
     290            return p1;
     291        else if (offset > 1-1e-8)
     292            return p2;
     293        else
     294            return new EastNorth(p1.getX() + ldx * offset, p1.getY() + ldy * offset);
     295     }
     296
    266297}
Note: See TracChangeset for help on using the changeset viewer.