Changeset 23480 in osm
- Timestamp:
- 2010-10-06T11:20:14+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/simplifyarea/src/sk/zdila/josm/plugin/simplify/SimplifyAreaAction.java
r23478 r23480 2 2 package sk.zdila.josm.plugin.simplify; 3 3 4 import static java.lang.Math.cos; 5 import static java.lang.Math.sin; 6 import static java.lang.Math.toRadians; 4 7 import static org.openstreetmap.josm.tools.I18n.tr; 5 8 import static org.openstreetmap.josm.tools.I18n.trn; … … 166 169 @SuppressWarnings("null") 167 170 private SequenceCommand simplifyWay(final Way w) { 168 final double angleThreshold = Double.parseDouble(Main.pref.get("simplify-area.angle", "10.0")); 169 final double distanceTreshold = Double.parseDouble(Main.pref.get("simplify-area.distance", "0.2")); 170 final double areaTreshold = Double.parseDouble(Main.pref.get("simplify-area.area", "5.0")); 171 final double angleThreshold = Main.pref.getDouble("simplify-area.angle", 10); 172 final double mergeThreshold = Main.pref.getDouble("simplify-area.merge", 0.2); 173 final double areaThreshold = Main.pref.getDouble("simplify-area.area", 5.0); 174 final double distanceThreshold = Main.pref.getDouble("simplify-area.dist", 3); 171 175 172 176 final List<Node> nodes = w.getNodes(); … … 203 207 final LatLon coord2 = n2.getCoor(); 204 208 205 if (isRequiredNode(w, n1) || isRequiredNode(w, n2) || coord1.greatCircleDistance(coord2) > distanceTreshold) {209 if (isRequiredNode(w, n1) || isRequiredNode(w, n2) || coord1.greatCircleDistance(coord2) > mergeThreshold) { 206 210 if (!closing) { 207 211 newNodes.add(n1); … … 229 233 230 234 if (coord1 != null) { 231 // System.out.print("AREA: " + computeArea(coord1, coord2, coord3) + "; ANGLE: " + computeConvectAngle(coord1, coord2, coord3)); 235 // System.out.print("AREA: " + computeArea(coord1, coord2, coord3) + "; ANGLE: " + computeConvectAngle(coord1, coord2, coord3) + "; XTE: "+crossTrackError(coord1, coord2, coord3)); 232 236 if (isRequiredNode(w, prevNode) || 233 237 !closed && i == len - 1 || // don't remove last node of the not closed way 234 238 computeConvectAngle(coord1, coord2, coord3) > angleThreshold || 235 computeArea(coord1, coord2, coord3) > areaTreshold) { 239 computeArea(coord1, coord2, coord3) > areaThreshold || 240 crossTrackError(coord1, coord2, coord3) > distanceThreshold) { 236 241 newNodes2.add(prevNode); 237 242 // System.out.println(" ... KEEP"); … … 272 277 273 278 274 public double computeConvectAngle(final LatLon coord1, final LatLon coord2, final LatLon coord3) { 275 final double angle = Math.abs(coord2.heading(coord3) - coord1.heading(coord2));276 return Math.toDegrees( angle < Math.PI ? angle : 2 * Math.PI - angle);279 public static double computeConvectAngle(final LatLon coord1, final LatLon coord2, final LatLon coord3) { 280 final double angle = heading(coord2, coord3) - heading(coord1, coord2); 281 return Math.toDegrees(Math.abs(angle_mPI_to_PI(angle))); 277 282 } 278 283 … … 288 293 return Math.sqrt(p * (p - a) * (p - b) * (p - c)); 289 294 } 290 295 296 public static double R = 6378135; 297 298 public static double crossTrackError(LatLon l1, LatLon l2, LatLon l3) { 299 return R*Math.asin(Math.sin(l1.greatCircleDistance(l2) / R) * Math.sin(heading(l1, l2) - heading(l1, l3))); 300 } 301 302 public static double heading(LatLon a, LatLon b) { 303 double hd = Math.atan2(sin(toRadians(a.lon() - b.lon())) * cos(toRadians(b.lat())), 304 cos(toRadians(a.lat())) * sin(toRadians(b.lat())) - 305 sin(toRadians(a.lat())) * cos(toRadians(b.lat())) * cos(toRadians(a.lon() - b.lon()))); 306 hd %= 2 * Math.PI; 307 if (hd < 0) { 308 hd += 2 * Math.PI; 309 } 310 return hd; 311 } 312 313 public static double angle_mPI_to_PI(double a) { 314 a = a % (2 * Math.PI); 315 if (a > Math.PI) { 316 a -= 2 * Math.PI; 317 } 318 if (a <= - Math.PI) { 319 a += 2 * Math.PI; 320 } 321 return a; 322 } 291 323 292 324 @Override
Note:
See TracChangeset
for help on using the changeset viewer.