How to calculate rectangle tangent to sphere

191 Views Asked by At

Given a rectangle $ABCD,$ how do I calculate points $A, B, C, \; \text{and}\; D\;$ if I place the rectangle tangent to a sphere, centered at a given Latitude and Longitude, and given a "Rotation" which would be degrees clockwise from "North" on the sphere?

You can assume that the sphere is a Unit Sphere centered at the Origin. enter image description here

I'm trying include this in a software application, so I would appreciate solutions suitable for programming, i.e. algebra or trigonometry rather than calculus.

Thank you!

1

There are 1 best solutions below

0
On

If you are aware of matrices, you can construct your rotation matrix from simple rotation matrices. Let's have rectangle parallel to plane $yz$ (with $z$ being the axis of spherical coordinates), sides parallel to $y$ and $z$ and center on the sphere (you can derive the coordinates of the vertices yourself).

We first rotate rectangle around its central point (axis $x$) by angle $\varphi$: $$ \Phi=\begin{pmatrix} 0 & 0 & 0 \\ 0 & \cos\varphi& -\sin\varphi\\ 0 & \sin\varphi& \phantom{-}\cos\varphi \end{pmatrix}. $$ Then we rotate the rectangle by given latitude angle (around axis $y$): $$ \Theta=\begin{pmatrix} \phantom{-}\cos\theta& 0& \sin\theta\\ 0 & 0 & 0 \\ -\sin\theta& 0& \cos\varphi \end{pmatrix}. $$ Finally, we will rotate around axis $z$ by longitude angle $\lambda$: $$ \Lambda=\begin{pmatrix} \cos\lambda& -\sin\lambda&0\\ \sin\lambda& \phantom{-}\cos\lambda & 0\\ 0 & 0 & 0 \\ \end{pmatrix}. $$

The total rotation is the product of the matrices. Since we apply matrices to vector from left to right, the order is like this: $$ R = \Lambda \Theta \Phi $$

From programming point of view, you can either derive the final equation for the corners on paper and then write it in code. Or preferably, add multiplication by matrix as a function your code and apply matrix multiplication on demand. The latter case will give you more flexibility and is probably less prone to bugs.