# Step 4: Computation of the Antenna Gain for Selected Directions

Only points of the spheroid are computed. In 3D mode all points on the spheroid are examined while in the 2x2D mode the computation is done the following way:
1. The points in the horizontal plane (including Mgeo) are computed.
2. The maximum gain in the horizontal plane is determined.
3. The points on the vertical plane, defined with Mgeo the vector of the z-axis and the vector from Mgeo to the point with maximum gain, are computed.
4. The point with a maximum gain in the vertical pattern is determined. If this point is not in the horizontal plane, the horizontal plane is parallel moved from Mgeo to this point with maximum gain, and the horizontal pattern is recomputed in this plane.

The computation is made in the coordinate system defined in step 2.

An arbitrary point P has the coordinates (xP,yP, zP) and is on the spheroid used for the computation. The difference vector δ between P and Mgeo is defined as:

(1) $\delta =\left(\begin{array}{c}{x}_{\delta }\\ {y}_{\delta }\\ {z}_{\delta }\end{array}\right)=\left(\begin{array}{c}{x}_{P}\\ {y}_{P}\\ {z}_{P}\end{array}\right)\text{\hspace{0.17em}}-\left(\begin{array}{c}{x}_{geo}\\ {y}_{geo}\\ {z}_{geo}\end{array}\right)$

Standardized to a length of 1 m this leads to the vector Δ

(2) $\Delta =\left(\begin{array}{c}{x}_{\Delta }\\ {y}_{\Delta }\\ {z}_{\Delta }\end{array}\right)=\frac{1}{\sqrt{{\left({x}_{d}^{}\right)}^{2}+{\left({y}_{d}^{}\right)}^{2}+{\left({z}_{d}^{}\right)}^{2}}}\left(\begin{array}{c}{x}_{\delta }\\ {y}_{\delta }\\ {z}_{\delta }\end{array}\right)$

Point P and vector $\Delta$ described in the 3D antenna pattern the following azimuth α and tilt ϑ:

(3) $\alpha =\left\{\begin{array}{lll}\mathrm{tan}\left(\frac{{x}_{\Delta }}{{y}_{\Delta }}\right)\hfill & if\hfill & x\ge 0,y\ge 0\hfill \\ 180°+\mathrm{tan}\left(\frac{{x}_{\Delta }}{{y}_{\Delta }}\right)\hfill & if\hfill & x\ge 0,y\le 0\hfill \\ 180°+\mathrm{tan}\left(\frac{{x}_{\Delta }}{{y}_{\Delta }}\right)\hfill & if\hfill & x\le 0,y\le 0\hfill \\ 360°+\mathrm{tan}\left(\frac{{x}_{\Delta }}{{y}_{\Delta }}\right)\hfill & if\hfill & x\le 0,y\ge 0\hfill \end{array}$

(assuming the x-axis is equal to 0°, and the y-axis is equal to 90°).

(4) $\vartheta =\mathrm{arccos}\left(z\Delta \right)$

(assuming 0° is equal to the positive z-axis and 90° is horizontal plane)

For the computation of the first horizontal pattern, ϑ is equal to 90° and α is incremented between 0° and 360°. For the computation of the vertical pattern, α is equal to 0° and ϑ is incremented between 0° and 180°. In 3D computation mode, both angles must be incremented to sample all directions.