seg.p1 = it.getSegmentEnd(); double segDistance = seg.distance(inputPt); double segFrac = seg.segmentFraction(inputPt);
/** * Project the point (fixedLon, fixedLat) onto the line segment from (fixedLon0, fixedLat0) to * (fixedLon1, fixedLat1) and return the fractional distance of the projected location along the segment as a * double in the range [0, 1]. All coordinates are fixed-precision geographic. * Pass in the cosine of the latitude to avoid repeatedly performing the expensive cosine operation. */ public static double segmentFraction(int fixedLon0, int fixedLat0, int fixedLon1, int fixedLat1, int fixedLon, int fixedLat, double cosLat) { // Adjust x scale to account for lines of longitude converging toward the poles. fixedLon0 = (int) (fixedLon0 / cosLat); fixedLon1 = (int) (fixedLon1 / cosLat); fixedLon = (int) (fixedLon / cosLat); LineSegment seg = new LineSegment(fixedLon0, fixedLat0, fixedLon1, fixedLat1); return seg.segmentFraction(new Coordinate(fixedLon, fixedLat)); }
/** * Project the point (fixedLon, fixedLat) onto the line segment from (fixedLon0, fixedLat0) to * (fixedLon1, fixedLat1) and return the fractional distance of the projected location along the segment as a * double in the range [0, 1]. All coordinates are fixed-precision geographic. * Pass in the cosine of the latitude to avoid repeatedly performing the expensive cosine operation. */ public static double segmentFraction(int fixedLon0, int fixedLat0, int fixedLon1, int fixedLat1, int fixedLon, int fixedLat, double cosLat) { // Adjust x scale to account for lines of longitude converging toward the poles. fixedLon0 = (int) (fixedLon0 / cosLat); fixedLon1 = (int) (fixedLon1 / cosLat); fixedLon = (int) (fixedLon / cosLat); LineSegment seg = new LineSegment(fixedLon0, fixedLat0, fixedLon1, fixedLat1); return seg.segmentFraction(new Coordinate(fixedLon, fixedLat)); }
seg.p1 = it.getSegmentEnd(); double segDistance = seg.distance(inputPt); double segFrac = seg.segmentFraction(inputPt);