blob: 30e084c456cd49c0655a96c3880d649f59ebb827 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.stem.loggers.imagewriter.logger.projections;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
/**
* Implementation of Equirectangular map projection. In terms of the existing
* coordinate system implied in the Globe system, this projection does nothing
* as this is the implied base coordinate system
*
* @see http://mathworld.wolfram.com/EquirectangularProjection.html
*
*/
public class Orthographic implements IMapProjection {
private Point2D origin = new Point2D.Double(0.0, 0.0);
private static final Rectangle2D PROJECTION_BOUNDS = new Rectangle2D.Double(
-58, -58, 116, 116);
/**
*
*/
public Orthographic() {
super();
}
/*
* (non-Javadoc)
*
* @see
* com.ibm.almaden.omniglobe.projection.IMapProjection#project(java.awt.
* geom.Point2D)
*/
public double[] project(double lat, double lon) {
double lambda0 = Math.toRadians(origin.getX());
double phi0 = Math.toRadians(origin.getY());
double phi = Math.toRadians(lat);
double lambda = Math.toRadians(lon);
double c = Math.sin(phi0)*Math.sin(phi) + Math.cos(phi0)*Math.cos(phi)*Math.cos(lambda-lambda0);
if (c < 0) {
return null;
}
double lonF = Math
.toDegrees(Math.cos(phi) * Math.sin(lambda - lambda0));
double latF = Math.toDegrees(Math.cos(phi0) * Math.sin(phi)
- Math.sin(phi0) * Math.cos(phi) * Math.cos(lambda - lambda0));
return new double[] { latF, lonF };
}
/*
* (non-Javadoc)
*
* @see
* com.ibm.almaden.omniglobe.projection.IMapProjection#project(java.awt.
* geom.Point2D, java.awt.geom.Point2D, boolean)
*/
public double[] project(double lat, double lon, double lat0, double lon0,
boolean distort) {
return project(lat, lon);
}
/*
* (non-Javadoc)
*
* @see
* com.ibm.almaden.omniglobe.projection.IMapProjection#inverseProject(java
* .awt.geom.Point2D)
*/
public double[] inverseProject(double lat, double lon) {
return new double[] { lat, lon };
}
/*
* (non-Javadoc)
*
* @see
* com.ibm.almaden.omniglobe.projection.IMapProjection#inverseProject(java
* .awt.geom.Point2D, java.awt.geom.Point2D, boolean)
*/
public double[] inverseProject(double lat, double lon, double lat0,
double lon0, boolean distort) {
return inverseProject(lat, lon);
}
/*
* (non-Javadoc)
*
* @see
* com.ibm.almaden.omniglobe.projection.IMapProjection#setOrigin(java.awt
* .geom.Point2D)
*/
public void setOrigin(double lat, double lon) {
origin = new Point2D.Double(lon, lat);
}
/*
* (non-Javadoc)
*
* @see com.ibm.almaden.omniglobe.projection.IMapProjection#getBounds()
*/
public Rectangle2D getBounds() {
return PROJECTION_BOUNDS;
}
}