This section describes the direction unit vector coordinates used by far field projections and grating projections.
The standard 3D far field and grating projection functions calculate the far field profile on a hemispherical surface 1 meter from the simulation. 

Calculating the field profile on a hemispherical surface creates a minor issue when we try to plot the data on a flat computer screen. The data must be 'flattened' in some way so that we can represent a curved surface on a flat computer screen. By default we plot the far field data as if we look straight down on the hemisphere. 

The position vectors u1, u2 of the data returned by the far field projections use 'direction unit vector' coordinates. Each unit vector goes from 1 to 1 as shown in the figure to the right.
The far field is calculated at a linearly spaced set of points as measured in the u1, u2 direction unit vector coordinates.
The point u1,u2 = 0,0 corresponds to propagation at normal incidence, in the middle of the hemisphere. 
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=acos(u_{z})$$ $$\phi=atan(\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. 