Become a Creator today!Start creating today - Share your story with the world!
Start for free
00:00:00
00:00:01
60: HAMILTON! [But Not the Musical] (Quaternions) image

60: HAMILTON! [But Not the Musical] (Quaternions)

Breaking Math Podcast
Avatar
593 Plays3 years ago

i^2 = j^2 = k^2 = ijk = -1. This deceptively simple formula, discovered by Irish mathematician William Rowan Hamilton in 1843, led to a revolution in the way 19th century mathematicians and scientists thought about vectors and rotation. This formula, which extends the complex numbers, allows us to talk about certain three-dimensional problems with more ease. So what are quaternions? Where are they still used? And what is inscribed on Broom Bridge? All of this and more on this episode of Breaking Math.


This episode is distributed under a CC BY-SA 4.0 license. For more information, visit CreativeCommons.org.

The theme for this episode was written by Elliot Smith.

[Featuring: Sofía Baca, Meryl Flaherty]

Recommended
Transcript

Revolutionary Quaternions Discovery

00:00:00
Speaker
I squared equals J squared equals K squared equals IJK equals negative one. This deceptively simple formula discovered by Irish mathematician William Rowan Hamilton in 1843 led to a revolution in the way 19th century mathematicians and scientists thought about vectors in rotation. This formula, which extends the complex numbers and is four-dimensional in nature, allows us to talk about certain three-dimensional problems with more ease. So what are quaternions?
00:00:28
Speaker
Where are they still used? And what is inscribed on Broombridge?

Introduction to Breaking Math Episode 60

00:00:33
Speaker
All this and more on this episode of Breaking Math. Episode 60. Hamilton! But not the musical.

Breaking Math Promotions

00:00:46
Speaker
I'm Zephia. And I'm Meryl. And you're listening to Breaking Math posters. Where can you get them? Facebook.com is Breaking Math podcast. They're 24 by 36 inches. Matt poster. They're well detailed. They are about tensors, which are used a lot in general relativity and applications like that. So if you like Einstein, or if you have a friend who likes Einstein or just math,
00:01:08
Speaker
You can get those at facebook.com slash breakingmathpodcast. If you want to support us every month, which we appreciate very, very much, we have a Patreon at patreon.com slash breakingmath. At our first tier, we deliver outlines. So if you pay $1 or more, you could get outlines and also shows without ads. So if you don't like ads and you like us, patreon.com slash breakingmath. The tensor posters are $15.15 plus $4 shipping and handling coming up to a total of $19.65.
00:01:38
Speaker
If you want updates about the show, you can follow us on Twitter at breakingmathpod. You can see our website breakingmathpodcast.app or find updates about the show on our Facebook at facebook.com slash breakingmathpodcast. And if you have ideas, comments, questions, or even corrections, email us at breakingmathpodcast.gmail.com.

Complex Numbers Explained

00:01:58
Speaker
So Meryl, what are quaternions?
00:02:00
Speaker
So quaternions are, if you're familiar with the complex numbers, where you just have a square root of negative one, called i, then you can have any two real numbers a and b, and you get a plus bi. But what we're doing here is that this is more of a four dimensional extension of complex numbers,
00:02:22
Speaker
So instead of just one square root of negative one that we call i, we have three square roots of negative one i, j, and k that all interact with each other. And they also kind of represent directions in 3D space, right? These square roots.
00:02:38
Speaker
Yeah, and so if you're working with vectors, then a lot of time in three dimensions, you'll see that the unit vectors in each of our directions, we call x, y and z are represented as the unit vectors i, j and k.
00:02:55
Speaker
And also, quaternions, you might think i, j, and k, there's only three. Another part of the quaternions is the number that you add to them. So it's a real number, plus a real number times i, plus a real number times j, plus a real number times k. So these are used in computer graphics sometimes, but we're going to talk about complex numbers to start with. Then we're going to talk about the basic formula and how we can derive a quaternion arithmetic from it.
00:03:21
Speaker
We're going to talk a little bit more about quaternion arithmetic. Then we're going to talk about some cool applications of quaternions, like 3D applications.

Complex Numbers in 2D Rotations

