Archive for the ‘Mathematics’ Category

The Klein Bottle and the 4th dimension [4D Toys v 1.7]

Tuesday, December 14th, 2021

One of the shapes people requested the most for 4D Toys is the Klein Bottle, so I finally added it!

I originally wasn’t very keen on adding the Klein Bottle for a strange reason: because it’s a 2D shape when sliced it would give thin 1D lines, which are obviously too thin to be interesting to look at. But people kept requesting it, and after thinking about it I figured I could give thickness to the lines by sweeping a circle across the 2D surface to get a 3D surface. This would look way better than simply extruding the Klein Bottle in 4D.

I also wanted to use this update as an opportunity to make a great video about Klein Bottles because the current ones on YouTube are in my opinion unnecessarily confusing. For example I don’t think it’s good to start with how the Klein bottle is two Möbius strips glued together. And I knew I could make better illustrations of the constructions.

Also, and importantly, none of the previous Klein bottle videos on YouTube properly explain the 4D part of it (the fact that a Klein Bottle has to self-intersect in 3D, but not in 4D). I was uniquely suited to fix that, ahah.

 

 

In the end, I am very proud of the illustrations I came up with. For example: showing the exact same perspective / construction for the Möbius Strip and the Klein Bottle really makes it clear what is going on! And as a bonus you get how the Klein Bottle is made out of two Möbius strips in an incredibly straightforward way…

It was obvious to me that the same construction could be done in higher dimensions to make what I call a “Spherinder Klein Bottle” which is a 3D version of the 2D Klein Bottle. Well, technically the “thickened” 2D Klein bottle in 4D Toys is also three-dimensional, but in a less interesting way since it’s just the Cartesian product of the 2D Klein Bottle with a 1D circle… Anyway, interestingly it looks almost simpler when sliced than the 2D Klein bottle.

Relatedly, because people have asked me before: yes there is a Klein bottle in Miegakure, and it shows up in a yet another unexpected way.

As always, thank you for your patience and enthusiasm!

By the way, I’ve decided to more seriously update the Patreon I originally made for my quaternion article/video. In many ways Miegakure is more than a game: It is revolutionizing how people explore scientific concepts with games, its YouTube channel is an educational tool in its own right with millions of views and many thousands of subscribers, scientific research developed for the game is published alongside it, etc… If you would like to support us, the Miegakure team would be very grateful. I will also post exclusive previews of what we are working on!

SIGGRAPH 2020 talk for my technical paper: N-Dimensional Rigid Body Dynamics

Tuesday, January 5th, 2021

It’s very exciting for work from a game (and a first for an indie game) to be presented in the SIGGRAPH Technical Papers program! Thank you all for your patience during development of the game, as you can see it can get pretty involved, ahah!

Link to the paper

SIGGRAPH 2020 Technical Paper: N-Dimensional Rigid Body Dynamics

Thursday, May 7th, 2020

Excited to announce that my technical paper “N-Dimensional Rigid Body Dynamics” was accepted to SIGGRAPH 2020! Very proud to present research developed for 4D Toys & Miegakure at such a prestigious conference.

Here is the link to the paper and the abstract:

I present a formulation for Rigid Body Dynamics that is independent of the dimension of the space. I describe the state and equations of motion of rigid bodies using geometric algebra. Using collision detection algorithms extended to nD I resolve collisions and contact between bodies. My implementation is 4D, but the techniques described here apply to any number of dimensions. I display these four-dimensional rigid bodies by taking a three-dimensional slice through them. I allow the user to manipulate these bodies in real-time.

Btw I believe it is basically unheard of to have work from an indie game presented in the SIGGRAPH technical papers track?

The paper is full of really fun and beautiful math (obviously Geometric Algebra based, see my recent article) that makes me happy. One reviewer called the work “whimsical,” and they’re not wrong, ahah.

Most of this work (including writing the paper) is from ~2012, but I added a section on the (4D) Dzhanibekov effect at the suggestion of the reviewers. Many thanks to them for helping me greatly improve the paper.

Interactive Article/Video: Let’s remove Quaternions from every 3D Engine (An Interactive Introduction to Rotors from Geometric Algebra)

Monday, February 3rd, 2020

I have not yet posted on this blog that last year I released an article/video with interactive diagrams on Geometric Algebra, specifically Rotors. (I also recently updated it). Here is the introduction:

To represent 3D rotations graphics programmers use Quaternions. However, Quaternions are taught at face value. We just accept their odd multiplication tables and other arcane definitions and use them as black boxes that rotate vectors in the ways we want. Why does $\mathbf{i}^2=\mathbf{j}^2=\mathbf{k}^2=-1$ and $\mathbf{i} \mathbf{j} = \mathbf{k}$? Why do we take a vector and upgrade it to an “imaginary” vector in order to transform it, like $\mathbf{q} (x\mathbf{i} + y\mathbf{j} + z \mathbf{k}) \mathbf{q}^{*}$? Who cares as long as it rotates vectors the right way, right?

