开发者

How to use a matrix to rotate the reference system of a vector relatively to another?

开发者 https://www.devze.com 2023-01-17 05:51 出处:网络
Real-life case (helps understand the question) I am building a device that can freely rotate around all its axis (x, y, z) and is equipped with:

Real-life case (helps understand the question)

I am building a device that can freely rotate around all its axis (x, y, z) and is equipped with:

  • an accelerometer (A) that gives me a vector pointing to the centre of the Earth (Va)
  • a 3D magnetometer (M) that gives me the direction of the magnetic field of the Earth (Vm)

The two vectors share the same开发者_开发知识库 reference system (x, y, z), but what I am interested to find is the vector that points to the north relative to the Earth surface [think of a hand-held compass: I want to find where the needle should point to].

This video shows a "ball compass" that has pretty much the same behaviour that my device should replicate electronically.

The coding question

I did a bit of research, and it seems to me that I should use is 3D rotation matrices doing the following two steps:

  1. rotate the reference system of Vm from R to R', in such a way that y' will be parallel to Va,
  2. "flatten" the Vm vector setting its y' component to 0

Unluckily I am still confused on how I should proceed in concrete terms (I have no previous experience of working with vectors and matrices). One of the things that confuses me is that most of the material I could google, talks in terms of angles, but the data I am receiving from both sensors is in the form V(Vx, Vy, Vz), where Vz, Vy and Vz are the components of V along the reference system.

So my question really boils down to: what is the matrix I have to use in order to perform the transformation of which at step #1?

Thank you in advance for your time and expertise.


One simpler answer that comes to mind is to use cross products.

you can find east with Ve = Va ⨉ Vm and then north with Vn = Va ⨉ Ve

(this might actually be south, haven't thought through the handedness)

0

精彩评论

暂无评论...
验证码 换一张
取 消