00:03:29
Speaker
So here we go. So we're going to start with complex numbers. And what this is is that we have both real and imaginary components to a complex number. Where does the imaginary component come in? And I know we've talked about this on the show before and how it has to do with square roots, right?
00:03:49
Speaker
Right, so we can get the square root of any positive number, right? Oh yeah, so yeah, like square root of 4 is 2 or negative 2. Right, or so we'd say the square root is 2, but negative 2 times negative 2 is also 4.
00:04:06
Speaker
Yeah. So what if we want to find the square root of a negative number, though? What if we want to find a number such that that number times itself is also negative? And obviously we can't do that with the numbers that we use for things like prices and weights of cars, right?
00:04:27
Speaker
Right, and so this is where i comes in, and so i is just something that we kind of constructed where we say i times i is negative one, or i squared is negative one.
00:04:39
Speaker
Yeah, and I just wanted to say a little bit about this too in as much as negative numbers. You can't express a count of things with negative numbers. You have to express a debt, right? So like I've heard of people like back before the 1600s thinking that the negative numbers were fake and imaginary. And that's how people thought about the complex numbers for at least a little while.
00:05:06
Speaker
I mean, if you look at a lot of early algebra, there are solutions that are in complex variables that don't come up at all from like the 1600s, 1700s and things like that. Another thing I actually wanted to add was that so complex numbers definitely seem a lot more real, I suppose. They're not called real numbers, but they seem a lot more concrete if you work in electrical and computer engineering, particularly where they're used to describe phase shift in sinusoidal signals.
00:05:36
Speaker
And the way that you can think about this is the light in your house, if you have like an incandescent light bulb, or actually any kind of light bulb, the electricity goes from positive 120, if you're in the United States, to negative 120 volts, 60 times a second. So to describe this, it turns out that we can use E and I. We'll talk about this on some other show. I think we actually have an episode about it quite a while ago.

Quaternion Properties and History

00:05:59
Speaker
But if you want if you let's say that you change the timing by like one one hundredth of a second, right? That's a phase shift and all this stuff is made really easy with complex numbers, right? It's because you're just choosing a different number on the complex unit circle and that represents your phase by that angle and
00:06:18
Speaker
Yeah, and by the same degree, someone could even say that the real number, the positive real numbers don't even seem like a legitimate number system because you can't really conceive of things that can't be written as fractions. I mean, you can even make the case that the integers aren't a good, aren't a concrete number system because there's integers that represent things that you cannot count. So it's all about perspective.
00:06:46
Speaker
After all, the cult of Pythagoras did murder people for trying to say the square root of 2 was irrational. Alright, so you talked about the unit circle, right? The complex unit circle? Can you talk about how numbers on that unit circle represent rotations?
00:07:03
Speaker
So let's say that I just started at the point one on the complex plane and I wanted to rotate that number over to I on the complex plane. So how do I do that? Yeah. Well, if a complex plane, the way that you draw this a lot of times is a grid, right? Um, where you have an origin and then the numbers, if you go further to the right, your real number increases. If you go to the left, uh, your real number decreases and then up and down does increase and decrease for the imaginary component.
00:07:33
Speaker
So I guess we can multiply by I, take I and multiply the number by it, right? I times that number.
00:07:42
Speaker
Right, and so multiplication with complex numbers does two things. So you get scaling based on how big, how far from the origin your complex number is, but you also get a rotation based on the angle that your complex number is at. So let's talk about the size, the magnitude of a complex number, right? So let's say we have a complex number 3 plus 4i. How can we determine the size of that number, the length?
00:08:08
Speaker
Well, we can use the Pythagorean theorem. So we have that three squared for the real part plus four squared for the imaginary part equals something squared. In this case, it would be 25 for whatever the overall size squared is. So take the square root of that and we get three squared plus four squared equals five squared. So we have that this complex number has a magnitude of five.
00:08:34
Speaker
And now let's talk about the angle, right? So this complex number, if you draw it on this plane and you rotate the line that goes straight out to the right from the origin, right? And you rotate it up to the complex number, it's going to make a certain angle and that's what we're talking about, right?
00:08:53
Speaker
Yeah, and so if we want to find the angle then of this complex number 3 plus 4i, so we take the arc tangent function, and so that would be the arc tangent of 4, our vertical component, over 3, our horizontal component, and we would get a value that comes out to approximately 53 degrees.
00:09:14
Speaker
Yeah. And so when you're multiplying by a complex number, first you rotate it by how much that number is around in the complex plane, right? And then you resize it by how long it is. So if it's shorter than one, you make it smaller. If it's longer than one, you make it longer. Exactly. So let's keep going with our example where we rotated one by I, getting I, right? So what happens when we rotate it by I again? So we have I times I and we get negative one, right?
00:09:41
Speaker
Yeah. And so what multiplying by I in this case does is that we're rotating because let's think about what the angle of I is, right? So it's all vertical component, no horizontal. Cause we're doing, we're defining imaginary numbers as vertical and, um, real numbers as horizontal just to recap.
00:10:01
Speaker
Yeah, what we're doing is that we're rotating our angle by 90 degrees, but also we're not scaling at all because I has a magnitude of one. And so let's think about what happens if we multiply by I again. So we're keeping our magnitude, but we're rotating by 90 degrees again. So in total, we've rotated 180 degrees.
00:10:26
Speaker
Yeah, so what we see then is that our magnitude multiplies and our rotations add up. Yeah, because then we get negative i, right? And then we multiply by i again and we get 1, which is where we started off at.
00:10:40
Speaker
So back to Quaternions. So we know that i squared equals j squared equals k squared equals ijk equals negative 1. But what does it mean? What it means is that all of these squared are negative 1. But I think it's good to pay attention to the ijk equals negative 1 aspect. Because what that implies when you do a little algebra is that these are non-communicative. But let's back up a little bit and talk about what that means.
00:11:08
Speaker
So what happened with the broom bridge, Merrill? William Rowan Hamilton, the man who discovered quaternions, was working with ways to extend complex numbers to three dimensions.

