Conversation started Nov 14, 2015 at 3:26.
Pip
Pip
Nov 14, 2015 03:26
@IcyDefiance yo, you know math? I need a quaternion wizard.
kinda-sorta. what's up?
Pip
Pip
I have a quat that I'm getting from a sensor, which integrates gyro, accelerometer, and magnetometer data and outputs it
I need to get my rotation in degrees
like, a compass value
so... the axis in a circle aligned with the ground
In OpenGL that would be the... Z axis and the X axis I believe
if you're looking at it top-down
so the rotation around the y axis
does it need to be aligned with north, or do you just need a number that changes when you turn?
Pip
Pip
A number that changes when I turn
I think I can reset the sensor to zero before a turn
so the value of the quat should be the change since zeroed
I think the equation would be something like as follows:
    float angle_rad = acos(q0) * 2;
    float x = q1 / sin(angle_rad/2);
    float y = q2 / sin(angle_rad/2);
    float z = q3 / sin(angle_rad/2);
But I'm not completely sure that that's right
where q1, q2, etc map to a value in q[0,1,2,3]
I have to check the sensor docs to find out what order the values are in, but yeah
uhh a quaternion typically represents an axis and a rotation around that axis, but don't worry about that. getting the value from a quat's values directly is painful.
you can probably take a vector like (0, 0, -1), transform it with the quat, then do trig on the X/Z axes of that
Pip
Pip
Nov 14, 2015 03:32
hmm
seems like there would be an easier way but I'm not thinking of one right now. kind of braindead.
Pip
Pip
I have no idea how quat math works
complex numbers
aka magic
Pip
Pip
I have no standard library for this, because it's microcontroller level
oh then you might be really screwed. like that quaternion you're getting, there's no function to just use it to transform a vector?
Pip
Pip
Nov 14, 2015 03:33
I don't think so
But I can check
I've been taking notes and links as I read
it might be part of a vector class instead of the quaternion class, if you have such things, lol
Pip
Pip
Here's the sensor
docs are on that page, but are bad
Here's the math stuff
EYYYY
Oh wait no
Oh wait maybe
Here we go: In the VectorFloat class
        void rotate(Quaternion *q) {
            Quaternion p(0, x, y, z);

            // quaternion multiplication: q * p, stored back in p
            p = q -> getProduct(p);

            // quaternion multiplication: p * conj(q), stored back in p
            p = p.getProduct(q -> getConjugate());

            // p quaternion is now [0, x', y', z']
            x = p.x;
            y = p.y;
            z = p.z;
        }
Does that look correct?
uhh...probably
I would think so
Pip
Pip
How would i use the v(0,0,-1) rotated?
that would have a 3d vector
Wouldn't I have to somehow integrate the three rotations though?
the 3D vector you get back will be pointing in the direction the user is facing
you can ignore its Y axis and do trig on the X/Z axes to get an angle
Pip
Pip
Nov 14, 2015 03:42
Alright, lemme see if I can scratch up some sample code for this
Welp, thanks @IcyDefiance
you figure it out?
Pip
Pip
I need to go to bed; I have to get up super early tomorrow
I did not
I'll be working on this more tomorrow for sure
okay last bit of information
Pip
Pip
I got some basic code to process the quats up but I don't have the sensor wired to actually get some values to test
okay
the trig function you want should be atan(x/z)
Pip
Pip
Nov 14, 2015 03:50
for what
well actually, atan2(x, z)
to get the angle from that rotated vector
Pip
Pip
ah okay
So I just literally plug in the vector's x and z values into it?
might be atan2(z, x)... lol
but yeah that should be it
Pip
Pip
awesome, thank you
Pip
Pip
Nov 14, 2015 03:52
Anyway, thanks a ton Icy. I definitely understand a bit more than I did an hour ago
 
Conversation ended Nov 14, 2015 at 3:52.