gov.nasa.worldwind.geom.Angle Java Examples

The following examples show how to use gov.nasa.worldwind.geom.Angle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WWJPanel.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see org.leo.traceroute.ui.AbstractRoutePanel#afterShow()
 */
@Override
public void afterShow(final Mode mode) {
	super.afterShow(mode);
	SwingUtilities.invokeLater(() -> {
		_container.invalidate();
		_container.revalidate();
		final GeoPoint localGeo = _services.getGeo().getLocalIpGeoLocation();
		final Position p = new Position(Angle.fromDegrees(localGeo.getLat()), Angle.fromDegrees(localGeo.getLon()), 2000);
		((OrbitView) _controller.getWWd().getView()).setCenterPosition(p);
		if (mode == Mode.TRACE_ROUTE) {
			_route.renotifyRoute();
		} else if (mode == Mode.SNIFFER) {
			_sniffer.renotifyPackets();
		} else {
			_whois.renotifyWhoIs();
		}
	});

}
 
Example #2
Source File: BasicMercatorTiledImageLayer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private BufferedImage transform( BufferedImage image, MercatorSector sector ) {
    int type = image.getType();
    if (type == 0)
        type = BufferedImage.TYPE_INT_RGB;
    BufferedImage trans = new BufferedImage(image.getWidth(), image.getHeight(), type);
    double miny = sector.getMinLatPercent();
    double maxy = sector.getMaxLatPercent();
    for( int y = 0; y < image.getHeight(); y++ ) {
        double sy = 1.0 - y / (double) (image.getHeight() - 1);
        Angle lat = Angle.fromRadians(sy * sector.getDeltaLatRadians() + sector.getMinLatitude().radians);
        double dy = 1.0 - (MercatorSector.gudermannianInverse(lat) - miny) / (maxy - miny);
        dy = Math.max(0.0, Math.min(1.0, dy));
        int iy = (int) (dy * (image.getHeight() - 1));

        for( int x = 0; x < image.getWidth(); x++ ) {
            trans.setRGB(x, y, image.getRGB(x, iy));
        }
    }
    return trans;
}
 
Example #3
Source File: OSMMapnikLayer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private static LevelSet makeLevels() {
    AVList params = new AVListImpl();

    params.setValue(AVKey.TILE_WIDTH, 256);
    params.setValue(AVKey.TILE_HEIGHT, 256);
    params.setValue(AVKey.DATA_CACHE_NAME, "Earth/OSM-Mercator/OpenStreetMap OpentopoMap");
    params.setValue(AVKey.SERVICE, "https://tile.openstreetmap.org/");
    params.setValue(AVKey.DATASET_NAME, "h");
    params.setValue(AVKey.FORMAT_SUFFIX, ".png");
    params.setValue(AVKey.NUM_LEVELS, 22);
    params.setValue(AVKey.NUM_EMPTY_LEVELS, 0);
    params.setValue(AVKey.LEVEL_ZERO_TILE_DELTA, new LatLon(Angle.fromDegrees(22.5d), Angle.fromDegrees(45d)));
    params.setValue(AVKey.SECTOR, new MercatorSector(-1.0, 1.0, Angle.NEG180, Angle.POS180));
    params.setValue(AVKey.TILE_URL_BUILDER, new URLBuilder());

    return new LevelSet(params);
}
 
Example #4
Source File: OpenTopoLayer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private static LevelSet makeLevels() {
    AVList params = new AVListImpl();

    params.setValue(AVKey.TILE_WIDTH, 256);
    params.setValue(AVKey.TILE_HEIGHT, 256);
    params.setValue(AVKey.DATA_CACHE_NAME, "Earth/OSM-Mercator/OpenStreetMap Mapnik");
    params.setValue(AVKey.SERVICE, "https://a.tile.opentopomap.org/");
    params.setValue(AVKey.DATASET_NAME, "h");
    params.setValue(AVKey.FORMAT_SUFFIX, ".png");
    params.setValue(AVKey.NUM_LEVELS, 22);
    params.setValue(AVKey.NUM_EMPTY_LEVELS, 0);
    params.setValue(AVKey.LEVEL_ZERO_TILE_DELTA, new LatLon(Angle.fromDegrees(22.5d), Angle.fromDegrees(45d)));
    params.setValue(AVKey.SECTOR, new MercatorSector(-1.0, 1.0, Angle.NEG180, Angle.POS180));
    params.setValue(AVKey.TILE_URL_BUILDER, new URLBuilder());

    return new LevelSet(params);
}
 
