Posted July 15, 2025 by Ascyt
#update #major #feature
So for a while I’ve been struggling with handling 4D rotations internally.
Right up until now I used to use Euler angles (rotating a point using an angle in the planes XW, YW, ZW, XY, XZ, YZ) and I’ve been having a lot of issues:
So I found a pretty weird workaround. Basically, instead of rotating the camera, I continously moved and rotated every vertex relative to the camera and rendered that. This worked, but it had a couple of issues:
Most of the time, when the problems of Euler angles are mentioned, “Gimbal Lock” is a magic word that’s used. Do I understand what it is? Kind of, yeah. But I don’t think this does a great job at explaining the practical issues that I had at least with Euler angles.
So okay. What’s the alternative? For 3D rotations, quaternions. So I looked up how to use those in 4D. Apparently, it’s possible, but not with a single quaternion - to be able to describe every rotation in 4-dimensional space (also called SO(4)) you need two quaternions: A quaternion pair.
Cool. In theory. Well in practice as well, unless you’re an idiot like me. See, for the longest time I not only had the difficult task of figuring out what the heck quaternions really are in the first place, but also how to use them in 4D?? And since quaternions are 4D numbers, you can imagine it was a pain to not find resources about quaternions in general but specifically about quaternions to describe 4-dimensional rotations. The fact that there were barely any resources on this to begin with did not make this better.
In my research, I also stumbled upon what seems to be the most commonly used approach to handle 4D rotations: Rotor4. Whatever the hell that is. Since I didn’t want to bother to start from 0 again, I decided to stick with quaternion pairs unless I find an absolute reason to not use them.
Up until I stumbled upon this StackExchange answer by Jim Belk. Even though my smooth brain nearly had a short circuit trying to understand this, this answer had basically all information that I had needed. After a lot of trial and error, I finally got quaternion pair rotation to work.
And honestly, it’s beautiful. You can basically use the Rotation4 class I made like a normal quaternion, but for 4D rotation. It uses two quaternions internally, leftQuaternion and rightQuaternion, and applying a rotation to a point is super easy, whether it is in world space or relative to the vector itself, and the order does not matter, both quaternions can be in any order when applied to a vector.
I don’t know why most 4D projects I’ve taken a look at seem to use the Rotor4 approach; I guess maybe for even more complex tasks such as a physics engines quaternion pairs might not make the cut either. Though I assume it really just came from a thought process like “it’s not possible to use a single quaternion to represent four-dimensional rotations, so that would mean I’d have to use something completely different”, or maybe because one person did it and so everyone else just followed. Or maybe Rotor4 is actually superior to quaternion pairs, I don’t know. For now it’s working pretty well at least, though.
If you’re curious about my implementation, here are the relevant parts:
Other changes I made in this update:
FixedRotationalPlanes scene. It contains all four axes with all six planes of rotation, and a 3D cube next to it.Nobody’s probably going to see this but hey, it’s cool to get my thoughts written down somewhere at least :) Plus, if even just one person reads this develog and is at least remotely interested, I can consider it a win.