# Tag Info

21

Quaternions solve a few problems elegantly: They are as compact as axis-angle representations (4 scalar values) They are easily converted to and from matrix representations Interpolation works from any start to end angle without special casing They never exhibit gimbal lock You can get around these issues with other representations, but quaternions are a ...

18

There is an entire 600 page book on "Visualizing Quaternions": http://books.google.ca/books?id=CoUB09xzme4C&lpg=PP1&ots=uEdJHsni9y&dq=Visualizing%20Quaternions&pg=PP1#v=onepage&q&f=false The book is actually quite good, covering a wide range of topics. It starts with a good introduction to game related linear algebra, it talks about ...

17

In short You only need to change T in your SQT form. Replace the translation vector v with v' = v-invscale(p-invrotate(p)) where v is the initial translation vector, p is the point around which you want the rotation to occur, and invrotate and invscale are the inverses of your rotation and scale. Quick demonstration Let p be the point around which you ...

14

There are more than one ways to do it. You can calculate the absolute orientation or the rotation relative to your avatar, that means your new orientation = avatarOrientation * q. Here is the latter one: Calculate the rotation axis by taking the cross product of your avatar's unit forward vector and the unit vector from avatar to target, the new forward ...

14

All of the canonical rotational formulas used to derive your rotation matrices are for rotation about the origin. If you would like instead to apply that rotation around a specific point, you must first offset the origin -- or, equivalently, move the object so the point you want to rotate about is at the origin. Consider the 2D case first, because it is ...

11

As Nathan Reed and teodron exposed, the recipe for rotating a vector v by a unit-length quaternion q is: 1) Create a pure quaternion p out of v. This simply means adding a fourth coordinate of 0: 2) Pre-multiply it with q and post-multiply it with the conjugate q*: 3) This will result in another pure quaternion which can be turned back to a vector: ...

10

Quaternions are associative: you mention that your solution is: newRot = oldRot * (inverse oldRot * worldRot) * oldRot which is the same as: newRot = oldRot * inverse oldRot * worldRot * oldRot which is the same as: newRot = identity * worldRot * oldRot newRot = worldRot * oldRot which actually brings you back to what's really happening: ...

10

Linear Algebra is the foremost discipline for 3d graphics programming simply because it's the mathematical language for describing spatial geometry. Your other three topics are really just subsets of linear algebra: Vectors are a way of thinking about points in space Matrices are ways of thinking about transformations of space and objects: translating ...

9

One of the visualization methods I like is to represent quaternion (orientation in 3d space) as vector (x,y,z components) + spin (the rotation around that vector, stored in w component). If you are looking for some online visualizer for quaternions, you can always use wolframalpha: http://www.wolframalpha.com/input/?i=quaternion%3A+0%2B2i-j-3k&lk=3 ...

9

Given only a point and a direction there is no defined 'right' or 'left'. Imagine being a falling raindrop, which direction is right or left for you in that case? In order to calculate (or even define) a right or left you need two directions, typically forward and up. You seem to already have a forward direction, so you need to define a up direction. ...

8

While you haven't shown the necessary code to verify my assumption here, I can almost guarantee that your problem is actually that this line: cameraRot.ToAxisAngle(out axis, out angle); is returning an angle value expressed in radians, while GL.Rotate(angle, axis); wants angle to be provided in degrees. To fix it, you need to convert the angle value ...

8

You are correct that a combined axis-angle representation like the one you describe has a stronger expressive power than many other systems because it can more conveniently store a rotation speed. However, in practice, people actually use quaternions and 3×3 matrices to manipulate rotations a lot more than just represent them. One typical operation is the ...

7

For the motion curve, I'd suggest using Hermite curves. You simply give a starting point/velocity and an ending point/velocity, and it creates a nice and smooth curve between those two. Use the ending point/velocity of the first pair of points as the starting point/velocity of the next pair of points and you have a nice long and winding curve that is ...

7

I visualize my quaternions as three-dimensional vectors (direction + length) with a bit to the side to be able to show rotation along the vector's axis. It's a common way to visualize rotation vector in physics, but the name escapes me.

7

You could decompose your quaternion into a yaw/pitch/roll set of angles, but that's overkill usually. Instead of composing your quaternions like this: cameraOrientation = cameraOrientation * framePitch * frameYaw; Try this: cameraOrientation = framePitch * cameraOrientation * frameYaw; It will then never generate tilt/roll and is equivalent to storing ...

