1

Summary: using 3 angles to represent a magnetic dipole's orientation is redundant because the rotation around the $z$-axis of the dipole does not change the magnetic field, there are only 2 DOFs for rotation for a magnetic dipole. After taking the linear approximation of the magnetic field at a certain orientation, it relates the change of orientation to the change of magnetic field through the Jacobian. The Jacobian always loses at least 1 rank, which is expected. But why the null space of the Jacobian is not a rotation around the $z$-axis? What I am trying to do is to use a least square method to solve for the magnet's orientation, which involves the Jacobian. Then I found this phenomenon that I couldn't understand.

I would like to be as rigorous as possible so I would write the math from the beginning. It makes the description long.

Detailed mathematics: The magnetic field of a dipole can be represented as: $$B(r,\mu)=\frac{\mu_0}{4\pi}\frac{|\mu|}{|r|^3} (3\hat{r}\hat{r}^T-I)\hat{\mu} $$

where $r$ is the vector from the magnet to the position where the field is measured, and $\mu$ is the magnetic dipole moment. The orientation of the magnetic dipole is embedded in $\hat{\mu}$, which can be represented as an intrinsic rotation by 3 Euler angles, e.g. Euler angles X-Y-X.

For simplicity, $r$ is considered known and fixed. Assuming the default dipole moment direction is attached to its body's z-axis, the magnetic field expression becomes a function of 3 Euler angles: $$B(\alpha,\beta,\gamma)=\frac{\mu_0}{4\pi}\frac{|\mu|}{|r|^3} (3\hat{r}\hat{r}^T-I)R_x(\alpha)R_y(\beta)R_x(\gamma)\begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}\\=\frac{\mu_0}{4\pi}\frac{|\mu|}{|r|^3} (3\hat{r}\hat{r}^T-I)\begin{bmatrix} s_{\beta} c_{\gamma} \\ -c_{\alpha}s_{\gamma}-s_{\alpha}c_{\beta}c_{\gamma} \\ c_{\alpha}c_{\beta}c_{\gamma}-s_{\alpha}s_{\gamma} \end{bmatrix} \\ =('')\begin{bmatrix} s_{\beta} c_{\gamma} \\ -c_{\alpha}s_{\gamma}-s_{\alpha}c_{\beta}c_{\gamma} \\ c_{\alpha}c_{\beta}c_{\gamma}-s_{\alpha}s_{\gamma} \end{bmatrix}$$

The first half is abbreviated as $('')$ because it's full rank and doesn't affect the null space of $J_o$. Linearize the magnetic field at a certain orientation $(\overline{\alpha},\overline{\beta},\overline{\gamma})$: $$ B(\alpha,\beta,\gamma) \approx B(\overline{\alpha},\overline{\beta},\overline{\gamma})+J_o(\overline{\alpha},\overline{\beta},\overline{\gamma}) (\begin{bmatrix} \alpha\\ \beta \\ \gamma \end{bmatrix}-\begin{bmatrix} \overline{\alpha} \\ \overline{\beta} \\ \overline{\gamma} \end{bmatrix})$$

where $J_o$ is the jacobian of $B$ with respect to $(\alpha,\beta,\gamma)$:

$$J_o=('')\begin{bmatrix} 0 & c_{\beta}c_{\gamma} & -s_{\beta}s_{\gamma}\\ s_{\alpha}s_{\gamma}-c_{\alpha}c_{\beta}c_{\gamma} & s_{\alpha}s_{\beta}c_{\gamma} & s_{\alpha}c_{\beta}s_{\gamma}-c_{\alpha}c_{\gamma} \\ c_{\alpha}s_{\gamma}-s_{\alpha}c_{\beta}c_{\gamma} & -c_{\alpha}s_{\beta}c_{\gamma} & -s_{\alpha}c_{\gamma}-c_{\alpha}c_{\beta}c_{\gamma} \end{bmatrix}$$

