gov.nasa.worldwind.globes.projections.ProjectionEquirectangular Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2014 United States Government as represented by the Administrator of the
* National Aeronautics and Space Administration.
* All Rights Reserved.
*/
package gov.nasa.worldwind.globes.projections;
import gov.nasa.worldwind.geom.*;
import gov.nasa.worldwind.globes.*;
/**
* Implements an Equirectangular projection, also known as Equidistant Cylindrical, Plate Carree and Rectangular. The
* projected globe is spherical, not ellipsoidal.
*
* @author tag
* @version $Id: ProjectionEquirectangular.java 2277 2014-08-28 21:19:37Z dcollins $
*/
public class ProjectionEquirectangular extends AbstractGeographicProjection
{
public ProjectionEquirectangular()
{
super(Sector.FULL_SPHERE);
}
public String getName()
{
return "Equirectangular";
}
@Override
public boolean isContinuous()
{
return true;
}
@Override
public Vec4 geographicToCartesian(Globe globe, Angle latitude, Angle longitude, double metersElevation, Vec4 offset)
{
return new Vec4(globe.getEquatorialRadius() * longitude.radians + offset.x,
globe.getEquatorialRadius() * latitude.radians, metersElevation);
}
@Override
public void geographicToCartesian(Globe globe, Sector sector, int numLat, int numLon, double[] metersElevation,
Vec4 offset, Vec4[] out)
{
double eqr = globe.getEquatorialRadius();
double minLat = sector.getMinLatitude().radians;
double maxLat = sector.getMaxLatitude().radians;
double minLon = sector.getMinLongitude().radians;
double maxLon = sector.getMaxLongitude().radians;
double deltaLat = (maxLat - minLat) / (numLat > 1 ? numLat - 1 : 1);
double deltaLon = (maxLon - minLon) / (numLon > 1 ? numLon - 1 : 1);
double offset_x = offset.x;
int pos = 0;
// Iterate over the latitude and longitude coordinates in the specified sector, computing the Cartesian point
// corresponding to each latitude and longitude.
double lat = minLat;
for (int j = 0; j < numLat; j++, lat += deltaLat)
{
if (j == numLat - 1) // explicitly set the last lat to the max latitude to ensure alignment
lat = maxLat;
// Latitude is constant for each row. Values that are a function of latitude can be computed once per row.
double y = eqr * lat;
double lon = minLon;
for (int i = 0; i < numLon; i++, lon += deltaLon)
{
if (i == numLon - 1) // explicitly set the last lon to the max longitude to ensure alignment
lon = maxLon;
double x = eqr * lon + offset_x;
double z = metersElevation[pos];
out[pos++] = new Vec4(x, y, z);
}
}
}
@Override
public Position cartesianToGeographic(Globe globe, Vec4 cart, Vec4 offset)
{
return Position.fromRadians(cart.y / globe.getEquatorialRadius(),
(cart.x - offset.x) / globe.getEquatorialRadius(), cart.z);
}
@Override
public Vec4 northPointingTangent(Globe globe, Angle latitude, Angle longitude)
{
return Vec4.UNIT_Y;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy