I want to rotate the whole value of a 3d vector into one axis using quaternion rotations.

The reason behind is that I want to align the X and Y Axis of my smartphone with the X and Y Axis of my vehicle in order to detect lateral and longitudinal acceleration separated on these two axis. Therefore I want to detect the first straight acceleration of the car and rotate the whole acceleration value into the heading axis (X-Axis) of the phone assuming a straight forward motion.

How do I achieve this?

enter image description here enter image description here

  • $\begingroup$ So you know the rotation you want to apply, but just don't know how quaternions work? $\endgroup$
    – fibonatic
    Jun 8, 2016 at 17:13
  • $\begingroup$ @fibonatic I know that if I accelerate forward for the first time with my car, I will get the corresponding sensor value mixed on two axes (e.g. X and Y-Axes). I also know the axis I would like to put the whole sensor value in (e.g. the X axis). $\endgroup$
    – R. Doe
    Jun 8, 2016 at 19:47

1 Answer 1

  • Use the average magnitude of X,Y as the acceleration vector.
  • Get the angle between this vector and the (1,0).
  • Create a quaternion with this vector that looks something like (cos(angle/2),0,0,-1)
  • Multiple all future acceleration results
  • $\begingroup$ That is sort of the way I used to do it now. Thank you! $\endgroup$
    – R. Doe
    Jun 10, 2016 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.