Find the rotation matrix of a circle of a sphere that is perpendicular with a vector on the sphere’s surface

circlesgeometry

enter image description here

Hello, Imagine having a sphere of ray R and then you randomly pick a point on the surface of said sphere
(x1=x0+ ray* sin(theta)cos(sigma) , y1= y0+ ray sin(theta)sin(sigma), z1= z0+ ray math.cos(theta))
where (x0,y0,z0) represent the center of the sphere and you know theta and sigma.

Now the line that passes through this point and the center of the sphere makes a 90 degree angle with the plane of another circle on this sphere, but what I want to know is how do I get a rotation matrix that applied to the circle that cuts the sphere only in the xy (z=z0, the dotted circle) will make a 90 degree angle with the aforementioned line.

Best Answer

Remember that a rotation matrix will only give a rotation around an axis that passes through the origin. So you cannot just apply a rotation matrix.

First subtract $(x_0,y_0,z_0)$ from the coordinates of any point you want to rotate. Then apply the rotation matrix. Then add $(x_0,y_0,z_0)$ to the rotated coordinates.

With that in mind, the rotation will actually be performed on a sphere whose center is at $(0,0,0)$ (after subtracting $(x_0,y_0,z_0)$ and before adding $(x_0,y_0,z_0)$ back again).

The simplest rotation, conceptually, is to simply rotate the circle about the axis through the two points where the two circles should intersect. This axis is perpendicular to the vector $(x_1-x_0,y_1-y_0,z_1-z_0),$ and also perpendicular to the projection of that vector onto the $x,y$ plane. The two intersection points are therefore $\left(r \cos\left(\sigma + \frac\pi2\right), r \sin\left(\sigma + \frac\pi2\right), 0\right)$ and $\left(r \cos\left(\sigma - \frac\pi2\right), r \sin\left(\sigma - \frac\pi2\right), 0\right),$ where $r$ is the sphere's radius ("ray" in your formulas). Slightly simpler formulas for these points (using the trig identities for angles plus or minus $\frac\pi2$ radians) are $(- r \sin(\sigma), r \cos(\sigma), 0)$ and $(r \sin(\sigma), -r \cos(\sigma), 0)$.

When describing an axis of rotation we typically just take a unit vector along the axis. The factor of $r$ makes the vector that much longer or shorter, so let's just use $(-\sin(\sigma), \cos(\sigma), 0).$ I chose this vector because it's the one on the "far side" of the sphere in your diagram and a right-hand-rule rotation by $\theta$ will give the result you want. If we used the other vector as an axis we'd have to rotate by $-\theta$ or us a left-hand rule.

From Wikipedia, the matrix for a rotation by angle $\theta$ around axis $(u_x,u_y,u_z)$ is $$\begin{bmatrix}\cos \theta +u_{x}^{2}\left(1-\cos \theta \right)&u_{x}u_{y}\left(1-\cos \theta \right)-u_{z}\sin \theta &u_{x}u_{z}\left(1-\cos \theta \right)+u_{y}\sin \theta \\u_{y}u_{x}\left(1-\cos \theta \right)+u_{z}\sin \theta &\cos \theta +u_{y}^{2}\left(1-\cos \theta \right)&u_{y}u_{z}\left(1-\cos \theta \right)-u_{x}\sin \theta \\u_{z}u_{x}\left(1-\cos \theta \right)-u_{y}\sin \theta &u_{z}u_{y}\left(1-\cos \theta \right)+u_{x}\sin \theta &\cos \theta +u_{z}^{2}\left(1-\cos \theta \right)\end{bmatrix}.$$

We want $u_x = -\sin(\sigma),$ $u_y = \cos(\sigma),$ and $u_z = 0.$ Plugging these into the matrix formula, we get $$\begin{bmatrix} \cos\theta + (1-\cos \theta )\sin ^2\sigma & -(1-\cos \theta ) \sin\sigma \cos\sigma & \sin \theta \cos\sigma \\ -\left(1-\cos \theta \right)\sin\sigma \cos\sigma & \cos \theta + (1-\cos \theta)\cos^2\sigma & \sin \theta \sin\sigma \\ -\sin \theta\cos\sigma & -\sin \theta\sin\sigma & \cos \theta \end{bmatrix}.$$

So that's your rotation matrix.


But note that either before or after you apply this rotation, you could rotate the circle in place and it would still be the same circle. When you combine that rotation with the rotation matrix above, you get a rotation about yet another axis which also takes the dotted-line circle to the solid circle.

For example, you could rotate by $\pi$ radians ($180$ degrees) around the vector $\left(\sin\left(\frac\theta2\right)\cos(\sigma), \sin\left(\frac\theta2\right)\sin(\sigma), \cos\left(\frac\theta2\right)\right)$, which is the bisector of the angle between the $z$ axis and $(x_1-x_0,y_1-y_0,z_1-z_0).$ Since we are rotating by $\pi$ radians rather than the angle $\theta,$ we have to substitute $-1$ where the Wikipedia formula has $\cos\theta$ and $0$ where Wikipedia has $\sin\theta.$ That gives a matrix $$\begin{bmatrix} 2u_{x}^{2} - 1 & 2u_{x}u_{y} & 2u_{x}u_{z} \\ 2u_{y}u_{x} & 2u_{y}^{2} - 1 & 2u_{y}u_{z} \\ 2u_{z}u_{x} & 2u_{z}u_{y} & 2u_{z}^{2} - 1 \end{bmatrix}.$$

Set $u_x = \sin\left(\frac\theta2\right)\cos(\sigma),$ $u_y = \sin\left(\frac\theta2\right)\sin(\sigma),$ and $u_z = \cos\left(\frac\theta2\right).$ Also consider the trig identities $2\sin^2\left(\frac\theta2\right) = 1 - \cos\theta$, $2\cos^2\left(\frac\theta2\right) = 1 + \cos\theta,$ and $2\sin\left(\frac\theta2\right) \cos\left(\frac\theta2\right) = \sin\theta,$ we get $$\begin{bmatrix} (1 - \cos\theta)\cos^2\sigma - 1 & (1 - \cos\theta)\sin\sigma\cos\sigma & \sin\theta\cos\sigma \\ (1 - \cos\theta)\sin\sigma\cos\sigma & (1 - \cos\theta)\sin^2\sigma - 1 & \sin\theta\sin\sigma \\ \sin\theta\cos\sigma & \sin\theta\sin\sigma & \cos\theta \end{bmatrix}.$$

A little more manipulation would show that this is very similar to the rotation matrix derived earlier, except that the signs of all entries in the first two columns have been reversed. This is because each individual point of the circle ends up $180$ degrees around the circle from where it does under the other rotation.

Related Question