Quaternion Arithmetic and 3D Applications

00:11:21
Speaker
And what he found was that he wasn't able to, as his son described it, multiply triples.
00:11:30
Speaker
which would be doing multiplication and division with a with a three dimensional complex number system. But what he was able to find though, was that he could easily do this with quadruples, or as he called them quaternions. And he came across this realization when he was walking across what is now known as Broombridge in Dublin, Ireland.
00:11:54
Speaker
Yeah, and he's scratched with a nail or something. I squared equals J squared equals K squared equals IJK equals negative one, which is one of those great little math stories. Yeah, and now we have a plaque there too. So IJ and K, like we talked about, can both be conceived as vectors in three dimensions and as square roots of negative one, which is just kind of mind boggling. But what do I mean when I say that something is non-communitive? So Meryl, what is communitivity?
00:12:24
Speaker
So commutativity is, let's say that we have two things a and b and we're trying in this case to multiply them, then we could say that a times b is the same thing as b times a. So that works with like normal numbers, right? Like two times three is equal to three times two, which is six. Yeah. And it even works with the complex numbers too.
00:12:47
Speaker
Yeah, so like 1 plus i times 1 minus i is, yeah, 2. But yeah, so no matter which way you have that. But with quaternions, i times j is not the same thing as j times i. And so one of the reasons why this is, is you can think about it in terms of rotation, right? So in a 2D plane, if I rotate something to the left, I can rotate it to the right and get back exactly where I started, right? Exactly. Makes sense.
00:13:16
Speaker
But if I have a globe, and let's say I have it so that Madagascar is facing me, and let's say I rotate it forward so that Antarctica is facing me, and then I rotate it to the right so that somewhere in Indonesia is facing me. I'll be in Indonesia.
00:13:39
Speaker
But if I start when I was in Madagascar, rotating to the right, which is like Indonesia, and then rotating up, I end up at the South Pole. So you could see that this rota- and you could try this with a basketball or a marble. Rotate it one way and then another and then do it the opposite way and you'll end up in different places. But why is IJNK rotation? We'll talk about that now.
00:14:04
Speaker
So to do this, let's talk about quaternion arithmetic and how quaternions are multiplied. And so this all comes from our original formula. So let's start with ijk equals negative one. And so let's say that we multiply this by k. And since it's non-commutative, or we're claiming it, it matters which side the k is on, right?
00:14:27
Speaker
Right. So let's just say we're multiplying by K on the right side. So IJK times K is negative one times K. And of course negative one times K is just negative K, right? Yeah. And so then what we get is IJ times negative one is equal to negative K. And then negative IJ is negative K. And finally, that gives us IJ equals K.
00:14:50
Speaker
Yeah, and so that's how we find out the basic properties of this. And it turns out that if you derive j times i from this, you get negative k. And so remember earlier when we were doing, you'd see if you start at i and you rotate, you go to negative 1 to i, to 1 to i, and then back to negative 1 or whatever 4 you have. Well, we could do this with j. So let's say we start at i. We multiply it by j, and we get k, right?
00:15:20
Speaker
And then we left multiply. Left multiply means put the number of multiplying by on the left. So we left multiply by i again and we get negative j. i times k is negative j. i times negative j is negative k. And i times negative k is j. So we go from k to negative j to negative k to j. So we're just doing four 90 degree rotations just in a different direction.
00:15:46
Speaker
Yeah, and it turns out they could do this in three completely different axes with i, j, and k. That is essential to what we mean by they're non-commutative. So if we want to rotate in the opposite direction, right? Because we're talking about a four-dimensional rotation right now, right? Yeah. If we want to rotate in the opposite direction by the same amount, all we have to do is negate i, j, and k, right?
00:16:10
Speaker
Sounds about right. But, um, so what do we mean? So what do we mean by saying that is four dimensional, right? This concept with one I J and K.
00:16:19
Speaker
Right, so let's not forget that when we're looking at these quaternions, so i, j, and k are square roots of negative one. So you could have a plane with one, a real component, and i, j, r, k are complex component. But at the end of the day, we have that we still have these three dimensions and a real component.
00:16:44
Speaker
Yeah, so since we use four numbers to represent it, it is four dimensional, especially since those are all independent dimensions.
00:16:55
Speaker
Hey, Breaking Math fans. First, I want to thank you for listening. I have an important message for everyone. You can start your own podcast right now with Anchor. Anchor lets you create and distribute your own podcast. Just get an idea, record, and upload. It's just that easy. Anyone can do it. I'm on my way to accomplishing my dream, and you can too. Just get on your device's app store and download Anchor. It contains everything you need to make a podcast. With Anchor, you can put your podcast on all the big platforms.
00:17:23
Speaker
Apple Podcast, Spotify, Google Podcast, Amazon, and more. Reach the whole world with Anchor. Best of all, Anchor is free. You have nothing to lose with a free platform. Download the Anchor app or go to anchor.fm to get started.
00:17:43
Speaker
So now we're going to talk about how we use quaternions for 3D rotations. The basic form that we use is something that is called a similarity transformation. And Meryl, do you want to talk about what a similarity transformation is?
00:17:56
Speaker
So we have a way in terms of matrices and that is we have M prime equals A times M times A inverse, where A is a linear transformation. And what does it mean to be the inverse of a linear transformation? It essentially means you reverse it, right?
00:18:16
Speaker
Yeah, in this case, and let's not forget that matrices are not commutative. So if you have A times M times A inverse, that is not the same thing as doing nothing to M.
00:18:28
Speaker
Yeah, because even though A times A inverse is equal to A inverse times A, which is equal to the identity matrix, which is a matrix of just diagonals, ones, and everything else, zero, that keeps everything the same, that does not mean that like Meryl said, that A times the matrix times the inverse of A is equal to the opposite order, even if the two breads of the sandwich are inverses of one another.
00:18:55
Speaker
You can almost think of this as, since matrices do either a skew or a stretch, you can think of it as skewing something like, for example, rotating it and stretching it up, and then moving the object a little bit and stretching it back. That's kind of what a similarity transformation is. And what it does is it preserves the lengths and relative angles.
00:19:16
Speaker
Yeah, and so we can use quaternions in a similar similar way. Let's say that we have a point P in 3D space and we have a quaternion Q. So now we're going to talk about how we can use quaternions in a way that works like similarity transformations. So let's say that we have some point P in 3D space and we have a unit quaternion.
00:19:42
Speaker
So what is a unit quaternion? So a unit quaternion is a quaternion that's on the unit quaternion sphere. And what that means is that, so let's say that we have A plus BI plus CJ plus DK, and that's our quaternion. Yeah, so A, B, C, and D define our quaternion.
00:20:02
Speaker
Yeah, then we have that a squared plus b squared plus c squared plus d squared equals one. And that means it's on that four dimensional unit sphere. And that's a four dimensional length, right?
00:20:15
Speaker
Yeah, because two dimensions, you have a squared plus b squared, the square root of that. Three squared, you have the square root of a squared plus b squared plus c squared. And actually for any number of dimensions, you keep doing that. The reason why we've talked about on another podcast, but to do it quickly, you can basically imagine drawing, like if we're in three dimensions, you can imagine on the xy plane, drawing a right triangle to the point and then drawing another right triangle that goes up from that. It's a little bit of algebra, but you can see it quite clearly.
00:20:41
Speaker
All right, so now that we know what unit quaternions are, how do we use them for rotation?