Personally, I have always found it important to actually understand the things I am using. I remember learning about Cross Products and Quaternions and being confused about why they worked this way, but nobody talked about it. Later on I learned about Geometric Algebra and suddenly I could see that the questions I had were legitimate, and everything became so much clearer.

In Geometric Algebra there is a way to represent rotations called a Rotor that generalizes Quaternions (in 3D) and Complex Numbers (in 2D) and even works in any number of dimensions.

3D Rotors are in a sense the true form of quaternions, or in other words Quaternions are an obfuscated version of Rotors. They are equivalent in that they have the same number of components, their API is the same, they are as efficient, they are good for interpolation and avoiding gimbal lock, etc… in fact, they are isomorphic, so it is possible to do some math to turn a rotor into a quaternion, but doing so makes them less general and less intuitive (and loses extra capabilites).

But instead of defining Quaternions out of nowhere and trying to explain how they work retroactively, it is possible to explain Rotors almost entirely from scratch. This obviously takes more time, but I find it is very much worth it because it makes them much easier to understand!

Earth-Centric planetary motion

For example, Quaternions are introduced as this mysterious four-dimensional object, but why introduce a fourth dimension of space to visualize a 3D concept? By contrast 3D Rotors do not require the use of a fourth dimension of space in order to be visualized.

Trying to visualize quaternions as operating in 4D just to explain 3D rotations is a bit like trying to understand planetary motion from an earth-centric perspective i.e. overly complex because you are looking at it from the wrong viewpoint.

It would be great if we could start phasing out the use and teaching of Quaternions and replace them with Rotors. The change is simple and the code remains almost the same, but the understanding grows a lot.

As a side note, Geometric Algebra contains more than just Rotors, and is a very useful tool to have in one’s toolbox. This article also serves as an introduction to it.

And here are some quotes about it:

The clearest explanation of 3D geometric algebra within 15 minutes that I’ve seen so far —BrokenSymmetry
I am sold. While I can understand quaternions to an extent, this way of thinking is a much more intuitive and elegant approach. —Jack Rasksilver
This sets a high standard for educational material, and is a shining example of how we can improve education with today’s technologies. —Sebastien Pierre
When I was in college, I asked one of my math professors why the cross product of two vectors results in a perpendicular vector whose magnitude is equal to the area of the parallelogram formed by the two vectors. Like..what? Why? And what about 2D? They blew me off, and that was a big part of why I stopped taking math in college. […] Anyway, I had pretty much given up on ever truly understanding the whole jumble of seemingly unrelated types that are cross products. But then I saw this: And…wow. Just 15 minutes and a lot more than just cross products suddenly make a lot more sense. —Mason Remaley
I’m a pure math dude at heart, even if I don’t get to do it much any more. Two years ago, my wife asked me, “If you had to get a math equation tattooed on your body, what would it be?” I answered, “i^2 = j^2 = k^2 = ijk = -1”. I felt a brief flush of anger when I saw this headline. This is an extraordinarily good article that should be read by pretty much anyone doing graphics programming. —pflats

I wrote most of in 2011/2012, but didn’t release it because I was not satisfied with part of it. But I thought it was time to let go and release it anyway. I actually think it is hurting the advancement of science that people are still mainly using quaternions instead of Geometric Algebra, so holding on to it was not good.

So last fall/summer I cleaned up some of the diagrams and made a 15 minute long video that follows the article exactly. I never made a video this long, and it was quite exhausting. But I thought it would be really cool to make an article that is perfectly synced to a video, so you can either read it or watch it, and the article serves as an exact table of contents for the video.

I think I came across Geometric Algebra from attending SIGGRAPH a long time ago? Specifically this book: Geometric Algebra for Computer Science by Dorst et al. Later on I found this great book: Linear and Geometric Algebra by Macdonald

Geometric Algebra soon came in handy for Miegakure, specifically to define the 4D equivalent to Quaternions, which I posted about on this blog. Later on it became the backbone of 4D Toys.

Learning about Geometric Algebra was also great because it answered so many questions I had when learning linear algebra, the cross product, quaternions, etc… I basically wrote this article for my past self as a college student.

I recently rewrote the introduction to add more detail about the properties of Rotors and how they relate to quaternions. Even though the content went into detail, it should now be clear what Rotors are from only reading the introduction. I can already see from reading recent comments that it was worth it.

I deliberately picked a cheeky click-bait title…

Something else that might be of interest is the history of Geometric Algebra, so I recently added a heavily summarized version to the end of the article. I think looking at the history makes it clearer how the quaternion viewpoint stayed in people’s minds for longer than necessary…