How to find the rotation matrix of a circle of a sphere that is perpendicular with a vector on the sphere's surface

1.3k Views Asked by At

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.

3

There are 3 best solutions below

6
On 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.

5
On

Warning the following may only work when the given vector is not already collinear to the $z$-axis. Moreover I restrict myself to the sphere of radius 1 centered in the origin, as it makes my life easier.

You have got a vector $n$ of length $1$. This vector is the normal of some plane $P$, which yields the desired circle $C’$ when intersected with the sphere of radius $1$. The question is how (and by what amount) to rotate the circle $C$ of radius $1$ in the $xy$ plane such that it agrees with the circle $C‘$.

Note that this is equivalent to rotating the normal of the circle $C$, say $z=(0,0,1)$ to the normal of the circle $C‘$, which is $n$. We can do this by rotating along the axis $z\times n$ (which is perpendicular to both $z$ and $n$) by $\angle(z,n)=\cos^{-1}(\langle z,n\rangle)$ (the angle between $z$ and $n$).

Warning: this may not be the shortest rotation making the circles line up, as it depends on the orientation of the normal vectors of the circles. We can circumvent this by subtracting $180^\circ$ respectively $\pi$ when $\angle(z,n) > 90^\circ$ respectively $\pi/2$.

Edit Upon request I want to add the following method, which involves spherical coordinates.

Note that it suffices to rotate the vector of the $z$-axis onto $n=(x_1,y_1,z_1)$. According to wikipedia: spherical coordinates the angle between the $z$axis and our vector $n$ is given by $\theta$. Moreover the rotation axis can be seen to be $(\cos(\sigma+\pi/2), \sin(\sigma+\pi/2),0)$.

4
On

Let us simplify the issue by taking $(x_0,y_0,z_0)=(0,0,0)$.

Let $R$ be the sphere's radius, $V_1:=(x_1,y_1,z_1)$ and $V_z:=(0,0,R)$

A rotation is known when you know its axis and its angle :

a) Its axis is defined by the cross product

$$V_1 \times V_z=\begin{pmatrix} \ \ Ry_1\\-Rx_1\\0\end{pmatrix}$$

We will denote the normalized version of this cross product by $\begin{pmatrix}k_x\\k_y\\k_z\end{pmatrix}$.

b) Its angle is

$$\theta=\cos^{-1}\left(\dfrac{V_1.V_z}{\|V_1\|\|V_z\|}\right)$$

The rotation matrix is given by the second Rodrigues formula in this reference :

$$\mathbf{R} =\mathbf{I} +(\sin \theta )\mathbf{K} +(1-\cos \theta )\mathbf{K}^{2}\tag{1}$$

where $\mathbf{K}$ is the skew symmetric matrix defined by :

$$\mathbf{K} =\left({\begin{array}{rrr}0&-k_{z}&k_{y}\\k_{z}&0&-k_{x}\\-k_{y}&k_{x}&0\end{array}}\right).$$

Remark : The Rodrigues formula under its matrix form (1) is a way to express a rotation as the exponential matrix of a skew symmetric matrix, precisely $$\mathbf{R}=\exp(\theta \mathbf{K})$$