Live data from Hacker News

Rediscovering Quaternions

jasonfantl.com

61–70 of 72 posts

Re: Rediscovering Quaternions

#61

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…

Imagine you are creating a 3D flight or space simulator. You would need to use the quaternion system to avoid your camera/craft from experiencing gimbal lock.

It can have other uses for things like inverse kinematics too.

Re: Rediscovering Quaternions

#62
post #61

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…

Imagine you are creating a 3D flight or space simulator. You would need to use the quaternion system to avoid your camera/craft from experiencing gimbal lock. It can have other uses for things like inverse kinematics too.

Never having done anything aviation simulation related I've never properly understood this.

At least for a simple camera I've done that with something that resembled a spherical coordinate system (although maybe not following the usual conventions) and it didn't experience gimbal lock. Effectively the axes rotate with you. It's also very intuitive to work with the code, although probably not very efficient compared to other approaches (but hey it's a camera it's not like there's 10k of them). Once you have the camera orientation you can derive a corresponding rotation matrix to apply to the scene geometry.

I guess what I'm trying to ask is if there's any reason other than efficiency not to do something like that when modeling craft and the like?

Re: Rediscovering Quaternions

#63
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…

As someone not at all really familiar with maths/3D stuff, your comment gives me some relief that should I want to do any for hobby projects, I can use quaternions to avoid accumulating floating point errors.

Re: Rediscovering Quaternions

#64

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…

> 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 Something's missing. Orientation in 3D space is a two-dimensional quantity; you would never need three dimensions to express it. The third dimension has t…

Direction in 3D has two degrees of freedom, orientation has three.

Re: Rediscovering Quaternions

#65

Earlier quoted context omitted.

If you a explaining this to the average American, you are going to have to start a bit further back than a "Plane".

A plane is just a burrito.

And monads are like burritos. Therefore, monads are like planes. How shall we represent diverted luggage?

Re: Rediscovering Quaternions

#66

Earlier quoted context omitted.

yes, that's the module i learnt about them in during college. IMHO I think for me they're interesting because it felt like mathematically they straddle the line of being nearly impossible for me. I could just barely do them and felt very accomplished when I could. Anything else was either impossible or easy by comparison. assuming my maths skills are average here then most people have similar experiences with them.

What in particular did you find difficult about dealing with them?

There was something called a slerp that allowed you to get an object to rotate from on orientation to another, similar to a linear interpolation.

This was fine for some things. but if you wanted something to rotate but only in a certain way it was annoying as sometimes it would get from A to B, but go through Z during its rotation.

Getting the order or multiplications right too.

Re: Rediscovering Quaternions

#67

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?

Others have mentioned game dev, but they're also essential for guidance, navigation, and control - spacecraft, aircraft, robotics, etc.

Re: Rediscovering Quaternions

#68

Earlier quoted context omitted.

Only if you’re describing orientation as two orthogonal rotations. I’m saying think of it like a ‘pointing’ vector that defines the axis of rotation. And such a vector does require 3 components in 3d space

Yes, a three-dimensional vector is a combination of a 3D orientation and a magnitude. An orientation by itself doesn't have three dimensions. The surface of a sphere is a two-dimensional space. > Only if you’re describing orientation as two orthogonal rotations. No, the space has the dimensionality it has. You may choose to describe a 3D orientation with more than two numbers, but you won't stop it from being a two-d…

Orientation would conventionally be a member of SO(3), which is a 3-dimensional manifold.

Your comment is essentially correct if you replace the word "orientation" with "direction", though.

Re: Rediscovering Quaternions

#69
post #61

Earlier quoted context omitted.

Imagine you are creating a 3D flight or space simulator. You would need to use the quaternion system to avoid your camera/craft from experiencing gimbal lock. It can have other uses for things like inverse kinematics too.

Never having done anything aviation simulation related I've never properly understood this. At least for a simple camera I've done that with something that resembled a spherical coordinate system (although maybe not following the usual conventions) and it didn't experience gimbal lock. Effectively the axes rotate with you. It's also very intuitive to work with the code, although probably not very efficient compared t…

How do you represent the viewports roll angle?

Re: Rediscovering Quaternions

#70
post #69

Earlier quoted context omitted.

Never having done anything aviation simulation related I've never properly understood this. At least for a simple camera I've done that with something that resembled a spherical coordinate system (although maybe not following the usual conventions) and it didn't experience gimbal lock. Effectively the axes rotate with you. It's also very intuitive to work with the code, although probably not very efficient compared t…

How do you represent the viewports roll angle?

Suppose unit X is viewport direction and unit Y is viewport horizontal. Since the axes follow you with each rotation the viewport direction is always the X unit vector even after rotation. So the viewport roll angle is a rotation about X.

Future user control inputs (ie a 4th rotation step) happen in this rotated space, and then you normalize the result so you only ever need 3 instead of 4 rotations.

It's been several years since I did this so hopefully I didn't mess up the explanation. Again I realize it isn't computationally efficient but there's only the one camera and it let me have code that was minimal and easy to reason about. Presumably if I were simulating 10k airplanes or whatever this wouldn't be a good idea.

Post reply on HN