Changeset 10001 in josm for trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
- Timestamp:
- 2016-03-17T01:50:12+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r9854 r10001 240 240 241 241 /** 242 * Makes a WayPoint at the projection of point Ponto the track providingPis less than242 * Makes a WayPoint at the projection of point p onto the track providing p is less than 243 243 * tolerance away from the track 244 244 * 245 * @param P: the point to determine the projection for245 * @param p : the point to determine the projection for 246 246 * @param tolerance : must be no further than this from the track 247 * @return the closest point on the track to P, which may be the first or last point if off the247 * @return the closest point on the track to p, which may be the first or last point if off the 248 248 * end of a segment, or may be null if nothing close enough 249 249 */ 250 public WayPoint nearestPointOnTrack(EastNorth P, double tolerance) {250 public WayPoint nearestPointOnTrack(EastNorth p, double tolerance) { 251 251 /* 252 252 * assume the coordinates of P are xp,yp, and those of a section of track between two … … 272 272 */ 273 273 274 double PNminsq = tolerance * tolerance;274 double pnminsq = tolerance * tolerance; 275 275 EastNorth bestEN = null; 276 276 double bestTime = 0.0; 277 double px = P.east();278 double py = P.north();277 double px = p.east(); 278 double py = p.north(); 279 279 double rx = 0.0, ry = 0.0, sx, sy, x, y; 280 280 if (tracks == null) … … 282 282 for (GpxTrack track : tracks) { 283 283 for (GpxTrackSegment seg : track.getSegments()) { 284 WayPoint R= null;284 WayPoint r = null; 285 285 for (WayPoint S : seg.getWayPoints()) { 286 EastNorth c= S.getEastNorth();287 if ( R== null) {288 R= S;289 rx = c.east();290 ry = c.north();286 EastNorth en = S.getEastNorth(); 287 if (r == null) { 288 r = S; 289 rx = en.east(); 290 ry = en.north(); 291 291 x = px - rx; 292 292 y = py - ry; 293 double PRsq = x * x + y * y;294 if ( PRsq < PNminsq) {295 PNminsq =PRsq;296 bestEN = c;297 bestTime = R.time;293 double pRsq = x * x + y * y; 294 if (pRsq < pnminsq) { 295 pnminsq = pRsq; 296 bestEN = en; 297 bestTime = r.time; 298 298 } 299 299 } else { 300 sx = c.east();301 sy = c.north();302 double A= sy - ry;303 double B= rx - sx;304 double C = -A* rx -B* ry;305 double RSsq = A * A + B * B;306 if ( RSsq == 0) {300 sx = en.east(); 301 sy = en.north(); 302 double a = sy - ry; 303 double b = rx - sx; 304 double c = -a * rx - b * ry; 305 double rssq = a * a + b * b; 306 if (rssq == 0) { 307 307 continue; 308 308 } 309 double PNsq = A* px +B* py +C;310 PNsq = PNsq * PNsq / RSsq;311 if ( PNsq < PNminsq) {309 double pnsq = a * px + b * py + c; 310 pnsq = pnsq * pnsq / rssq; 311 if (pnsq < pnminsq) { 312 312 x = px - rx; 313 313 y = py - ry; 314 double PRsq = x * x + y * y;314 double prsq = x * x + y * y; 315 315 x = px - sx; 316 316 y = py - sy; 317 double PSsq = x * x + y * y;318 if ( PRsq - PNsq <= RSsq && PSsq - PNsq <= RSsq) {319 double RNoverRS = Math.sqrt((PRsq - PNsq) / RSsq);320 double nx = rx - RNoverRS *B;321 double ny = ry + RNoverRS *A;317 double pssq = x * x + y * y; 318 if (prsq - pnsq <= rssq && pssq - pnsq <= rssq) { 319 double rnoverRS = Math.sqrt((prsq - pnsq) / rssq); 320 double nx = rx - rnoverRS * b; 321 double ny = ry + rnoverRS * a; 322 322 bestEN = new EastNorth(nx, ny); 323 bestTime = R.time +RNoverRS * (S.time -R.time);324 PNminsq =PNsq;323 bestTime = r.time + rnoverRS * (S.time - r.time); 324 pnminsq = pnsq; 325 325 } 326 326 } 327 R= S;327 r = S; 328 328 rx = sx; 329 329 ry = sy; 330 330 } 331 331 } 332 if ( R!= null) {333 EastNorth c = R.getEastNorth();332 if (r != null) { 333 EastNorth c = r.getEastNorth(); 334 334 /* if there is only one point in the seg, it will do this twice, but no matter */ 335 335 rx = c.east(); … … 337 337 x = px - rx; 338 338 y = py - ry; 339 double PRsq = x * x + y * y;340 if ( PRsq < PNminsq) {341 PNminsq =PRsq;339 double prsq = x * x + y * y; 340 if (prsq < pnminsq) { 341 pnminsq = prsq; 342 342 bestEN = c; 343 bestTime = R.time;343 bestTime = r.time; 344 344 } 345 345 }
Note:
See TracChangeset
for help on using the changeset viewer.