Example #5
Source File: OepnvkarteLayer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private static LevelSet makeLevels() {
    AVList params = new AVListImpl();

    params.setValue(AVKey.TILE_WIDTH, 256);
    params.setValue(AVKey.TILE_HEIGHT, 256);
    params.setValue(AVKey.DATA_CACHE_NAME, "Earth/OSM-Mercator/Oepnvkarte");
    params.setValue(AVKey.SERVICE, "http://tile.memomaps.de/tilegen//");
    params.setValue(AVKey.DATASET_NAME, "h");
    params.setValue(AVKey.FORMAT_SUFFIX, ".png");
    params.setValue(AVKey.NUM_LEVELS, 22);
    params.setValue(AVKey.NUM_EMPTY_LEVELS, 0);
    params.setValue(AVKey.LEVEL_ZERO_TILE_DELTA, new LatLon(Angle.fromDegrees(22.5d), Angle.fromDegrees(45d)));
    params.setValue(AVKey.SECTOR, new MercatorSector(-1.0, 1.0, Angle.NEG180, Angle.POS180));
    params.setValue(AVKey.TILE_URL_BUILDER, new URLBuilder());

    return new LevelSet(params);
}
 
Example #6
Source File: TMCoord.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Create an arbitrary set of Transverse Mercator coordinates with the given values.
 *
 * @param latitude the latitude <code>Angle</code>.
 * @param longitude the longitude <code>Angle</code>.
 * @param easting the easting distance value in meters.
 * @param northing the northing distance value in meters.
 * @param originLatitude the origin latitude <code>Angle</code>.
 * @param centralMeridian the central meridian longitude <code>Angle</code>.
 * @param falseEasting easting value at the center of the projection in meters.
 * @param falseNorthing northing value at the center of the projection in meters.
 * @param scale scaling factor.
 * @throws IllegalArgumentException if <code>latitude</code>, <code>longitude</code>, <code>originLatitude</code>
 * or <code>centralMeridian</code> is null.
 */
public TMCoord(Angle latitude, Angle longitude, double easting, double northing,
               Angle originLatitude, Angle centralMeridian,
               double falseEasting, double falseNorthing,
               double scale)
{
    if (latitude == null || longitude == null)
    {
        throw new IllegalArgumentException("Latitude Or Longitude Is Null");
    }
    if (originLatitude == null || centralMeridian == null)
    {
        throw new IllegalArgumentException("Angle Is Null");
    }

    this.latitude = latitude;
    this.longitude = longitude;
    this.easting = easting;
    this.northing = northing;
    this.originLatitude = originLatitude;
    this.centralMeridian = centralMeridian;
    this.falseEasting = falseEasting;
    this.falseNorthing = falseNorthing;
    this.scale = scale;
}
 
Example #7
Source File: ViewControlsSelectListener.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
protected Angle computePanAmount(Globe globe, OrbitView view, ScreenAnnotation control, double panStep)
{
    // Compute last pick point distance relative to pan control center
    double size = control.getAttributes().getSize().width * control.getAttributes().getScale();
    Vec4 center = new Vec4(control.getScreenPoint().x, control.getScreenPoint().y + size / 2, 0);
    double px = lastPickPoint.x - center.x;
    double py = view.getViewport().getHeight() - lastPickPoint.y - center.y;
    double pickDistance = Math.sqrt(px * px + py * py);
    double pickDistanceFactor = Math.min(pickDistance / 10, 5);

    // Compute globe angular distance depending on eye altitude
    Position eyePos = view.getEyePosition();
    double radius = globe.getRadiusAt(eyePos);
    double minValue = 0.5 * (180.0 / (Math.PI * radius)); // Minimum change ~0.5 meters
    double maxValue = 1.0; // Maximum change ~1 degree

    // Compute an interpolated value between minValue and maxValue, using (eye altitude)/(globe radius) as
    // the interpolant. Interpolation is performed on an exponential curve, to keep the value from
    // increasing too quickly as eye altitude increases.
    double a = eyePos.getElevation() / radius;
    a = (a < 0 ? 0 : (a > 1 ? 1 : a));
    double expBase = 2.0; // Exponential curve parameter.
    double value = minValue + (maxValue - minValue) * ((Math.pow(expBase, a) - 1.0) / (expBase - 1.0));

    return Angle.fromDegrees(value * pickDistanceFactor * panStep);
}
 
