In my 3D application I store object's position in a vector and it's rotation around the origin in a quaternion. I need to rotate the object around a vector with an arbitrary origin. I tried converting the position - vectorOrigin and the rotation into a matrix, rotating the matrix and then extracting the position and rotation as a vector and a quaternion from the resulting matrix. The position comes up ok, but the rotation remains constant (the object rotates around the given vector but it always faces in the same direction).
Is my method wrong or do I have a bug?
Rotate Point Using Quaternion Vector For convenient visualization, define the point on the x-y plane. Create a quaternion vector specifying two separate rotations, one to rotate the point 45 and another to rotate the point -90 degrees about the z-axis. Use rotatepoint to perform the rotation. Plot the rotated points.
I'm not sure why do you expect the rotation to change. You have programmatic "creatures" representing the origin point, the destination point, and a rotation. Computing the destination point based on the other two "creatures" shouldn't affect them.
What about the usual approach? If you need to rotate the position (x, y, z) around the point (a, b, c), first translate the position so that the rotation will be around the origin: use (x-a, y-b, z-c) as the position, rotate around the origin as usual to get the new translated position (x'-a, y'-b, z'-c), and translate back and get your new position (x', y', z').
I'm not familiar with quaternions, and maybe this is totally offtopic, but you can't rotate a 3d object around a point, the axis of rotation must be a line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With