How do I compute the solid angle of a square in space in spherical coordinates? I am trying to find out how to calculate a solid angle of a square or a rectangle in space, in a situation where


*

*we know θ and ϕ, being θ the polar angle and ϕ the azimutal angle

*the sphere has radius r = 1

*the plane's minimum distance from the center of the sphere is equal to r, thus 1. In other terms the plane is tangent to the sphere.

*we also know θ and ϕ at the edges as they both vary from -֔π/4 to ֔π/4. This is a consequence of the plane simply being one face of a cube that includes the sphere.

*the zero of both angles θ and ϕ coincides with the center of the plane.


In alternative words this problem could be described as finding the solid angle, using known azimutal polar angles, for every pixel of an image that is ideally placed at distance one from the sphere.

What is a general formula to find the solid angle of any quad placed on the plane?
Edit: as someone asked what software I used to produce the sketch, it’s Blender 2.76.
 A: Let $A_i=(x_i,y_i,1)$ $(i\ {\rm mod}\ 4)$ be the four vertices of the square $Q$. The edges $A_{i-1}A_i$ together with the origin $O$ determine four planes $\sigma_i$ that bound a quadrilateral cone. Using the vector product you can  compute the unit normals ${\bf n}_i$ of these planes, and this in turn will allow you to compute the inner angle $\alpha_i$ between the two  planes intersecting along the line $OA_i$. This $\alpha_i$ then is the angle at $A_i'\in S^2$ of the spherical quadrangle $Q'$ obtained through the projection. The area of $Q'$ is then simply given by the "spherical excess" of the $\alpha_i$, i.e., 
$${\rm area}(Q')=\sum_{i=0}^3\alpha_i\ -2\pi\ .$$
A: If the pixels are small enough and you do not need a mathematically exact answer (that is, if a good approximation is sufficient),
a relatively simply formula would treat the pixel as if it were being projected onto a plane tangent to the sphere at the actual image of the center of the pixel.
That is, we take a plane tangent to the sphere inside one of your red regions as an means of approximating the red region.
If the normal to the plane in which the pixels lie is $\hat{\mathbf n}$ and the vector from the center of the sphere to the center of the pixel is $\mathbf x,$
then the directional vector from the center of the sphere is 
$\hat{\mathbf x} = \frac{1}{\lVert \mathbf x\rVert}\mathbf x.$
Mapping the pixel onto the sphere, the area is reduced by two effects:


*

*Projecting the pixel onto a plane at an angle to the pixel's plane, the area is multiplied by the inner product of the normals of the two planes. The normal of the projected plane is the direction vector, so this effect multiplies the area by the factor $\hat{\mathbf x} \cdot \hat{\mathbf n}$.

*Projecting the pixel closer to the origin of the projection, the area is multiplied by the square of the ratio of the distances, that is, by $r^2/\lVert \mathbf x\rVert^2.$ Since $r = 1$ this factor is $1/\lVert \mathbf x\rVert^2.$
The end result is that if the original pixel has area $A$, the
area of the pixel projected onto the sphere is approximately
$$(\hat{\mathbf x} \cdot \hat{\mathbf n}) \frac{1}{\lVert \mathbf x\rVert^2}A
= \frac{{\mathbf x} \cdot \hat{\mathbf n}}{\lVert \mathbf x\rVert^3}A.$$
Since the sphere has radius $1,$ the area of the projection of the pixel on the sphere is also the solid angle subtended by the pixel.
