0

I'am working with Madgwick algorithm who gives me a Quaternions for accelerometer and gyro. So I can get the angle from q0 with this formula 2 * acors(q0) it's works I've tried and I got the good value. But now I don't understand how can I know for x or y has rotate to x° because I have only one angle with Quaternion.

For example imagine I have this Quaternion q0 to q3 {0,71, 0,18, -0,65, 0.30}, so for q0 equals to 0.71 I have an angle to 90°. but in my example x and y are different, so how can I know x is 90° and y is 20° for example, is it possible without using Euler angle? I've tried this formula for x q1/sin(angle/2) but the result doesn't convince me....

simon
  • 1,180
  • 3
  • 12
  • 33
  • `q1/sin(angle/2)` is x-component of **rotation axis** direction vector. And what do you want to get? – MBo Jun 28 '21 at 11:57
  • @MBo For example I would like to know how can I know thaht my x axis rotate 20° for example by using q0 and q1 is it possible ? I'am completly beginner with Quaternions. Because if q0 give me an angle of 90° for example how can I know if my x is 90° and my y is 50° for example. – simon Jun 28 '21 at 12:01

1 Answers1

0

If you have quaternion (u is unit vector, direction vector of rotation axis)

(cos(a/2), u * sin(a/2))

and want to know how vector V is transformed with this quaternion (in the end of Rotation Identity section)

V' = Vperp*cos(a) + (u x Vperp) * sin(a) + Vpara

where Vperp and Vpara are components of vector V perpendicular and parallel to vector u

Vpara = u * (u.dot.V)
Vperp = V - Vpara

Example:

let rotation axis (u) is (0.707, 0.707, 0), we want to know how 
OX-aligned vector (1,0,0) will look after rotation by 180 degrees

Vpara = (0.707, 0.707, 0) * (0.707*1 + 0.707*0 + 0) = (0.5, 0.5, 0)
Vperp = (1, 0, 0) - (0.5, 0.5, 0) = (0.5, -0.5, 0)
V' = (0.5, -0.5, 0) * -1  + (u x Vperp) * 0 + (0.5, 0.5, 0) = (0, 1, 0)

(OX becomes OY)

MBo
  • 77,366
  • 5
  • 53
  • 86
  • Ok I understand thanks, maybe it's more easy for me to compare two Quaternion, beceause I have an initial Quaternion for my start position after few moment I got a new Quaternion, maybe it's possible to compare 2 Quaternion and get the angle between x and y for 2 Quaternion? – simon Jun 28 '21 at 13:14
  • Sorry, but quaternion describes rotation, not position. We apply quaternion to vector `q v q^-1` , and get rotated vector (same result as trigonometric formula in the answer, another calculations) – MBo Jun 28 '21 at 13:18
  • Mmmh ok, so if I understand, I can't know the angle in x and y between this Quaternion `(0.95, -0.17, -0,06, 0.23) ` and this other Quaternion `(0.67, -0.22, -0.70, 0.23) ` that's right? it's not natural for me to work with Quaternion, but I want to use it to avoid Gimbal lock – simon Jun 28 '21 at 13:28
  • 1
    There is no angle between x and y in quaternion. Imagine you have three perpendicular pens OX, OY, OZ in plasticine ball. Quaternion axis u is one more pen inserted in the same ball. You have point P to rotate, link it with U pen with shortest thread, then rotate point around U pen with the same thread length by quaternion-defined angle. – MBo Jun 28 '21 at 13:36
  • Ok I understand but look at this thread https://stackoverflow.com/questions/57063595/how-to-obtain-the-angle-between-two-quaternions it seems to compute angles between two Quaternions non? – simon Jun 28 '21 at 13:55
  • I don't know if it's for you, but my final objective is to detect a rotation more than 90° in pitch or roll using quaternion. So I have a initiale Quaternion and I'd like to detect if an another Quaternion has rotate more than 90° in pitch or roll compraed to my intial Quaternion. I think I'am little bit loss with Quaternion... – simon Jun 28 '21 at 14:34
  • I am not specialist in quaternion usage in body/apparatus orientation. As far as I understand, orientation might be dewscribed by quaternion needed to rotate body from standard direction (1,0,0) to current direction. In this case - yes, having quaternions Q and P, you can find transformation between them as quaternion T = Q * P^-1 and get angle from T as usual – MBo Jun 28 '21 at 14:46