7

It seems that most engines do have those rotation methods. XNA has one in it's Vector3 struct. // Returns a new Vector3 that results from the rotation. public static Vector3 Transform ( Vector3 value, Quaternion rotation ) three.js has the function exactly as you wrote it. In Unity's case, their Vector3.Rotate() method might be internally ...

6

First of all, q^(-1) is not -q/magnitude(q); it's q*/(magnitude(q))^2 (q* is the conjugate; that negates all the components except the real one). Of course, you can leave off the division by the magnitude if all your quaternions are normalized already, which they typically would be in a rotation system. As for the multiplication with a vector, you just ...

5

Frankly, I would continue to use quaternions if you are already using them and comfortable with them. It doesn't seem to me like it's worthwhile to build out a whole system -- if even it's a small one -- to handle fixed sets of rotations when you can simply do that on top of a system that handles arbitrary ones. Furthermore, you can address the floating ...

5

First observation: The inverse of q is not -q/magnitude(q), that is completely wrong. Rotations with quaternions imply that these 4D complex number equivalents have unitary norm, hence lie on the S3 unit sphere in that 4D space. The fact that a quat is unitary means that its norm is norm(q)^2=q*conjugate(q)=1 and that means that the quat's inverse is its ...

5

For an FPS camera you usually don't want roll and are limited to +/- 90 degrees pitch, so I'd just keep track of the current state using yaw and pitch angles. The full power of quaternions isn't really helpful for this. You can still convert the yaw/pitch angles to and from quaternions in case you want to transition between the FPS camera and animated ...

5

Expressing rotations with quaternions can be done from an axis-angle representation, but not in a single way. For that same axis angle (w, a) pair, you get two quaternions performing the same task. One has its components based directly on the w vector and the a angle, the other has the same components, but negated. This is normal, since they describe the ...

5

Rotating a point p using a quaternion q is done with q * [0, p] / q. Replacing q with -q has absolutely no effect on the result. If your rotations "go the wrong direction" when the sign of the quaternion changes, then the problem lies in the way you use the quaternions to rotate points.

5

1) The non-scary way to do 90-degree rotations is to swap a set of axes, and negate one of them: Rotated along x-axis: swap Y/Z to Z/-Y (a,b,c) -> (a,c,-b)

5

The problem is neither of the conversion functions, the problem is the input matrix. It is not an affine transformation matrix, because the rotational part is not a pure rotation matrix, it has one or more flipping/negated axis in it. Only Rotation matrices can be converted to quaternions. More specifically rotation matrices are orthogonal matrices with ...

5

Your problem is purely two-dimensional, in the plane formed by the sphere centre and your source and destination points. Using quaternions is actually making things more complex, because in addition to a position on a 3D sphere, a quaternion encodes an orientation. You may already have something to interpolate on a circle, but just in case, here is some ...

5

rotationVelocity += addedRotation is actually fine. Angular velocity is a vector and adds in the usual way. The part you may be missing is that in your description of the desired motion, you have a rotation around a constant axis (the global up-vector) combined with a rotation about a rotating axis (the ship's roll axis, which is rotating because of the ...

5

Each orientation in 3D space can be represented by 2 distinct unit quaternions, q and -q (component-wise negated q). For instance the orientation represented by the 3x3 identity matrix I can be represented by 2 quaternions: q: { 0, 0, 0}, 1 -q: {-0, -0, -0}, -1 Both represent the same orientation in 3D space, their dot product is exactly -1, each of ...

4

You do not necessarily need an alternate visualization technique for quaternions versus matrices. When you visualize your rotation matrix as the 3 axes gizmo, what you're really visualizing is an orientation. Since the quaternion also represents an orientation, consider continuing to use your 3 axes gizmo as your mind's eye visualization object. Rarely, ...

4

Here's a great intro http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-2/

4

Torque and angular momentum should probably be represented as ordinary 3D vectors, not quaternions. Angular momentum vectors add according to the parallelogram rule, and torque is the time derivative of angular momentum, so you apply a torque to change angular momentum exactly the same way as applying an acceleration to change velocity. Then you multiply ...

Only top voted, non community-wiki answers of a minimum length are eligible