Quaternions in 3D and 4D Rotations

00:20:46
Speaker
We mentioned before the similarity transformation. Okay, so rotating by quaternions looks a lot like the similarity transformation. So let's say that we have a unit quaternion Q and some point P. And by the way, because P is a point in 3D space, we're going to imagine that it's a pure quaternion, that it just has values for i, j, and k, no real component.
00:21:10
Speaker
Yeah, so 3i plus 4j plus 8k would be a pure quaternion, although not a unit quaternion, whereas 2 plus 3i plus 9j plus 13k would not be. Yeah, that sounds about right. So what we're going to do is we're going to treat Q as the transformation. And so if we have Q times P times Q inverse,
00:21:30
Speaker
So to do the inverse of a quaternion, all you have to do is take the negative, all you have to do is negate, turn negative, that means the BCD in components. So we have a quaternion A plus B times I plus C times J plus D times K. You just change that to A minus BI minus CJ minus DK.
00:21:50
Speaker
Okay, so then if we have q times p times q inverse, then the way that we can imagine this is that let's say that we have some 3d vector for the i j k parts of q, then let's say that that axis is staring right at you.
00:22:07
Speaker
then what we can do is that we can take the point P in relation to that axis and we can rotate it around. And so the amount that we rotate it is by the angle 2 inverse cosine of A about that axis B, C, D. So that's a lot to process. So let's definitely break that down. What does inverse cosine kind of feel like and look like?
00:22:35
Speaker
So what you're doing with inverse cosine is because let's not forget that Q is a unit quaternion. So it's going to take a value between negative one and one and turn it into an angle. And what is the range of angles? It should be from so it should be between zero to 180 degrees. Or we can also think of this in radians as zero to pi.
00:22:57
Speaker
or 0, and half of a turn, half of a tau of a circle. And then we just double it because when you multiply it in this way, you just double the angle. And it's kind of an interesting thing that happens when you're doing quaternions. So yeah, so you can imagine this. So let's say the angle that we're rotating about is facing you. That would be like if you were in the roof of a gym stadium and there's a Harlem Globetrotter spinning around a basketball on their finger.
00:23:23
Speaker
And if you looked right down at the basketball and saw the swirls so that it looked like a spiral to you, that would mean that the vector would be going into your eyes. From another direction, you could see it spinning sideways, kind of like the Earth, but it would still be spinning around the same thing. And you could define any three-dimensional orientation using these. And it shows these kind of tricks that allow us to use quaternions for three-dimensional rotation.
00:23:49
Speaker
And for those of you who would like an interactive quaternion thing, 3blue1brown, who's an amazing YouTuber, has a thing at etr.net, E-A-T-E-R dot net slash quaternions that allows you to visualize them, and I think that'd be really useful for this section specifically. And the quaternions form what is called a double cover of rotations in three dimensions, used in this way, you know, the Q times P times the inverse of Q thing, meaning that there's always two quaternions that correspond to any one point.
00:24:17
Speaker
And that's just something topologically interesting, but we'll leave that for another time.

