Sevdat Posted July 29 Share Posted July 29 (edited) Good day, I am confused because from the way I know this is the proper way of doing it: public quat angledAxis(float angle, vec3 rotationAxis){ return new quat(rotationAxis, angle); } public vec3 rotate(vec3 origin, vec3 point, quat angledAxis){ quat q = angledAxis; vec3 v = point - origin; vec3 rotatedOffset = q * v * new quat(new float[] { -q.x, -q.y, -q.z, q.w });; return origin + rotatedOffset; } but for some reason rotatedOffset should be: vec3 rotatedOffset = q * v; So that when the same quat (angledAxis) is used 360 times it reaches to the starting position twice. Shouldn't the quaternion be multiplied with this part? new quat(new float[] { -q.x, -q.y, -q.z, q.w }); so that the rotation is proper? Or am I missing something? Edited July 29 by Sevdat Link to comment

karpych11 Posted July 29 Share Posted July 29 Hello. If I understand correctly, you are trying to rotate a point relative to a given origin using a pure imaginary quaternion. In this case, the multiplication works incorrectly because you need to use quaternion multiplication instead of quaternion and vector multiplication. That is, we use the formula new_v = (q * v) * conjugate(q) as in the definition. The code will look like this: vec3 rotateExplicit(vec3 origin, vec3 point, quat angledAxis) { vec3 v = point - origin; quat pureImaginaryQuaternion = new quat(); pureImaginaryQuaternion.x = v.x; pureImaginaryQuaternion.y = v.y; pureImaginaryQuaternion.z = v.z; pureImaginaryQuaternion.w = 0.0f; pureImaginaryQuaternion = MathLib.Mul((MathLib.Mul(angledAxis, pureImaginaryQuaternion)), MathLib.Conjugate(angledAxis)); vec3 rotatedOffset = new vec3( pureImaginaryQuaternion.x, pureImaginaryQuaternion.y, pureImaginaryQuaternion.z ); return origin + rotatedOffset; } The main difference is that in this version, the vector is converted into a quaternion. Then the multiplication works as expected: the distributive property and the rules of imaginary unit multiplication are used. But you can simply use quaternion-vector multiplication from a math library. In it, the formula from the above example is already transformed: vec3 rotate(vec3 origin, vec3 point, quat angledAxis) { vec3 v = point - origin; vec3 rotatedOffset = MathLib.Mul(angledAxis, v); return origin + rotatedOffset; } 1 Link to comment

## Recommended Posts