The linear approximation also relates, at a certain configuration, how the change in orientation is mapped to the change in magnetic field: $$ B(\alpha,\beta,\gamma) - B(\overline{\alpha},\overline{\beta},\overline{\gamma}) \approx J_o(\overline{\alpha},\overline{\beta},\overline{\gamma}) (\begin{bmatrix} \alpha\\ \beta\\ \gamma \end{bmatrix}-\begin{bmatrix} \overline{\alpha} \\ \overline{\beta} \\ \overline{\gamma} \end{bmatrix})$$ $$\delta_B(\overline{\alpha},\overline{\beta},\overline{\gamma}) = J_o(\overline{\alpha},\overline{\beta},\overline{\gamma}) \delta_{angle}(\overline{\alpha},\overline{\beta},\overline{\gamma})$$

Using 3 angles to represent the orientation of the magnet is redundant because the rotation around the z-axis cannot be observed. It results in the rank deficiency of $J_o$. It also means there is a null space for $J_o$.

Presumably, the null space will represent a rotation around the z-axis. However, take $(\overline{\alpha},\overline{\beta},\overline{\gamma}) = (0,0,0)$ for example, in this case, the dipole is pointing upward.

$$J_o(0,0,0) = ('')\begin{bmatrix} 0 & 1 & 0\\ -1 & 0 & 1\\ 0 & 0 & 0 \end{bmatrix}$$

$$null(J_o) = \begin{bmatrix} 1\\ 0\\ -1 \end{bmatrix}$$

The null space is not representing a rotation around the z-axis. In fact, the rotation around the z-axis at $(\overline{\alpha},\overline{\beta},\overline{\gamma}) = (0,0,0)$ is $\begin{bmatrix} \alpha\\ \beta \\ \gamma \end{bmatrix}-\begin{bmatrix} \overline{\alpha} \\ \overline{\beta} \\ \overline{\gamma} \end{bmatrix} = \begin{bmatrix} \frac{\pi}{2}\\ \delta_{\beta}\\ -\frac{\pi}{2} \end{bmatrix}$, which is not a sub-space in $\mathbb{R}^3$, it's a line shifted from the origin.

Why this would happen?


EDIT

I found Prof. Barfoot's paper on linearizing the rotation: Pose estimation using linearized rotations and quaternion algebra. What concerns my question would be Section 3.1. One difference is that the paper uses extrinsic rotation. But it just changes the order of the rotation matrix and does not affect the discussion.

In the paper, it shows that linearizing the rotation matrix using Taylor expansion (26) is not correct, because the linearized "rotation matrix" is not a rotation matrix anymore (27). What should be used is derived as (31):

$$ C(\theta) = C(\overline{\theta}+\delta_{\theta}) = C(\delta_{\phi})C(\overline{\theta}) = C(S(\overline{\theta})\delta_{\theta})C(\overline{\theta}) $$

where $\theta = (\alpha, \beta, \gamma)$ in my question, and $C(\theta)$ is the rotation matrix obtained by rotating the frame around the Euler angles $\theta$ extrinsically. $S(\theta)$ is defined in (21): $$S(\theta) = S(\alpha, \beta, \gamma) = \begin{bmatrix} C_{x}(\gamma)C_{y}(\beta)\begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix} & C_{x}(\gamma)\begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix} & \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix} \end{bmatrix} $$

After plugging in $\overline{\theta}=\begin{bmatrix} 0 \\ 0 \\ 0 \end{bmatrix}$, $\delta_{\theta} = \begin{bmatrix} \frac{\pi}{2} \\ \delta_{\beta} \\ -\frac{\pi}{2} \end{bmatrix}$, which is a rotation around the z-axis:

$$C(\begin{bmatrix} \frac{\pi}{2} \\ \delta_{\beta} \\ -\frac{\pi}{2} \end{bmatrix}) = C(\begin{bmatrix} 1 & 0 & 1 \\ 0 & 1 & 0 \\ 0&0&0 \end{bmatrix}\begin{bmatrix} \frac{\pi}{2} \\ \delta_{\beta} \\ -\frac{\pi}{2} \end{bmatrix})I = C(\begin{bmatrix} 0 \\ \delta_{\beta} \\ 0 \end{bmatrix})$$

