There is a point in space described by 3 numbers: x, y, z

There is a rotation angle described by quaternion W, X, Y, Z

You need to rotate the point around the center of coordinates (0,0,0) and get its new coordinates.

How can this be done at all?

For example, if a point has a position of 0.10.0, and the quaternion describes a rotation around the axis by 180 degrees, the output should be 0, -10.0

  • @ AndreiNOP is excellent, and now for quaternions ;-) - Kromster
  • In any case, I do not understand how to use the rotation matrix. - Crantisz
  • one
    @Crantisz, take the matrix Mz(180) = ((-1 0 0) (0 -1 0) (0 0 1)) and multiply by your vector ((0) (10) (0)) , it turns out just ((0) (-10) (0)) - Andrey NOP

1 answer 1

I tried the rotation matrix from the comment :

enter image description here

This is what happened:

 function rotate_direction_by_q(a,b){ var w=b[3]; var x=b[0]; var y=b[1]; var z=b[2]; var out=[]; out[0] = a[0] * (1 - 2*y*y - 2*z*z) + a[1] * (2*x*y - 2*z*w) + a[2] * (2*x*z + 2*y*w) ; out[1] = a[0] * (2*x*y + 2*z*w) + a[1] * (1 - 2*x*x - 2*z*z) + a[2] * (2*y*z - 2*x*w) ; out[2] = a[0] * (2*x*z - 2*y*w) + a[1] * (2*y*z + 2*x*w) + a[2] * (1 - 2*x*x - 2*y*y) ; return out; } 

I take the quaternion from the Blend4web engine. There for some reason W goes at the end, therefore w=b[3] a not w=b[0]

We are testing a 90 degree rotation:

 кватернион (с неправильным w): [0, 0, 0.7071099877357483, 0.7071099877357483] координаты: [0,10,0] результат: [-10.000090695113002, -0.00009069511300197064, 0] 

Works!