Quaternions in Programming

00:24:24
Speaker
So 3D rotation matrices are used a lot in 3D programming, or at least used to be used more in certain applications. But more recently, in the last probably 10 years or so, quaternions have become a bigger part of 3D rotation. So let's talk about 3D rotation and what it means in matrix form.
00:24:44
Speaker
In three dimensions, what it means is that you have nine different numbers that you have to keep track of. And usually when you're doing 3D rotation matrices, you're dealing with Euler angles, which means that you have an angle within an angle within an angle, which means that you have what's called gimbal lock.
00:24:59
Speaker
If you've ever done 3D modeling or you've ever looked around in a video game and you've gotten stuck on a specific plane or a specific angle, that's called gimbal lock and it's when the two angles add up. You don't get that with quaternions, which can be used for 3D rotation, which also use four components versus nine components. So it's a lot easier on the processor too. And even though quaternions can be represented using matrices, there's different ways to do this. You can check this out on Wikipedia.
00:25:27
Speaker
There's a fundamental difference between the matrix representation of quaternions. When you're rotating by quaternions, let's say we have one orientation, we want to go to another orientation, right? If I just move a quaternion from one to the other while keeping the fact that it's a unit quaternion constant, then I'll have a smooth rotation. So another cool thing about quaternions is that they are the first non-commutative division algebra ever discovered.

