Live data from Hacker News

Rediscovering Quaternions

jasonfantl.com

41–50 of 72 posts

Re: Rediscovering Quaternions

#41

The easiest way for me to conceptualize it is to think of it as orientation + rotation. 3 dims for the orientation vector to get the object facing/pointing the right way, then a further 1 dim/var for rotation about that axis. For a total of 4 variables/dimensions 3blue1brown and Ben Eater did a series of interactive videos on the subject that can be explored: https://eater.net/quaternions My favorite demo on this poi…

[deleted]

Re: Rediscovering Quaternions

#42

The easiest way for me to conceptualize it is to think of it as orientation + rotation. 3 dims for the orientation vector to get the object facing/pointing the right way, then a further 1 dim/var for rotation about that axis. For a total of 4 variables/dimensions 3blue1brown and Ben Eater did a series of interactive videos on the subject that can be explored: https://eater.net/quaternions My favorite demo on this poi…

What happens if rotation is zero? Won't (ai +bj+ ck) get multiplied by zero then, and the orientation information is lost?

Re: Rediscovering Quaternions

#43

While they might be theoretically pleasing, I've had trouble seeing the appeal of quaternions for 3D graphics. Recently I was working on some 3D-rendering code from scratch for a project, and I looked into using quaternions for rotation, only to scratch my head at how fiddly they were to apply to vectors. (Also, many resources talking about them focus on their abstract properties at the expense of actual examples, wh…

I found quaternions much more convenient to work with when writing some 3d graphics software for a college course a long time ago.

It's mostly for the same reasons everyone else mentioned, simplifying interpolation and avoiding gimbal lock. I also found the actual operations much easier to implement. I never developed a good mental model of what they actually are, but tried not to let that bother me too much.

Re: Rediscovering Quaternions

#44

The easiest way for me to conceptualize it is to think of it as orientation + rotation. 3 dims for the orientation vector to get the object facing/pointing the right way, then a further 1 dim/var for rotation about that axis. For a total of 4 variables/dimensions 3blue1brown and Ben Eater did a series of interactive videos on the subject that can be explored: https://eater.net/quaternions My favorite demo on this poi…

What happens if rotation is zero? Won't (ai +bj+ ck) get multiplied by zero then, and the orientation information is lost?

If you click through to the interactive example, you can try it! You'll see that the if the above equations are `q`, then full formula to rotate a vector `v` is `v' = q * v * q^-1`

Re: Rediscovering Quaternions

#45
post #38

Earlier quoted context omitted.

Quaternions are automatically orthogonal, whereas matrices can shear and therefore may accumulate floating point distortions under repeated opreations.[0] Think of matrices as computational instructions, which are straightforward but lossy, while quaternions are the canonical "lossless representations". The sweet spot for using quaternions is to use them as intermediate representations of rotation operations, then "c…

Does leaving them unnormalized affect their numerical accuracy? A few sources [0] [1] suggest renormalizing often, but I'm not sure whether it's just dogmatic or if it's actually necessary. It definitely seems less involved than re-orthogonalizing matrices, in any case. (Luckily, for my project, I'm not particularly worried about error, since the only thing being rotated frequently is the camera, and microscopic scal…

As I mentioned, unnormalized quaternions just adds an extra uniform scaling, so it’s just a matter of dividing the final vertex by qq* to remove the scaling.

EDIT: I guess if you use a shitty overzealously reduced version of the quaternion formula then you absolutely need to normalize it constantly, because the reduced formula assumed three degrees of freedom (completely defeating the purpose of using quats in the first place), normalization is then to solve a problem that you caused. But if you use a proper formula then my recommendation is actually that you never normalize your quats, instead only un-scale your vertex at the end.

Re: Rediscovering Quaternions

#46

> These discontinuities are not just an artifact of poor implementation; it can be proven that any representation of 3D rotations using only three values must contain discontinuities. This is a bit pedantic - and the blog post actually does clarify this - but the problem isn't that a 3D representation of representations has "discontinuities" as such, it's that it's not orientable in Euclidean 3D space. It is similar…

That statement is also incorrect.

1. "any representation of 3D rotations using only three values"

That is not representation, that is parametrization. Euler-angle parametrization sometimes fails because it is not a correct parameterization of SO(3) in general by construction, this is why it sometimes fails (essentially, the three consecutive rotations can sometimes effectively collapse into two for certain set of angles, regardless of how you choose your 3 axes, in which case you can't relate 2 independent parameters back to the 3 independent axis-angle parameters). The correct parametrization of SO(3) is the axis-angle parametrization, which can be represented using quaternions or 3D reals matrices.

The "representation", on the other hand, would typically be unit quaternions or 3D orthogonal matrices.

2."it can be proven that any representation of 3D rotations using only three values must contain discontinuities." where is that proof and what discontinuity are you talking about? It sound like he misunderstood what "SO(3) is not simply connected" means. Lie groups are differentiable.

3 parameters are sufficient to represent any 3D rotation. The natural parametrization of all Lie groups, including SO(3), is the axis-angle parametrization, and their elements have the form exp(i θ n.J) where n is a unit vector defining the axis of rotation, θ determines the amount of rotation, and J is a vector of the generators of the corresponding Lie algebra. The "regular" 3D matrix representation in the axis-angle parameterization is obtained with so(3) generators L_x, L_y, L_z in their fundamental representation. Basis quaternions i, j, k (which can be represented by Pauli matrices) obey the same Lie algebra as L_x, L_y, L_z, but the group that it corresponds to (which is SU(2)) is a double cover of SO(3) (up to a sign), so they can still be used for implementing 3D rotations once you pick a sign.

Re: Rediscovering Quaternions

#47

Not detracting from this post, but has anyone else noticed there's a front page post about Quaternions or Kalman filters on about a monthly cadence? Wonder why that is?

Because quaternions are awesome? :) it definitely feels like a discovery when you learn about them first.

Are they?

[Let's remove Quaternions from every 3D Engine] https://marctenbosch.com/quaternions/

Re: Rediscovering Quaternions

#48

Earlier quoted context omitted.

What happens if rotation is zero? Won't (ai +bj+ ck) get multiplied by zero then, and the orientation information is lost?

If you click through to the interactive example, you can try it! You'll see that the if the above equations are `q`, then full formula to rotate a vector `v` is `v' = q * v * q^-1`