The equality does not hold anymore. And the linearized rotation matrix is not a rotation around the z-axis. It does not solve the problem.


FOLLOW-UP

Let's say I want to linearize the function at $\overline{\omega} = (0, \frac{\pi}{2}, 0)$, which is a rotation around the $y$-axis for $\frac{\pi}{2}$. Under this rotation, the body's $z$-axis is aligned with the global $x$-axis. I presume the null space of the Jacobian would be $\delta_\omega = \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}$, which is a rotation around the global $x$-axis.

As a sanity check, $exp(\begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}_\times)*exp(\begin{bmatrix} 0 \\ \frac{\pi}{2} \\ 0 \end{bmatrix}_\times)\begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix} = exp(\begin{bmatrix} 0 \\ \frac{\pi}{2} \\ 0 \end{bmatrix}_\times)\begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}$. It means that $\delta_{\omega}=\begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}$ indeed does not change the vector when $\overline{\omega} = (0, \frac{\pi}{2}, 0)$.

To linearized the function at this point, I write my function as

$$C(\omega)v =\exp([\omega]_{\times})R_0(\overline{\omega})\begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}$$.

And linearized it as

$$C(\omega)v = \exp([\omega]_{\times})R_{0}v \approx \exp([\overline{\omega}]_{\times}))R_0(\overline{\omega})v + \frac{\partial \exp([\omega]_{\times})) R_0(\overline{\omega})v }{\partial \omega}|_{\omega=\overline{\omega}} \delta_{\omega}$$

$$ = \exp([\overline{\omega}]_{\times}))R_0(\overline{\omega})v + J_o(\overline{\omega})\delta_{\omega} $$

