# Multiply quaternion by vector3... how is it done (mathematically)?

I’m not asking for a “transform.rotation * Vector3.forward = unit direction”. What I am asking is more mathematical than that.

What are the mathematical steps taken in Unity by the * operator to multiply these matrices which are not uniform in dimension?

Because correct me if I’m wrong, but shouldn’t it be impossible to multiply a 4x4 matrix with a 3x1 matrix, even when transposed to a 1x3 it should not be possible.

I am trying to form a better understanding of quaternions and spacial rotations.

As the docs say, using Quaternion*Vector3 is shorthand for calling a Rotation by the Quaternion on the Vector3. It is not actually a Matrix multiplication; in fact, a quaternion is not a matrix, instead it is more akin to a four-dimensional complex number.

If you wish to know more about how Quaternions are used to generate rotations, Wikipedia’s article is a good source. In short, you can think of the XYZW values of a Quaternion as a rotation axis vector described by XYZ and a rotation angle described by W. In order to apply the rotation defined by the quaternion to a Vector3, a standard 3X3 rotation matrix is formed from the quaternion XYZ similar as to how one would form a 3X3 rotation matrix from a set of Euler angles φϑψ. In both cases, the variable set defines a rotation but in order to be used, it must be transformed to a form appropriate for the space you are operating on - in this case, a 3X3 rotational matrix for 3-dimensional euclidean space.
The advantage of using quaternions is two-fold: First, while ‘bigger’ (four values instead of the three Euler ones) to store the rotation matrix can be calculated much faster as it does not require any trigonometric functions. Second, they avoid Gimbal Lock.

Please keep in mind that there is a reason you are repeatedly told not to modify quaternions by hand whenever looking into the issue! While not outright voodoo, a quaternion’s data structure is rather complex and does not lend to natural understanding. In practically every case, the inbuilt functions provided for accessing and modifying quaternions will be easier, faster and more reliable than custom modifications!