Example #8
Source File: MGRSCoord.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Create an arbitrary MGRS coordinate from a pair of latitude-longitude <code>Angle</code>
 * and the corresponding MGRS coordinate string.
 *
 * @param latitude the latitude <code>Angle</code>.
 * @param longitude the longitude <code>Angle</code>.
 * @param MGRSString the corresponding MGRS coordinate string.
 * @throws IllegalArgumentException if <code>latitude</code> or <code>longitude</code> is null,
 * or the MGRSString is null or empty.
 */
public MGRSCoord(Angle latitude, Angle longitude, String MGRSString)
{
    if (latitude == null || longitude == null)
    {
        throw new IllegalArgumentException("Latitude Or Longitude Is Null");
    }
    if (MGRSString == null)
    {
        throw new IllegalArgumentException("String Is Null");
    }
    if (MGRSString.length() == 0)
    {
        throw new IllegalArgumentException("String Is Empty");
    }
    this.latitude = latitude;
    this.longitude = longitude;
    this.MGRSString = MGRSString;
}
 
Example #9
Source File: MGRSCoord.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Create a MGRS coordinate from a standard MGRS coordinate text string.
 * <p>
 * The string will be converted to uppercase and stripped of all spaces before being evaluated.
 * </p>
 * <p>Valid examples:<br />
 * 32TLP5626635418<br />
 * 32 T LP 56266 35418<br />
 * 11S KU 528 111<br />
 * </p>
 * @param MGRSString the MGRS coordinate text string.
 * @param globe the <code>Globe</code> - can be null (will use WGS84).
 * @return the corresponding <code>MGRSCoord</code>.
 * @throws IllegalArgumentException if the <code>MGRSString</code> is null or empty,
 * the <code>globe</code> is null, or the conversion to geodetic coordinates fails (invalid coordinate string).
 */
public static MGRSCoord fromString(String MGRSString)
{
    if (MGRSString == null || MGRSString.length() == 0)
    {
        throw new IllegalArgumentException("String Is Null");
    }

    MGRSString = MGRSString.toUpperCase().replaceAll(" ", "");

    final MGRSCoordConverter converter = new MGRSCoordConverter();
    long err = converter.convertMGRSToGeodetic(MGRSString);

    if (err != MGRSCoordConverter.MGRS_NO_ERROR)
    {
        throw new IllegalArgumentException("MGRS Conversion Error (\"" +
           MGRSString +"\")");
    }

    return new MGRSCoord(Angle.fromRadians(converter.getLatitude()), Angle.fromRadians(converter.getLongitude()), MGRSString);
}
 
Example #10
Source File: MGRSCoord.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Create a MGRS coordinate from a pair of latitude and longitude <code>Angle</code>
 * with the given precision or number of digits (1 to 5).
 *
 * @param latitude the latitude <code>Angle</code>.
 * @param longitude the longitude <code>Angle</code>.
 * @param globe the <code>Globe</code> - can be null (will use WGS84).
 * @param precision the number of digits used for easting and northing (1 to 5).
 * @return the corresponding <code>MGRSCoord</code>.
 * @throws IllegalArgumentException if <code>latitude</code> or <code>longitude</code> is null,
 * or the conversion to MGRS coordinates fails.
 */
public static MGRSCoord fromLatLon(Angle latitude, Angle longitude, int precision)
{
    if (latitude == null || longitude == null)
    {
        throw new IllegalArgumentException("Latitude Or Longitude Is Null");
    }

    final MGRSCoordConverter converter = new MGRSCoordConverter();
    long err = converter.convertGeodeticToMGRS(latitude.radians, longitude.radians, precision);

    if (err != MGRSCoordConverter.MGRS_NO_ERROR)
    {
        throw new IllegalArgumentException("MGRS Conversion Error");
    }

    return new MGRSCoord(latitude, longitude, converter.getMGRSString());
}
 
Example #11
Source File: ViewControlsSelectListener.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Setup the view to a first person mode (zoom = 0)
 *
 * @param view the orbit view to set into a first person view.
 */