Sorry, what you have stated is not very clear. If you use cos(theta) + sin(theta)*(ai + bj + ck) representation as you mentioned, what does happen to the orientation information when sin(theta) becomes zero

Re: Rediscovering Quaternions

#49

Earlier quoted context omitted.

If you click through to the interactive example, you can try it! You'll see that the if the above equations are `q`, then full formula to rotate a vector `v` is `v' = q * v * q^-1`

Sorry, what you have stated is not very clear. If you use cos(theta) + sin(theta)*(ai + bj + ck) representation as you mentioned, what does happen to the orientation information when sin(theta) becomes zero

When theta=0, you have

  q = cos(0) + sin(0)*(ai+bj+ck) = 1 + 0 = 1
That means applying the "rotation" to the vector gives

  v' = q * v * q^-1 = 1 * v * 1^-1 = v
So the output ("rotated") vector is the same as the input, as you would expect for a rotation by 0.

Re: Rediscovering Quaternions

#50
post #38

While they might be theoretically pleasing, I've had trouble seeing the appeal of quaternions for 3D graphics. Recently I was working on some 3D-rendering code from scratch for a project, and I looked into using quaternions for rotation, only to scratch my head at how fiddly they were to apply to vectors. (Also, many resources talking about them focus on their abstract properties at the expense of actual examples, wh…

Quaternions are automatically orthogonal, whereas matrices can shear and therefore may accumulate floating point distortions under repeated opreations.[0] Think of matrices as computational instructions, which are straightforward but lossy, while quaternions are the canonical "lossless representations". The sweet spot for using quaternions is to use them as intermediate representations of rotation operations, then "c…

I get what you mean, but it seems misleading to cite floating point issues with matrices and call quats lossless. Matrices are not inherently imprecise, they have floating point error when you use floating point numbers to represent them, and the same is absolutely true for quats too.

A better word than lossless is perhaps ‘overspecified’ when referring to a 3x3 matrix being used to represent a rotation or orientation. A 3x3 matrix has redundant information in that case (however a matrix is more general and more powerful than a quat). But axis-angle is 4D like a quat too, and more intuitive than a quaternion. Actually normalized-axis-angle (with no scaling) can beat normalized quats, because axis-angle can be a 3D value and quats cannot. Same goes for Euler angles too. In general, if your quats are implemented with floats then applying quat transforms will introduce unwanted floating point scaling that may accumulate under repeated operations (and if you compile to a matrix first then you also have the matrix problem you mentioned).

Post reply on HN