tags:

views:

1203

answers:

4

Hello,

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?

+4  A: 

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').

Oz
This is what I was doing. The object moves around a vector with an arbitrary origin, but it is always facing in same direction. I should face the vector's origin.I edited the question to clarify my algorithm.
If I understand correctly, you need to add another rotation, around a vector parallel to the one you mentioned, but that goes through the *center* of the object.
Oz
You are right. I solved it by rotating the object around it's center and then rotating object's position around the given vector.
+1  A: 

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.

Aric TenEyck
Not entirely off topic and a good point...
David Zaslavsky
Fair point. I meant rotating around a vector with an arbitrary origin. I edited the question.
A: 

"Is my method wrong or do I have a bug?"

I'm guessing that your method is wrong:

http://en.wikipedia.org/wiki/Quaternion_rotation http://mathworld.wolfram.com/Quaternion.html

duffymo
A: 

hi how to rotate a line around a center position just like clock but it should move with drag of mouse in any direction at any instance from clock wise to anticlock and vice versa

help me ...........

amit [email protected]

Amit