protected void setupFirstPersonView(OrbitView view)
{
    if (view.getZoom() == 0)  // already in first person mode
        return;

    Vec4 eyePoint = view.getEyePoint();
    // Center pos at eye pos
    Position centerPosition = wwd.getModel().getGlobe().computePositionFromPoint(eyePoint);
    // Compute pitch and heading relative to center position
    Vec4 normal = wwd.getModel().getGlobe().computeSurfaceNormalAtLocation(centerPosition.getLatitude(),
        centerPosition.getLongitude());
    Vec4 north = wwd.getModel().getGlobe().computeNorthPointingTangentAtLocation(centerPosition.getLatitude(),
        centerPosition.getLongitude());
    // Pitch
    view.setPitch(Angle.POS180.subtract(view.getForwardVector().angleBetween3(normal)));
    // Heading
    Vec4 perpendicular = view.getForwardVector().perpendicularTo3(normal);
    Angle heading = perpendicular.angleBetween3(north);
    double direction = Math.signum(-normal.cross3(north).dot3(perpendicular));
    view.setHeading(heading.multiply(direction));
    // Zoom
    view.setZoom(0);
    // Center pos
    view.setCenterPosition(centerPosition);
}
 
Example #12
Source File: ViewControlsSelectListener.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Find out where on the terrain surface the eye would be looking at with the given heading and pitch angles.
 *
 * @param view    the orbit view
 * @param heading heading direction clockwise from north.
 * @param pitch   view pitch angle from the surface normal at the center point.
 *
 * @return the terrain surface point the view would be looking at in the viewport center.
 */
protected Vec4 computeSurfacePoint(OrbitView view, Angle heading, Angle pitch)
{
    Globe globe = wwd.getModel().getGlobe();
    // Compute transform to be applied to north pointing Y so that it would point in the view direction
    // Move coordinate system to view center point
    Matrix transform = globe.computeSurfaceOrientationAtPosition(view.getCenterPosition());
    // Rotate so that the north pointing axes Y will point in the look at direction
    transform = transform.multiply(Matrix.fromRotationZ(heading.multiply(-1)));
    transform = transform.multiply(Matrix.fromRotationX(Angle.NEG90.add(pitch)));
    // Compute forward vector
    Vec4 forward = Vec4.UNIT_Y.transformBy4(transform);
    // Return intersection with terrain
    Intersection[] intersections = wwd.getSceneController().getTerrain().intersect(
        new Line(view.getEyePoint(), forward));
    return (intersections != null && intersections.length != 0) ? intersections[0].getIntersectionPoint() : null;
}
 
Example #13
Source File: UPSCoord.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Create a set of UPS coordinates from a pair of latitude and longitude for the given <code>Globe</code>.
 *
 * @param latitude  the latitude <code>Angle</code>.
 * @param longitude the longitude <code>Angle</code>.
 * @param globe     the <code>Globe</code> - can be null (will use WGS84).
 *
 * @return the corresponding <code>UPSCoord</code>.
 *
 * @throws IllegalArgumentException if <code>latitude</code> or <code>longitude</code> is null, or the conversion to
 *                                  UPS coordinates fails.
 */
public static UPSCoord fromLatLon(Angle latitude, Angle longitude)
{
    if (latitude == null || longitude == null)
    {
        throw new IllegalArgumentException("Latitude Or Longitude Is Null");
    }

    final UPSCoordConverter converter = new UPSCoordConverter();
    long err = converter.convertGeodeticToUPS(latitude.radians, longitude.radians);

    if (err != UPSCoordConverter.UPS_NO_ERROR)
    {
        throw new IllegalArgumentException("UPS Conversion Error");
    }

    return new UPSCoord(latitude, longitude, converter.getHemisphere(),
        converter.getEasting(), converter.getNorthing());
}
 
Example #14
Source File: LocRecord.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 6 votes vote down vote up
public LocRecord(final String owner, final double lat, final double lon) {
	this.owner = owner;
	final StringBuilder sb = new StringBuilder();
	//owner TTL class LOC ( d1 [m1 [s1]] {"N"|"S"} d2 [m2 [s2]] {"E"|"W"} alt["m"] [siz["m"] [hp["m"] [vp["m"]]]] )
	final double[] latDms = Angle.fromDegreesLatitude(lat).toDMS();
	final double[] lonDms = Angle.fromDegreesLatitude(lon).toDMS();
	sb.append(owner).append(".").append(SPACE).append(0).append(SPACE).append("IN").append(SPACE).append("LOC").append(SPACE);
	sb.append(Math.abs((int) latDms[0])).append(SPACE).append((int) latDms[1]).append(SPACE).append((float) latDms[2]).append(SPACE).append(lat >= 0 ? "N" : "S")
			.append(SPACE);
	sb.append(Math.abs((int) lonDms[0])).append(SPACE).append((int) lonDms[1]).append(SPACE).append((float) lonDms[2]).append(SPACE).append(lon >= 0 ? "E" : "W")
			.append(SPACE);
	sb.append("0m").append(SPACE).append("0m").append(SPACE).append("0m").append(SPACE).append("0m");
	raw = sb.toString();
	final Map<String, String> names = new HashMap<>();
	names.put("name", "Loc record");
	final City city = new City(null, null, null, names);
	final Country country = new Country(null, 0, 0, LOC, names);
	final Location loc = new Location(0, 0, lat, lon, null, null, null);
	location = new CityResponse(city, null, country, loc, null, null, null, null, null, null);
	valid = true;
}
 
