Hacker News new | ask | show | jobs
by TipVFL 2845 days ago
Quaternions recently made me look pretty smart.

I was consulting at a company that's developing a VR real estate app, and the first thing I did was check to see whether they were calculating their rotations with quaternions.

It was easy to do, I just looked straight up and then turned my head to the right. My view rotated to the left, and I almost vomited. I immediately ripped the headset off and said, "You're using euler angles to calculate rotations, you need to use quaternions."

I felt pretty good about finding the biggest flaw in their system in 3 seconds.

4 comments

Why are they using their own custom engine with a buggy VR integration in 2018? I assume they have some kind of business reason, but based on your story it seems like whatever engineer(s) they hired couldn't follow basic integration samples and documentation.
There are many reasons to not use Unity or Unreal. One major one being that they have restrictive licenses.

The best selling/best graphics fidelity (imo) VR game Lone Echo has its own custom game engine.

Even if you're writing your own engine from scratch, VR runtimes provide orientation information directly to the engine as a 4x4 transform matrix. They would have to ignore all the documentation and go far out of their way to somehow regress to euler angles, and are likely introducing other precision issues in doing so.
4x4 transform matrices typically represent 3-space transformations with homogeneous coordinates. Rotation matrices in this framework are effectively the same thing as Euler angles. They are not quaternions.
If you want to get pedantic they're also not euler angles, they're 4x4 transformation matrices.

You can pick out euler angles just as easily as calculating the quaternion by taking the basis vectors through the matrix and extracting it from there.

I'm aware of reasons for using a custom engine over Unity or Unreal, my question is what is this firms specific reason for not going that route. Also, Ready at Dawn has been developing that engine for years, and has world class engine programmers that know how to implement headtracking correctly, so the comparison isn't fair in this case.
> I was consulting at a company that's developing a VR real estate app, and the first thing I did was check to see whether they were calculating their rotations with quaternions.

You had better checked whether representations are represented via spin groups (which can be represented via Clifford algebras). These work in every dimension in opposite to quaternions.

EDIT: And via pin groups (also representable via Clifford algebras), also reflections can be reprented (recall that the composition of two reflections is a rotation and any rotation can be represented this way).

VR is by definition 3D, so quaternions should be enough, right? The reflections method could also be done with quaternions.

Full abstraction over dimension is certainly interesting, but often not necessary.

> Full abstraction over dimension is certainly interesting, but often not necessary.

Already the capability that is works both in 2D and in 3D is in my opinion reason enough.

What folks ship as a product is trivial quaternions.
Was it because of https://en.wikipedia.org/wiki/Gimbal_lock ?

Apollo 11 engineers made the same mistake. :)

For Apollo, it wasn't so much a "mistake" as a conscious decision to save weight. The Gemini IMU used 4 gimbals, and so avoided the issue entirely. Apollo dropped the weight of the extra gimbal and instead required the pilots to avoid flying in certain orientations.
I would characterize this more as a hardware engineering choice, with associated work around in software (don't rotate the spacecraft through gimbal lock/Euler angle singularity).

Disclaimer: IANARS

Yes large differences in orientation will make Euler angles gimbal lock. And it looks strange, even for small differences in orientation.

https://www.youtube.com/watch?v=Ocoibc7MoKg

The Shuttle program used quaternions, although the ISS apparently uses a definition that is easier to read by sight: http://webcache.googleusercontent.com/search?q=cache:-ivJED8...
I wrote a simple version of Google Earth for the Microsoft Surface in 2008 or so (back when Surface was a computer in the shape of a table with a touch interface). I felt pretty smart when I invented quaternions using matrices for rotating the globe, and then later realized what I was doing.
Yeah, no. If you're using matrix-based transforms, you're not using quaternions.

Edit: I'm oversimplifying. There's no reason you can't use both. But if you're exclusively using matrices, then by definition you're not using quaternions.

> I invented quaternions using matrices

what

I read that as "I was representing my dimensions as vectors and figured out a way to use 4D matricies for the math to work out and later found out that quaternions were a thing"
Am I correct suspecting quaternions were tensors?