# How to rotate covariance?

I am working on an EKF and have a question regarding coordinate frame conversion for covariance matrices. Let's say I get some measurement $(x, y, z, roll, pitch, yaw)$ with corresponding 6x6 covariance matrix $C$. This measurement and $C$ are given in some coordinate frame $G_1$. I need to transform the measurement to another coordinate frame, $G_2$. Transforming the measurement itself is trivial, but I would also need to transform its covariance, correct? The translation between $G_1$ and $G_2$ should be irrelevant, but I would still need to rotate it. If I am correct, how would I do this? For the covariances between $x$, $y$, and $z$, my first thought was to simply apply a 3D rotation matrix, but that only works for a 3x3 submatrix within the full 6x6 covariance matrix. Do I need to apply the same rotation to all four blocks?

Covariance is defined as

\begin{align} C &= \mathbb{E}(XX^T) - \mathbb{E}(X)\mathbb{E}(X^T) \end{align}

where, in your case, $$X \in \mathbb{R}^6$$ is your state vector and $$C$$ is the covariance matrix you already have.

For the transformed state $$X'=R X$$, with $$R \in \mathbb{R}^{6\times 6}$$ in your case, this becomes

\begin{align} C' &= \mathbb{E}(X' X'^T) - \mathbb{E}(X')\mathbb{E}(X'^T) \\ &= \mathbb{E}(R X X^T R^T) - \mathbb{E}(RX)\mathbb{E}(X^T R^T) \\ &= R ~\mathbb{E}(X X^T) ~R^T - R\mathbb{E}(X)\mathbb{E}(X^T)R^T \\ &= R \big(~\mathbb{E}(X X^T) - \mathbb{E}(X)\mathbb{E}(X^T)\big)R^T \\ &= R C R^T \end{align}

As a caveat, be careful with Euler angles. Those are usual non-intuitive in their behavior so you might not be able to simply rotate them with the same rotation matrix that you use for position. Remember that they are usually defined (in the robotics world) in terms of the local coordinate system whereas position is usually defined in terms of the global coordinate system. Off the top of my head, though, I can't remember if they need special treatment.

• Thanks. In this case, though, $R$ is 3x3 and $C$ is 6x6. I guess part of my problem is that I'm uncertain how $R$ would affect the covariance between linear axes and rotation (or even the covariance of the Euler angles themselves), i.e., how should I augment $R$ so that it's 6x6. – TheWumpus Mar 3 '14 at 18:14
• $R$ is just any arbitrary affine transformation. In your case, the top left 3x3 block and the bottom right 3x3 blocks are both the rotation matrix (if you assume that the Euler angles can be rotated the same ... see caveat in answer). The off-diagonal blocks are zeros. – ryan0270 Mar 3 '14 at 21:23

The MRPT library can do this for you. You need to use a CPose3DPDFGaussian to represent your pose and covariance then use the + operator.

Under the hood it represents your 6DOF covariance as a 7DOF quaternion base covariance, where the math is more straightforward.

• Would be beneficial to show the maths as well as a library that does it for you. – chutsu Apr 10 '19 at 10:04

Very intuitive explanation with geometric interpretation for covariance and its decomposition.

http://www.visiondummy.com/2014/04/geometric-interpretation-covariance-matrix/

• Hello and welcome to Robotics! Thanks for your answer but we prefer answers to be self contained where possible. Links tend to rot so answers which rely on a link can be rendered useless if the linked to content disappears. If you add more context from the link, it is more likely that people will find your answer useful. – mactro Feb 24 '17 at 9:17
{"ft_lang_label":"__label__en","ft_lang_prob":0.87183917,"math_prob":0.9948068,"size":3547,"snap":"2021-31-2021-39","text_gpt3_token_len":1008,"char_repetition_ratio":0.13688964,"word_repetition_ratio":0.0,"special_character_ratio":0.2751621,"punctuation_ratio":0.097595476,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9995951,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-07-25T12:15:43Z\",\"WARC-Record-ID\":\"<urn:uuid:2d274440-c30d-4a99-8c37-99f7d9238c35>\",\"Content-Length\":\"187563\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:d01f24d7-1890-4152-963b-a7a334a29ad0>\",\"WARC-Concurrent-To\":\"<urn:uuid:3b024cd5-295f-4f97-8e40-908ccce59478>\",\"WARC-IP-Address\":\"151.101.1.69\",\"WARC-Target-URI\":\"https://robotics.stackexchange.com/questions/2556/how-to-rotate-covariance/9671\",\"WARC-Payload-Digest\":\"sha1:MKV7GIAIV6ROLV2HJC7CHVXMIZVONPSB\",\"WARC-Block-Digest\":\"sha1:UHDGZ5EY5ZSIYLBVE4T74OYPLHDBMETB\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046151672.96_warc_CC-MAIN-20210725111913-20210725141913-00131.warc.gz\"}"}