Example #15
Source File: CustomPolyline.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public CustomPolyline(Path2D.Double path) {
    this.path = path;

    List<Position> positions = new ArrayList<>();

    double[] coordinates = new double[2];

    PathIterator pathIterator = this.path.getPathIterator(null);

    pathIterator.currentSegment(coordinates);
    Position firstPosition = new Position(Angle.fromDegreesLatitude(coordinates[1]), Angle.fromDegreesLongitude(coordinates[0]), 0.0d);
    positions.add(firstPosition);
    pathIterator.next();

    while (!pathIterator.isDone()) {
        pathIterator.currentSegment(coordinates);
        Position position = new Position(Angle.fromDegreesLatitude(coordinates[1]), Angle.fromDegreesLongitude(coordinates[0]), 0.0d);
        positions.add(position);
        pathIterator.next();
    }

    setPositions(positions);
}
 
Example #16
Source File: ViewControlsSelectListener.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Reset the view to an orbit view state if in first person mode (zoom = 0)
 *
 * @param view the orbit view to reset
 */
protected void resetOrbitView(OrbitView view)
{
    if (view.getZoom() > 0)   // already in orbit view mode
        return;

    // Find out where on the terrain the eye is looking at in the viewport center
    // TODO: if no terrain is found in the viewport center, iterate toward viewport bottom until it is found
    Vec4 centerPoint = computeSurfacePoint(view, view.getHeading(), view.getPitch());
    // Reset the orbit view center point heading, pitch and zoom
    if (centerPoint != null)
    {
        Vec4 eyePoint = view.getEyePoint();
        // Center pos on terrain surface
        Position centerPosition = wwd.getModel().getGlobe().computePositionFromPoint(centerPoint);
        // Compute pitch and heading relative to center position
        Vec4 normal = wwd.getModel().getGlobe().computeSurfaceNormalAtLocation(centerPosition.getLatitude(),
            centerPosition.getLongitude());
        Vec4 north = wwd.getModel().getGlobe().computeNorthPointingTangentAtLocation(centerPosition.getLatitude(),
            centerPosition.getLongitude());
        // Pitch
        view.setPitch(Angle.POS180.subtract(view.getForwardVector().angleBetween3(normal)));
        // Heading
        Vec4 perpendicular = view.getForwardVector().perpendicularTo3(normal);
        Angle heading = perpendicular.angleBetween3(north);
        double direction = Math.signum(-normal.cross3(north).dot3(perpendicular));
        view.setHeading(heading.multiply(direction));
        // Zoom
        view.setZoom(eyePoint.distanceTo3(centerPoint));
        // Center pos
        view.setCenterPosition(centerPosition);
    }
}
 
Example #17
Source File: StatusBar.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
protected String makeAngleDescription( String label, Angle angle ) {
    String s;
    if (Angle.ANGLE_FORMAT_DMS.equals(angleFormat))
        s = String.format("%s %s", label, angle.toDMSString());
    else
        s = String.format("%s %7.4f\u00B0", label, angle.degrees);
    return s;
}
 
Example #18
Source File: ViewControlsSelectListener.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
protected Angle computeLookPitch(OrbitView view, ScreenAnnotation control, double pitchStep)
{
    // Compute last pick point 'pitch' relative to look control center on y
    double size = control.getAttributes().getSize().width * control.getAttributes().getScale();
    Vec4 center = new Vec4(control.getScreenPoint().x, control.getScreenPoint().y + size / 2, 0);
    double py = view.getViewport().getHeight() - lastPickPoint.y - center.y;
    double pickDistanceFactor = Math.min(Math.abs(py) / 3000, 5) * Math.signum(py);
    // New pitch
    Angle pitch = view.getPitch().add(Angle.fromRadians(pitchStep * pickDistanceFactor));
    pitch = pitch.degrees >= 0 ? (pitch.degrees <= 90 ? pitch : Angle.fromDegrees(90)) : Angle.ZERO;
    return pitch;
}
 