Quaternions and Division Algebra

00:25:55
Speaker
So what is a division algebra?
00:25:57
Speaker
So quite simply put, it's an algebra over which division is possible.
00:26:02
Speaker
So asking what division algebra is also asks, what is an algebra? So an algebra is basically a field that has the idea of multiplication and is defined in this way. So if I take X and Y, we'll put them together, right? We got some number X, X, Y. Let's call that Z. Okay. So let's do X times like A, A where A is a constant, A times Y. We would get A times Z, right? Right. And AX times Y would also equal A times Z.
00:26:30
Speaker
And in the same way, if you do x plus a times y, you get x times y plus x times a. So z plus x times a. And so basically, you keep doing this, and so it's basically an algebra where multiplication exists. So division algebra is one where division always also exists. So let's talk about what a field is. A field is a bunch of numbers where you could define addition, subtraction, multiplication, and division.
00:26:59
Speaker
Except by zero. Except by zero, yes. And so if we have a and b in the field, that means that there's some x and some y such that a equals b times x and b equals a times y. So with the real numbers, let's say a is 2 and b is 3. So a is equal to 3 times 2 thirds, right? 2 is equal to 3 times 2 thirds and 3 is equal to 2 times 3 halves or 1.5.
00:27:26
Speaker
So those exist, and you can try any two numbers and you'll always be able to find those that exist because x is equal to a divided by b and y is equal to b divided by a. So a non-communicative division algebra means that a, b is not always equal to b, a. And it was the first one discovered, and since then we've discovered other ones, not just non-communicative, non-associative by this point, right?
00:27:49
Speaker
Yeah, so other ones that look a little like that are, we can say, the Octonians. What are Octonians? They're like the Quaternions, but instead they're eight-dimensional, not four. Couldn't say I hate you. And it gets worse, though, because we also have the Sedenians, which are the same thing, but 16 dimensions. Cut! Cut! Cut to commercial! Cut, everyone!

Closing Remarks on Number Systems

00:28:14
Speaker
Real numbers, complex numbers, and quaternions are an integral and historical part of mathematics. Real numbers can be used for debts and amounts, complex numbers for things like electrical engineering, and quaternions for 3D and 4D rotation. It is fascinating that these urnians and onions, also involving what are known as octonions, fulfill what turn out to be such picky requirements. I'm Sophia. And I'm Meryl. And this has been Breaking Math. Meryl, do you want to plug the union?
00:28:42
Speaker
Uh, yes, while I still am a UNM graduate student, I would like to give a shout out to the University of New Mexico Graduate Workers Union. UNM works because we do. And also, if you want to get a poster, facebook.com slash breaking up podcast, you won't regret it. I think no, you won't.