function [ x y ] = AltAz2xy(Alt,Az,x0,y0)
%AltAz2xy computes x and y from alt and azimuth, with optional x0 y0 at zenith
% this is for a Sigma 15mm lens and a Canon 5D Mark III camera
% Christopher Stubbs Jan 16 2014. Using empirical terms for x0,y0 and alpha

% Azoffset is amount y pixel axis is to the E of N, in degrees
% Pixaz=Az+Azoffset

Azoffset=-4.4;

% default values, can override with additional argument if desired
if nargin == 2
        x0=1408;
        y0=924;
end

% For no distortion, the radius in pixels is proportional to sin(zenith/2).

% Let's assume the lens goes to 90 deg of zenith angle at the diagonal 
% corner, so that is a distance of (monochromatic pixels= 2888 x 1924)
% sqrt(1444^2+962^2)=1735 pixels. So rpix=alpha*sind(zenith/2), 
% and 1735=alpha*sind(90/2) so alpha=1735/.707=2454. 

% fit to data gives 2474.4 

% radial distance in pixels, away from zenith
zenith=90-Alt;

rpix=2474.4*sind(zenith/2)

PixAz=Az+Azoffset;

dy=rpix.*cosd(PixAz)
dx=-rpix.*sind(PixAz)

y=y0+dy;
x=x0+dx;




end