Example #19
Source File: ViewControlsSelectListener.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
protected Angle computeLookHeading(OrbitView view, ScreenAnnotation control, double headingStep)
{
    // Compute last pick point 'heading' relative to look control center on x
    double size = control.getAttributes().getSize().width * control.getAttributes().getScale();
    Vec4 center = new Vec4(control.getScreenPoint().x, control.getScreenPoint().y + size / 2, 0);
    double px = lastPickPoint.x - center.x;
    double pickDistanceFactor = Math.min(Math.abs(px) / 3000, 5) * Math.signum(px);
    // New heading
    Angle heading = view.getHeading().add(Angle.fromRadians(headingStep * pickDistanceFactor));
    heading = heading.degrees >= 0 ? heading : heading.addDegrees(360);
    return heading;
}
 
Example #20
Source File: NwwPanel.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void setPitchLimits( Angle minAngle, Angle maxangle ) {
    View view = getWwd().getView();
    if (view != null && view instanceof OrbitView) {
        OrbitView oView = (OrbitView) view;
        OrbitViewLimits orbitViewLimits = oView.getOrbitViewLimits();
        orbitViewLimits.setPitchLimits(minAngle, maxangle);
    }
}
 
Example #21
Source File: ViewControlsSelectListener.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
protected Angle computePanHeading(OrbitView view, ScreenAnnotation control)
{
    // Compute last pick point 'heading' relative to pan control center
    double size = control.getAttributes().getSize().width * control.getAttributes().getScale();
    Vec4 center = new Vec4(control.getScreenPoint().x, control.getScreenPoint().y + size / 2, 0);
    double px = lastPickPoint.x - center.x;
    double py = view.getViewport().getHeight() - lastPickPoint.y - center.y;
    Angle heading = view.getHeading().add(Angle.fromRadians(Math.atan2(px, py)));
    heading = heading.degrees >= 0 ? heading : heading.addDegrees(360);
    return heading;
}
 
Example #22
Source File: NwwPanel.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Move to see a given sector.
 * 
 * @param sector
 *            the sector to go to.
 * @param animate
 *            if <code>true</code>, it animates to the position.
 */
public void goTo( Sector sector, boolean animate ) {
    View view = getWwd().getView();
    view.stopAnimations();
    view.stopMovement();
    if (sector == null) {
        return;
    }
    // Create a bounding box for the specified sector in order to estimate
    // its size in model coordinates.
    Box extent = Sector.computeBoundingBox(getWwd().getModel().getGlobe(),
            getWwd().getSceneController().getVerticalExaggeration(), sector);

    // Estimate the distance between the center position and the eye
    // position that is necessary to cause the sector to
    // fill a viewport with the specified field of view. Note that we change
    // the distance between the center and eye
    // position here, and leave the field of view constant.
    Angle fov = view.getFieldOfView();
    double zoom = extent.getRadius() / fov.cosHalfAngle() / fov.tanHalfAngle();

    // Configure OrbitView to look at the center of the sector from our
    // estimated distance. This causes OrbitView to
    // animate to the specified position over several seconds. To affect
    // this change immediately use the following:

    if (animate) {
        view.goTo(new Position(sector.getCentroid(), 0d), zoom);
    } else {
        ((OrbitView) wwd.getView()).setCenterPosition(new Position(sector.getCentroid(), 0d));
        ((OrbitView) wwd.getView()).setZoom(zoom);
    }
}
 
Example #23
Source File: BasicMarkerWithInfo.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public BasicMarkerWithInfo(Position position, MarkerAttributes attrs,
    Angle heading, String info) {
    this.info = info;
    if (attrs == null) {
        String message = Logging.getMessage("nullValue.AttributesIsNull");
        Logging.logger().severe(message);
        throw new IllegalArgumentException(message);
    }

    this.position = position;
    this.heading = heading;
    this.attributes = attrs;
}
 
Example #24
Source File: CurrentGpsPointLayer.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void updatePosition( double lat, double lon ) {
    if (gpsMarker == null) {
        gpsMarker = new BasicMarker(Position.fromDegrees(lat, lon, 0), basicMarkerAttributes);
        addMarker(gpsMarker);
    } else {
        if (doHeading) {
            double azimuth = GeometryUtilities.azimuth(new Coordinate(previousLon, previousLat), new Coordinate(lon, lat));
            Angle heading = Angle.fromDegrees(azimuth);
            gpsMarker.setHeading(heading);
        }
        gpsMarker.setPosition(Position.fromDegrees(lat, lon, 10));
    }
    previousLat = lat;
    previousLon = lon;
}
 
