Skip to main content
24 votes
Accepted

Using Quaternions: What can I do with them? (without the maths)

Multiplication At least in terms of Unity's implementation of Quaternions, the multiplication order described in the question is not correct. This is important because 3D rotation is not commutative. ...
DMGregory's user avatar
  • 135k
15 votes

Using Quaternions: What can I do with them? (without the maths)

Where's the dot product used? In Unity, one of the most common users of the dot product is whenever you check if two quaternions are equal via == or ...
Luke Briggs's user avatar
11 votes
Accepted

Is adding quaternions a useful operation?

I can think of two reasons: if your quats represent infinitesimal rotations, adding them together actually yields the composite rotation, provided the result is infinitesimal too (i.e. an element of ...
teodron's user avatar
  • 3,301
7 votes

Switch axes and handedness of a quaternion?

To convert the Quaternion, we need to convert the imaginary part (xyz) which represents the axis of rotation into the destination coordinate system. In this case, that means exchanging x & y while ...
DMGregory's user avatar
  • 135k
7 votes
Accepted

Unwanted roll when rotating camera with pitch and yaw

As I explained above, this is not an issue with quaternions. Quaternions just represent your rotation. The problem is that you have mutually conflicting goals for this rotation: The camera can look ...
DMGregory's user avatar
  • 135k
7 votes
Accepted

Rotate from Current Rotation to Another using Angular Velocity

"maybe due to the gimbal nature of Vector3 for angular velocity" ...using Vector3 for angular velocity does not entail gimbals, but converting it to Euler angles does. Angular velocity is ...
DMGregory's user avatar
  • 135k
7 votes
Accepted

Converting a quaternion in a right to left handed coordinate system

A quaternion can be thought of as an angle-axis representation: quaternion.xyz = sin(angle/2) * axis.xyz quaternion.w = cos(angle/2) So, converting them between ...
DMGregory's user avatar
  • 135k
6 votes

How to express and verify euler rotation limits in Unity

Euler angles aren't necessarily a good way of expressing limits over arbitrary ranges, as their behaviour close to zero is very different from their behaviour away from zero. Below I've visualized ...
DMGregory's user avatar
  • 135k
6 votes
Accepted

Direction vector to quaternion

From http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/ ...
Bram's user avatar
  • 3,729
6 votes
Accepted

Euler angle and Quaternion conversion become weird when yaw is bigger than 90 degrees

Your current code assumes it's always going to get Euler angles where x is between ±90° and z is close to 0. Meanwhile, glm wants to return Euler angles that are standardized so that y is between ±90°,...
DMGregory's user avatar
  • 135k
6 votes

Combining Quaternion Rotations

Multiplying two quaternions gives you a quaternion equivalent to performing the two rotations they represent in sequence. ...
DMGregory's user avatar
  • 135k
5 votes

Convert quaternion to a different coordinate system

Summarizing your two coordinate spaces: ...
DMGregory's user avatar
  • 135k
5 votes

Unity Quaternion.LookRotation meaning

Quaternion.LookRotation(forward, up) constructs an orientation quaternion that... rotates an object's local z+ axis (0, 0, 1) — the blue arrow on its local ...
DMGregory's user avatar
  • 135k
5 votes

Does gimbal lock occur only when a combination of local and world rotation axis are used?

Gimbal lock occurs when your internal structure for storing/composing rotations uses a gimbal model: Image via Wikipedia, attributed: "By Lookang many thanks to Fu-Kwun Hwang and author of Easy ...
DMGregory's user avatar
  • 135k
5 votes
Accepted

Understanding how to use Quaternion to rotate object

Explaining why quaternions work the way they do and their relation to mainstream linear transformation rotations would require some more advanced mathematics knowledge regarding group theory and how ...
PentaKon's user avatar
  • 348
4 votes
Accepted

LookRotation() make X axis face the target instead of Z

I've answered a few flavours of this before. The basic idea is to chain together two rotations: one that takes the axes you want to align and points them along z+ and y+ respectively, and then the ...
DMGregory's user avatar
  • 135k
4 votes
Accepted

How to smooth rotations?

Yes, in fact that's what quaternions are often used for - interpolating between two different orientations. Other methods of representing orientation suffer from issues like gimbal lock and wrap-...
congusbongus's user avatar
  • 14.8k
4 votes
Accepted

Storing transformations in game objects. (GLM, C++)

My general recommendation is to keep both the source components of your transformation for ease of manipulation: local translation vector local orientation quaternion local axis-aligned scale triplet,...
DMGregory's user avatar
  • 135k
4 votes

GLM conversion from euler angles to quaternion and back does not hold

The results are not what you expect, but they are not wrong. It’s just that for a given orientation there are at least two “paths” through Euler angles that lead there. For instance, the identity ...
sam hocevar's user avatar
  • 23.9k
4 votes
Accepted

How does Unity know where the character is facing?

It doesn't know. What it does is point the local z axis of the object (that's the blue arrow you see in the scene view when selecting its local transform gizmo) in the ...
DMGregory's user avatar
  • 135k
4 votes
Accepted

How does Unity's FromToRotation work? A major part of its behavior seems undocumented

FromToRotation chooses the shortest possible rotation that maps fromDirection to toDirection....
DMGregory's user avatar
  • 135k
3 votes
Accepted

Quaternion not giving correct value back. What am I doing wrong here?

Rounding. If you attach the debugger and look at the values of your quaternion: You'll see that the values are just too small to be displayed with one tenth precision, as the debug value is ...
House's user avatar
  • 73.3k
3 votes

Applying angular velocity to quaternion

In the following I use a vector hat to represent a quaternion and a unit vector hat to represent a unit quaternion. Let q(t) represent the quaternion rotation at any point in time. Let r be a ...
DarthRubik's user avatar
3 votes
Accepted

How can I min-max quaternions?

Alright so I figured out an even more ideal solution. The way I was trying to solve the problem was going to lead to more issues than I needed to deal with, so instead I slept on the problem and ...
Yattabyte's user avatar
  • 1,033
3 votes

How can I min-max quaternions?

I bit on the mathematical side, but here's a Q & A on MSE on computing quanternion distance. Using that you could do something like: ...
Pikalek's user avatar
  • 12.4k
3 votes
Accepted

How to orbit an object around another object in an oval path in Unity?

You may translate the orbiting object with the coordinates of an elliptical path. You can get the x and y values from the equations. x = centerX + (semi-major * sin T) y = centerY + (semi-...
Sourav Paul Roman's user avatar
3 votes
Accepted

Unity : how to Rotate GameObject back to Indentity position?

I'd usually approach it like this: ...
DMGregory's user avatar
  • 135k
3 votes
Accepted

Euler (right-handed) to Quaternion (left-handed) conversion in Unity

Three points we need to consider: Matrices and quaternions in Unity multiply from right to left, if we think of each subsequent rotation being applied with regard to the world axes: ...
DMGregory's user avatar
  • 135k
3 votes
Accepted

Relative quaternion rotation (delta rotation) produces unstable results

Thanks to Neal on Mathematics Stackexchange I found out that my code to calculate relative rotations was indeed in the wrong order (I took it from Unity Anwers which seems not to be the correct way to ...
AtiX's user avatar
  • 61

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