This section describes the direction unit vector coordinates used by far field projections and grating projections.
Coordinate transformations between spherical and direction cosine units are described below.
Coordinate limits and units $$radius \qquad 0< r \qquad m$$ $$polar\ angle \qquad 0\leq \theta\leq\pi \qquad rad$$ $$azimuthal\ angle \qquad 0\leq \phi\leq2\pi \qquad rad$$ $$unit\ vector \qquad 1\leq u\leq1 \qquad$$ 

Spherical to direction cosine $$u_{x}=sin(\theta)cos(\phi)$$ $$u_{y}=sin(\theta)sin(\phi)$$ $$u_{z}=cos(\theta)$$ $$u_{z}=\sqrt{1u_{x}^{2}u_{y}^{2}}$$ $$u_{x}^{2}+u_{y}^{2}+u_{z}^{2}=1$$ 

Direction cosine to spherical
$$r=1$$ $$\theta=a\cos(u_{z})$$ $$\phi=a\tan(\frac{u_{y}}{u_{x}})$$ 
Note: farfieldspherical The farfieldspherical function can be used to interpolate far field data from ux,uy coordinates to spherical coordinates. 
Note: Performing integrals We typically want to perform integrals in spherical coordinates such as the following $$power=\int\int P(\theta,\phi)R^2 sin(\theta)d\theta d\phi$$ where P is the Poynting vector and R is the radius. The far field projections return the electric field as a function of the variables ux and uy which are the x and y components of the unit direction vector. When changing integration variables from (q,j) to (ux,uy), it can be shown that $$power=\int\int P(\theta,\phi)R^{2}sin(\theta)d\theta d\phi \\=\int\int P(u_{x},u_{y})R^{2}\frac{du_{x} du_{y}}{cos(\theta)} $$ Care must be taken to avoid numerical errors due to the cos(q) term. It's best to use the farfield3dintegrate function to evaluate these integrals. 