Example #25
Source File: WWJPanel.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void focusPoint(final GeoPoint point, final boolean isRunning, final boolean animation) {
	final long elevation = 5000 * 1000;
	if (_controller == null || _controller.getWWd() == null) {
		return;
	}
	// center the map on the given point
	final LabeledPath label = point == null ? null : _pointToLabel.get(point);
	if (label != null) {
		highlightAnnotation(label, point);
		final View view = _controller.getWWd().getView();
		final OrbitViewInputHandler ovih = (OrbitViewInputHandler) view.getViewInputHandler();
		if (animation && Env.INSTANCE.getAnimationSpeed() > 0) {
			final Position pos = new Position(label.getLocations().iterator().next(), 10);
			ovih.addPanToAnimator(pos, view.getHeading(), view.getPitch(), elevation, Env.INSTANCE.getAnimationSpeed(), true);
			//				if (_mode == Mode.TRACE_ROUTE && isRunning) {
			//					// if tracing, move at the speed of the timeout
			//					final Position pos = new Position(label.getLocations().iterator().next(), 10);
			//					ovih.addPanToAnimator(pos, view.getHeading(), view.getPitch(), elevation,
			//							Env.INSTANCE.getAnimationSpeed(), true);
			//				} else if (_mode == Mode.TRACE_ROUTE || !isRunning) {
			//					_controller.getWWd().getView()
			//							.goTo(new Position(label.getLocations().iterator().next(), 10), elevation);
			//				}
		} else {
			final Position p = new Position(Angle.fromDegrees(point.getLat()), Angle.fromDegrees(point.getLon()), 2000);
			((OrbitView) view).setCenterPosition(p);
		}
	}
}
 
