Parameter for quat attribute XML

Discussion in 'Modeling' started by Delay Lama, Dec 14, 2018.

  1. Good Morning,

    I am new to MuJoCo and I am asking two noob question. This is about the Parameters in the quat attribute in xml.

    1) I assume that the order of parameters is (w, x, y, z). Can someone confirm this?

    2) I found many examples and information on how quats are working, noted and calculated. One is the following
    http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/ :
    // RotationAngle is in radians
    x = RotationAxis.x * sin(RotationAngle / 2)
    y = RotationAxis.y * sin(RotationAngle / 2)
    z = RotationAxis.z * sin(RotationAngle / 2)
    w = cos(RotationAngle / 2)
    And right now I don't know how to handle this information.
    If i want to use a quat in XML to rotate my Object, do I just define the rotation Vector via (X,Y,Z) and (using right hand rule) the arc by W. Or do I have to insert the calculations above.
    a) (angle, x, y, z)
    or
    b)(cos(angle/s), x*(angle/2), y*(angle/2), z*(angle/2) )
    I would guess it is the first one but I am not sure.

    Thank you for clarification on this one and have a nice day

    Delay Lama


     
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    the order is q = (w,x,y,z)

    if you want to rotate by angle theta (in radians) around axis v where v is a unit vector, set:

    w = cos(theta/2)
    (x,y,z) = sin(theta/2) * v

    same as in the tutorial you referenced
     
  3. lets see.
    My test setup is as following.
    Starting from the point (0 0 0) I marked the main axes in positive directions.
    (x, is Blue)
    upload_2018-12-14_11-9-33.png
    I inserted a "tube" in X direction. My goal is, to turn it to the (1,1,1) vector.
    upload_2018-12-14_11-10-27.png
    The rotation axes is (-1 -1 1) [x, y, z]. And I guess i need to rotate around 45° so 1/4 of PI.

    My first attempt was to insert the raw vector and the angle (I tried degree and radiant):
    [quat="-1 -1 1 0.785"] and [quat="-1 -1 1 45"] both turned out wrong.

    Next try is to calculate the values according to the tutorials formula:
    x = RotationAxis.x * sin(RotationAngle / 2) => -1 * sin( (1/4 * pi) / 2 ) = -0,382
    y = RotationAxis.y * sin(RotationAngle / 2) => -1 * sin( (1/4 * pi) / 2 ) = -0,382
    z = RotationAxis.z * sin(RotationAngle / 2) => 1 * sin( (1/4 * pi) / 2 ) = 0,382
    w = cos( (1/4 * pi) / 2) = 0,923

    => <geom type="box" pos="0 0 0" size="5 0.5 0.5" rgba="1 1 1 1" quat="-0.382 -0.382 0.382 0.923"/>
    upload_2018-12-14_11-17-57.png
    It looks way better, but still a bit of.

    So, i guess it is correct to calculate the formal and and use the results as the quats parameters.
    Do I have a wrong thought or am I heading in the right direction and calculations are just bit of?

    And a second question, is there a reason why the formula isn't integrated in the quat procedure? It seems that all needed information are at hand.


    EDIT: quat="-0.382 -0.382 0 0.923" this seems to do the trick. now I just have to figure our how to rotate the stick.
     
    Last edited: Dec 14, 2018
  4. Emo Todorov

    Emo Todorov Administrator Staff Member