I did this derivation, asked MATLAB to give me $J_o(\overline{\omega})$ and the null space of it. MATLAB gave me $(1,0,-1)$, which is not the expected $(1,0,0)$. I am not sure if I have misunderstood something and made it wrong.

  • It might be helpful to also post this on the physics page. https://physics.stackexchange.com/ – Nic Jun 27 '24 at 19:25
  • 1
    Hi @Nic, I did post one and updated: https://physics.stackexchange.com/questions/819501/linear-approximation-of-the-magnetic-dipole-field – William Lin Jun 27 '24 at 19:31
  • 1
    Are you sure you have to use Euler angles to represent the orientation? Because Euler angles are almost always a wrong choice, regardless of which convention (among nearly infinitely many different ones) you choose to work with. If you choose the "right coordinates", i.e., the exponential coordinates for the tangent space attached at the current orientation, then indeed the null space exactly corresponds to the redundancy. – Junekey Jeon Jun 28 '24 at 04:26
  • 1
    I don't really have an answer to your exact question (involving Euler angles which I quite passionately hate), but my guess is that it is simply because Euler angles don't play nice with linearization. – Junekey Jeon Jun 28 '24 at 04:26
  • Hi @JunekeyJeon, thank you so much for reading my question and providing input! I am using Euler angles because it's the simplest one I know so I also do not know what "exponential coordinates for the tangent space attached at the current orientation" is. What is it and how can I use that to obtain the desired property? – William Lin Jun 28 '24 at 14:31
  • 1
    The key is that you should not try to coordinatize the orientation "globally". Instead, you should consider a coordinate system centered at the current orientation. Like I did in my post, you think $B$ as a function of the vector $\omega$ in a way that the orientation is given as the product $\exp([\omega]{\times})R{0}$ where $R_{0}$ is the current orientation. (Or the other order of multiplication, depending on the convention.) Then the linearized approximation for $B$ in terms of $\omega$ will become a nice expression. – Junekey Jeon Jun 28 '24 at 15:10
  • 1
    ... After you do something with that and update $R_{0}$, then use this new one for further processing. But really, I am doubtful if you really need to work with 3D orientation from the first place. As you pointed out, there is a redundant DoF, which means you can reformulate your problem in 2D. I would use spherical coordinate for such a problem, with the same "rebasing" technique to avoid numerical issues at the north/south poles. – Junekey Jeon Jun 28 '24 at 15:12
  • @JunekeyJeon, I indeed tried using spherical coordinates to represent the orientation. But at the north/south pole, the Jacobian loses one more rank and becomes rank 1. So I switched to using 3 Euler angles, where I can select a subspace of those 3 angles to ensure the Jacobian is rank 2 in that subspace. But the null space problem appears. – William Lin Jun 28 '24 at 15:26
  • @JunekeyJeon So for the 3 Euler angles, what I should do is: when linearizing around a certain $\overline{\omega} \in \mathbb{R}^3$, I should write $B$ as a function of $\exp([\omega]{\times})R(\overline{\omega})$ instead of $\exp([\omega]{\times})$, then calculate the Jacobian. Is that correct? – William Lin Jun 28 '24 at 16:04
  • Hi @JunekeyJeon, I am not sure if I have understood it correctly. I did the derivation according to my understanding and updated it in the original question's FOLLOW-UP section. Could you have a look? It's hard to write Latex in the comment and the private chat doesn't show Latex so I did it this way. If there is a better way I could reach you, please kindly let me know. Thank you! – William Lin Jun 28 '24 at 21:30
  • As I said, Euler angles are not great and not needed unless you have very specific reasons to use them, like e.g. have to actually move some physical actuators. I didn't really look into the actual details of your computations, but a rough guess is that you get (1,0,-1) because of the specific convention you chose: X-Y-X. – Junekey Jeon Jul 02 '24 at 06:48
  • 1
    Linearization, by definition, is a way to approximate your function as a linear function on the tangent space of the point you are looking at. For the case of 3D orientation, the tangent space is naturally parameterized by the angular velocity vectors (the $\omega$ vector), and its components has nothing to do with Euler angles. They correspond to the coordinates of the rotation axis, scaled by the rotation angle. If you use that coordinate system, then you do get the expected answer. – Junekey Jeon Jul 02 '24 at 06:51
  • Regarding the spherical coordinate thing, you should not try to use it when you're close to the north/south poles. A better way is to first rotate your system so that the dipole is aligned at the x-axis before you invoke the spherical coordinates, just like you should never use $\exp([\omega]{\times})$ and should use $\exp([\omega]{\times})R(\bar{\omega})$ instead. – Junekey Jeon Jul 02 '24 at 06:55
  • Hi @JunekeyJeon, thanks for following up! In the FOLLOW-UP section of the original question, I tried to use the $\omega$ vector and $exp([\omega]_{\times})R(\overline{\omega})$, and linearized at an example $\overline{\omega} = \begin{bmatrix} 0\ \frac{\pi}{2}\0 \end{bmatrix}$ The result is not as expected. Did I do something wrong or misunderstand your point? – William Lin Jul 02 '24 at 13:17
  • 1
    I think you misunderstood some things. The point of doing the translation $R(\bar{\omega})$ is to move the origin of the linear approximation. You are approximating your function at a nonzero point, which is why you fail to get the expected outcome, I think. You have to write things in a way that your derivative is evaluated at zero. – Junekey Jeon Jul 04 '24 at 09:33
  • Thank you for pointing it out, @JunekeyJeon! I think I get the point now. After I move the origin to $\overline{\omega}$, I should evaluate the Jacobian at $\omega = 0$. "Section 3.3: Derivative at the identity" of this paper: https://arxiv.org/abs/1312.0788 introduces how to evaluate the derivative of the exponential map with respect to the exponential coordinate at the origin. Using the results from the paper on the Jacobian's formula, I do get the result that the null space is the body's $z$-axis. – William Lin Jul 05 '24 at 13:38
  • 1
    Cool, glad you got it! – Junekey Jeon Jul 08 '24 at 11:08
  • @JunekeyJeon, thank you so much for your time and patience! – William Lin Jul 08 '24 at 13:13

0 Answers0