protected boolean areShapesIntersecting(Airspace a1, Airspace a2) { if ((a1 instanceof SphereAirspace) && (a2 instanceof SphereAirspace)) { SphereAirspace s1 = (SphereAirspace) a1; SphereAirspace s2 = (SphereAirspace) a2; LatLon location1 = s1.getLocation(); LatLon location2 = s2.getLocation(); double altitude1 = s1.getAltitudes()[0]; double altitude2 = s2.getAltitudes()[0]; boolean terrainConforming1 = s1.isTerrainConforming()[0]; boolean terrainConforming2 = s2.isTerrainConforming()[0]; // We have to compute the 3D coordinates of the sphere's center ourselves here. Vec4 p1 = terrainConforming1 ? this.getSurfacePoint(location1, altitude1) : this.getPoint(location1, altitude1); Vec4 p2 = terrainConforming2 ? this.getSurfacePoint(location2, altitude2) : this.getPoint(location2, altitude2); double r1 = s1.getRadius(); double r2 = s2.getRadius(); double d = p1.distanceTo3(p2); return d <= (r1 + r2); } return false; }
public Airspace createAirspace(WorldWindow wwd, boolean fitShapeToViewport) { SphereAirspace sphere = new SphereAirspace(); sphere.setAttributes(getDefaultAttributes()); sphere.setValue(AVKey.DISPLAY_NAME, getNextName(toString())); sphere.setAltitude(0.0); sphere.setTerrainConforming(true); this.initializeSphere(wwd, sphere, fitShapeToViewport); return sphere; }
protected void initializeSphere( WorldWindow wwd, SphereAirspace sphere, boolean fitShapeToViewport) { // Creates a sphere in the center of the viewport. Attempts to guess at a reasonable size and // height. Position position = ShapeUtils.getNewShapePosition(wwd); double sizeInMeters = fitShapeToViewport ? ShapeUtils.getViewportScaleFactor(wwd) : DEFAULT_SHAPE_SIZE_METERS; sphere.setLocation(new LatLon(position)); sphere.setRadius(sizeInMeters / 2.0); }