public boolean inBuffer(GPXPoint p, double dmax) { GPXPoint s1; GPXPoint s2; for (int i = 1; i < points.size(); i++) { s1 = points.get(i - 1); s2 = points.get(i); try { double d = s1.distanceTo(s2); double d1 = s1.distanceTo(p); double d2 = s2.distanceTo(p); if (d1 < dmax || d2 < dmax) { return true; } // Al-Kashi // d2� = d� + d1� + 2*d*d1*cos a double cosa1 = (d2 * d2 - d * d - d1 * d1) / (-2.0 * d * d1); double a1 = Math.acos(cosa1); double cosa2 = (d1 * d1 - d * d - d2 * d2) / (-2.0 * d * d2); double a2 = Math.acos(cosa2); if (a1 < Math.PI / 1.9 && a2 < Math.PI / 1.9) { // sin a = d / d1 double dist = d1 * Math.sin(a1); if (dist < dmax) { return true; } } } catch (Throwable e) { } } return false; }
private void computePolygon() { polygon = new Polygon2D(); for (GPXPoint point : points) { polygon.addPoint((float) point.getLon(), (float) point.getLat()); } }
public boolean includes(GPXPoint p) { if (polygon == null) { computePolygon(); } return polygon.contains(p.getLon(), p.getLat()); }