Example #26
Source File: UPSCoord.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create a set of UPS coordinates for the given <code>Globe</code>.
 *
 * @param hemisphere the hemisphere, either {@link gov.nasa.worldwind.avlist.AVKey#NORTH} or {@link
 *                   gov.nasa.worldwind.avlist.AVKey#SOUTH}.
 * @param easting    the easting distance in meters
 * @param northing   the northing distance in meters.
 * @param globe      the <code>Globe</code> - can be null (will use WGS84).
 *
 * @return the corresponding <code>UPSCoord</code>.
 *
 * @throws IllegalArgumentException if the conversion to UPS coordinates fails.
 */
public static UPSCoord fromUPS(String hemisphere, double easting, double northing)
{
    final UPSCoordConverter converter = new UPSCoordConverter();
    long err = converter.convertUPSToGeodetic(hemisphere, easting, northing);

    if (err != UTMCoordConverter.UTM_NO_ERROR)
    {
        throw new IllegalArgumentException("UTM Conversion Error");
    }

    return new UPSCoord(Angle.fromRadians(converter.getLatitude()),
        Angle.fromRadians(converter.getLongitude()),
        hemisphere, easting, northing);
}
 
Example #27
Source File: UPSCoord.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create an arbitrary set of UPS coordinates with the given values.
 *
 * @param latitude   the latitude <code>Angle</code>.
 * @param longitude  the longitude <code>Angle</code>.
 * @param hemisphere the hemisphere, either {@link gov.nasa.worldwind.avlist.AVKey#NORTH} or {@link
 *                   gov.nasa.worldwind.avlist.AVKey#SOUTH}.
 * @param easting    the easting distance in meters
 * @param northing   the northing distance in meters.
 *
 * @throws IllegalArgumentException if <code>latitude</code>, <code>longitude</code>, or <code>hemisphere</code> is
 *                                  null.
 */
public UPSCoord(Angle latitude, Angle longitude, String hemisphere, double easting, double northing)
{
    if (latitude == null || longitude == null)
    {
        throw new IllegalArgumentException("Latitude Or Longitude Is Null");
    }

    this.latitude = latitude;
    this.longitude = longitude;
    this.hemisphere = hemisphere;
    this.easting = easting;
    this.northing = northing;
}
 
Example #28
Source File: TMCoord.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create a set of Transverse Mercator coordinates from a pair of latitude and longitude,
 * for the given <code>Globe</code> and projection parameters.
 *
 * @param latitude the latitude <code>Angle</code>.
 * @param longitude the longitude <code>Angle</code>.
 * @param globe the <code>Globe</code> - can be null (will use WGS84).
 * @param a semi-major ellipsoid radius. If this and argument f are non-null and globe is null, will use the specfied a and f.
 * @param f ellipsoid flattening. If this and argument a are non-null and globe is null, will use the specfied a and f.
 * @param originLatitude the origin latitude <code>Angle</code>.
 * @param centralMeridian the central meridian longitude <code>Angle</code>.
 * @param falseEasting easting value at the center of the projection in meters.
 * @param falseNorthing northing value at the center of the projection in meters.
 * @param scale scaling factor.
 * @return the corresponding <code>TMCoord</code>.
 * @throws IllegalArgumentException if <code>latitude</code> or <code>longitude</code> is null,
 * or the conversion to TM coordinates fails. If the globe is null conversion will default
 * to using WGS84.
 */
public static TMCoord fromLatLon(Angle latitude, Angle longitude, Double a, Double f,
               Angle originLatitude, Angle centralMeridian,
               double falseEasting, double falseNorthing,
               double scale)
{
    if (latitude == null || longitude == null)
    {
        throw new IllegalArgumentException("Latitude Or Longitude Is Null");
    }
    if (originLatitude == null || centralMeridian == null)
    {
        throw new IllegalArgumentException("Angle Is Null");
    }

    final TMCoordConverter converter = new TMCoordConverter();
    if (a == null || f == null)
    {
        a = converter.getA();
        f = converter.getF();
    }
    long err = converter.setTransverseMercatorParameters(a, f, originLatitude.radians, centralMeridian.radians,
            falseEasting, falseNorthing, scale);
    if (err == TMCoordConverter.TRANMERC_NO_ERROR)
        err = converter.convertGeodeticToTransverseMercator(latitude.radians, longitude.radians);

    if (err != TMCoordConverter.TRANMERC_NO_ERROR && err != TMCoordConverter.TRANMERC_LON_WARNING)
    {
        throw new IllegalArgumentException("TM Conversion Error");
    }

    return new TMCoord(latitude, longitude, converter.getEasting(), converter.getNorthing(),
            originLatitude, centralMeridian, falseEasting, falseNorthing, scale);
}
 
Example #29
Source File: TMCoord.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Create a set of Transverse Mercator coordinates for the given <code>Globe</code>,
 * easting, northing and projection parameters.
 *
 * @param easting the easting distance value in meters.
 * @param northing the northing distance value in meters.
 * @param globe the <code>Globe</code> - can be null (will use WGS84).
 * @param originLatitude the origin latitude <code>Angle</code>.
 * @param centralMeridian the central meridian longitude <code>Angle</code>.
 * @param falseEasting easting value at the center of the projection in meters.
 * @param falseNorthing northing value at the center of the projection in meters.
 * @param scale scaling factor.
 * @return the corresponding <code>TMCoord</code>.
 * @throws IllegalArgumentException if <code>originLatitude</code> or <code>centralMeridian</code>
 * is null, or the conversion to geodetic coordinates fails. If the globe is null conversion will default
 * to using WGS84.
 */
public static TMCoord fromTM(double easting, double northing,
               Angle originLatitude, Angle centralMeridian,
               double falseEasting, double falseNorthing,
               double scale)
{
    if (originLatitude == null || centralMeridian == null)
    {
        throw new IllegalArgumentException("Angle Is Null");
    }

    final TMCoordConverter converter = new TMCoordConverter();

    double a = converter.getA();
    double f = converter.getF();
    long err = converter.setTransverseMercatorParameters(a, f, originLatitude.radians, centralMeridian.radians,
            falseEasting, falseNorthing, scale);
    if (err == TMCoordConverter.TRANMERC_NO_ERROR)
        err = converter.convertTransverseMercatorToGeodetic(easting, northing);

    if (err != TMCoordConverter.TRANMERC_NO_ERROR && err != TMCoordConverter.TRANMERC_LON_WARNING)
    {
        throw new IllegalArgumentException("TM Conversion Error");
    }

    return new TMCoord(Angle.fromRadians(converter.getLatitude()), Angle.fromRadians(converter.getLongitude()),
            easting, northing, originLatitude, centralMeridian, falseEasting, falseNorthing, scale);
}
 
Example #30
Source File: Coordinates.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
public static TMCoord tmFromMgrs(String mgrs, double central_meridan)
{
   MGRSCoord coord = MGRSCoord.fromString(mgrs);
   TMCoord tm = TMCoord.fromLatLon(coord.getLatitude(), 
      coord.getLongitude(), WGS84_A, WGS84_F,
      Angle.fromRadians(ORIGIN_LATITUDE),
      Angle.fromRadians(central_meridan),  
      FALSE_EASTING, FALSE_NORTHING, SCALE);
   return tm;
}