// (C)2007 Attila Kovacs <attila@submm.caltech.edu>



public class HammerAitoff extends SphericalProjection {
	
	public HammerAitoff() {}

	public String getFitsID() { return fitsID; }

	public String getFullName() { return fullName; }

	@Override
	public final void getOffsets(double theta, double phi, CoordinatePair toOffset) {
		double gamma = gamma(theta, phi);
		toOffset.x = 2.0 * gamma * Math.cos(theta) * Math.sin(0.5*phi);
		toOffset.y = gamma * Math.sin(theta);
	}

	@Override
	public final double phi(CoordinatePair offset) {
		double Z2 = Z2(offset);
		double Z = Math.sqrt(Z2);
		return 2.0 * Vector2D.getAngle(2.0*Z2 - 1.0, 0.5*Z*offset.x);
	}

	@Override
	public final double theta(CoordinatePair offset) {
		return asin(offset.y * Math.sqrt(Z2(offset)));
	}
	
	public final double Z2(CoordinatePair offset) {
		return 1.0 - (offset.x * offset.x)/16.0 - (offset.y*offset.y)/4.0;
	}
	
	public final double gamma(double theta, double phi) {
		return Math.sqrt(2.0 / (1.0+Math.cos(theta)*Math.cos(0.5*phi)));
	}
	
	public final static String fitsID = "AIT";
	public final static String fullName = "Hammer-Aitoff";
}
