What you're looking at right now is something called quaternion multiplication,
or rather, you're looking at a certain representation of a specific motion happening on a four-dimensional sphere
being represented in our three-dimensional space
one which you'll understand by the end of this video.
Quaternions are an absolutely fascinating and often underappreciated number system from math.
Just as complex numbers are a two-dimensional extension of the real numbers,
quaternions are a four-dimensional extension of complex numbers,
but they're not just playful mathematical shenanigans.
They have a surprisingly pragmatic utility for describing rotation in three dimensions and even for quantum mechanics.
The story of their discovery is also quite famous in math.
The Irish mathematician William Rowan Hamilton
spent much of his life seeking a three-dimensional number system analogous to the complex numbers,
and as the story goes, his son would ask him every morning
whether or not he had figured out how to divide triples and he would always say "no, not yet."
But on October 16th, 1843, while crossing the Broome Bridge in Dublin,
he realized—with a supposed flash of insight—
that what he needed was not to add a single dimension to the complex numbers,
but to add two more imaginary dimensions:
three imaginary dimensions describing space
and the real numbers sitting perpendicular to that in some kind of fourth dimension.
He carved the crucial equation describing these three imaginary units into the bridge
which today bears a plaque in his honor showing that equation.
Now, you have to understand our modern notion of vectors with their dot product and the cross product and things like that
didn't really exist in Hamilton's time, at least not in a standardized form.
So after his discovery, he pushed hard for quaternions to be
the primary language with which we teach students to describe three-dimensional space,
even forming an official quaternion society to proselytize his discovery.
Now, unfortunately, this was balanced with mathematicians on the other side of the fence
who believed that the confusing notion of quaternion multiplication
was not necessary for describing three dimensions
resulting in some truly hilarious old-timey trash talk legitimately calling them evil.
It's even believed that the Mad Hatter scene from Alice in Wonderland
whose author you may know was an Oxford mathematician
was written in reference to quaternions: that the chaotic table placement changes were mocking their multiplication,
and that certain quotes were referencing their non-commutative nature.
Fast forward about a century and the computing industry gave
quaternions a resurgence among programmers who work with graphics and robotics and anything involving orientation in 3D space,
and this is because they give an elegant way to describe and to compute 3D rotations
which is computationally more efficient than other methods and which also avoids a lot of the numerical errors that arise in these other methods.
The 20th century also brought quaternions some more love from a completely different direction, quantum mechanics.
You see, the special actions the quaternions describe in four dimensions
are actually quite relevant to the way that two-state systems like spin of an electron, or
the polarization of a photon are described mathematically.
What I'll show you here is a way to visualize quaternions in their full four-dimensional glory.
It would surprise me if this approach was fully original,
but I can say that it's certainly not the standard way to teach quaternions, and that these specific
four-dimensional right-hand rule image that I'd like to build up to is something that I haven't really seen elsewhere.
Building up an understanding for this visual will take us meaningful time,
but once you have it, there is a very natural and satisfying intuition for how to think about quaternion multiplication
It won't be until the next video that I show you how exactly quaternions describe orientation in three dimensions,
which is for some people the whole reason we care about it,
but once we're able to go at it armed with the image of what they're doing to a 4d hypersphere,
there's a pleasing understanding to be had for the otherwise opaque formulas characterizing this relationship.
The structure here will be to start by imagining teaching complex numbers to someone who only understands one dimension,
then describing 3d rotations to someone who only understands two dimensions,
and ultimately to represent what quaternions are doing up in four dimensions,
within the constraints of our 3d space.
Our first character is Linus the Linelander, whose mind can only grasp the one-dimensional geometry of lines and the algebra of real numbers.
We're gonna try to describe complex members to Linus, and it's really important for you to
empathize with him as much as you can during this, because in a few minutes you're gonna be in his shoes
On the one hand, you could define complex numbers purely algebraically:
you say each one is expressed as some real number plus some other real number times i,
where i is a newly invented constant whose defining property is that i × i = -1.
Then you say to Linus to multiply two complex numbers, you just use the distributive property—what many people learn in school as "FOIL"—
and you apply this rule that i × i = -1 to simplify things down further. And that's fine!
That totally works, and the standard textbook way to introduce quaternions is analogous to this:
showing the algebraic rules and calling it done
But I think something is missing If we don't at least try to show Linus the geometry of complex numbers
and what complex multiplication looks like, since the problems in math and physics
where complex numbers are shockingly useful often leverage this spatial intuition.
You and I, who understand two dimensions, might think of it like this:
When you multiply two complex numbers, z times w,
you can think of z as a sort of function acting on w, rotating and stretching it in some way.
I like to think of this by broadening the view and asking "what does z do to the entire plane?"
and you can think of that bird's-eye view action by imagining using one hand to fix the number 0 in place,
and using another hand to drag the point at 1 up to z,
since anything times 0 is 0 and anything times 1 is itself.
And in two dimensions, there is one and only one stretching-rotating action on the plane that'll do this.
This is also how I'll have you thinking about quaternion multiplication later on,
where the number on the left acts as a kind of function to the one on the right, and
we'll understand this function by seeing how it acts by transforming space,
although instead of rotating 2d space, it does a sort of double rotation in 4d space.
By the way, if you want to review thinking about complex numbers as a kind of action,
a good warm-up for this video might be the one I did on e to the pi i explained with introductory group theory
Now Linus the Linelander is pretty comfortable with the idea of stretching: that's what multiplication by real numbers looks like.
Maybe it's a little weird for him to think about stretching in multiple dimensions, but it's not fundamentally different.
The difficult thing to communicate to Linus is rotation:
specifically, focus on the unit circle of the complex plane—all the numbers a distance 1 from zero—
since multiplication by these numbers corresponds to pure rotation.
How would you explain to Linus the look and the feel of multiplying by these numbers?
At first, that might seem impossible. I mean, rotation is just such an intrinsically two-dimensional idea.
But on the other hand, rotation involves only one degree of freedom:
a single number, the angle, specifies a given rotation uniquely.
So in principle, it should be possible to associate the set of all rotations to the one-dimensional continuum that is Linus's world
And there are many ways you could do this, but the one I'm going to show you is what's called a stereographic projection
It's a special way to map a circle onto a line, or a sphere into a plane, or even a 4d hypersphere into 3d space.
For every point on the unit circle, draw a line from -1 through that point
and wherever it intersects the vertical line through the circle's center, that's where the point of the circle gets projected
So for example, the point at 1 gets projected into the center of the line;
the point i actually stays fixed in place, as does -i;
all of the points on that 90° arc between 1 and i
will get projected somewhere in the interval between where 1 landed and where i landed.
As you continue farther around the circle on the arc between i and -1,
the projected points end up farther and farther away at an increasing rate.
Similarly, if you come around the other way towards -1,
the projected points end up farther and farther on the other end of the line.
This line of projected points is what we show to Linus,
labeling a few key points like 1 and i and -1, all for reference.
Technically, the point at -1 has no projection under this map,
since the tangent line to the circle at that point never crosses the vertical line,
but what we say is that -1 ends up at the "point" at infinity.
This is a special point you imagine adding to the line where you would approach it
if you walk infinitely far along the line in either direction.
Now it's important to remember and to remind Linus that what he's seeing is only the complex numbers that are a distance 1 from the origin: the unit circle.
Linus doesn't see most numbers like 0 or 1 + i or -2 - i.
But that's okay, because right now we just want to describe complex numbers z
where multiplying by z has the effect of a pure rotation, so he only needs to understand the unit circle.
For example, when we take the number i and multiply it by any other complex number w,
the effect is to rotate by 90° counterclockwise.
And when we apply this action to the circle being projected down to the line for Linus, what does he see?
Well, it's a bit of a strange morphing action on the line, one which I want you to become familiar with for something we'll see later on.
It's easiest to understand by following a few key reference points.
i times 1 is i, so that means the number 1 should move up to i.
i times i is -1, so the point at i slides off to infinity.
i times -1 is equal to -i, so that point at infinity kind of comes back around from the bottom to the position one unit below the center
and i times -1 is 1, so that point at -i slides up to 1.
Even though this is kind of a weird motion, it lets us communicate some important ideas to Linus.
For example, multiplying by i four times, which corresponds to rotating by 90° four times in a row,
gets us back to where we started: i to the fourth equals one.
Here, to get more of a feel for things
let me just show the circle rotated at various different angles, on both the left and the right half of the screen here,
and putting a hand on the point that started at the number 1 to help us and to help Linus keep track of the overall motion.
Next, let's introduce Felix the Flatlander, who only understands two-dimensional geometry.
Imagine trying to explain rotations of a sphere to Felix.
In the spirit of transitioning from complex numbers to quaternions,
let's extend the complex numbers with its horizontal axis of real numbers and its vertical axis of imaginary numbers
with a third axis, defined by some newly invented constant j
sitting one unit away from 0, perpendicular to the complex plane.
Instead of having this new axis in the z direction like you might expect, for a better analogy with how we'll visualize quaternions,
we'll want to orient things so that the i and the j axes sit in the x and the y directions
with the real number line aligned along the z direction.
So every point in 3d space is described as some real number,
plus some real number times i, plus some real number times j.
As it happens, it's not possible to define a notion of multiplication for a 3d number system like this
that would satisfy the usual algebraic properties that make multiplication a useful construct.
Perhaps I'll outline why this is the case in a follow-on video, but staying focused on our current goal,
think about describing 3d rotations in this coordinate system to Felix the Flatlander.
The unit sphere consists of all those numbers which are a distance 1 from 0at the origin,
meaning the sum of the squares of their coordinates is 1.
We can't show all of 3d space to Felix, but what we can do is project this 2d surface to him
and give him a feel for what reorientations of the sphere look like under that projection.
Analogous to what we did before, stereographic projection will associate almost every point on the unit sphere
with a unique point on the horizontal plane defined by the i and the j axes.
For each point on the sphere, draw a line from -1 at the south pole through that point and see where it intersects the plane.
So the point 1 at the north pole ends up at the center of the plane;
all of the points of the northern hemisphere get mapped somewhere inside the unit circle of the ij plane;
and that unit circle which passes through i, j, -i, and -j actually stays fixed in place.
And that's an important point to make note of:
even though most points and lines and patches that Felix the Flatlander sees are going to be warped projections of the real sphere,
this unit circle is the one thing that he has which is an honest part of our unit sphere, unaltered by projection
All of the points in the southern hemisphere get projected outside that unit circle,
each getting farther and farther away as you approach -1 at the south pole.
And again, -1 has no projection under this mapping, but what we say is that it ends up at some point at infinity.
That point at infinity is something such that no matter which direction you walk on the plane,
as you go infinitely far out, you'll be approaching that point.
It's analogous to how if you walk any direction away from the north pole, you're approaching the south pole.
Now let me just pull up a view of what Felix sees in two dimensions.
As I rotate the sphere in various ways, the lines of latitude and longitude drawn on that sphere
get projected into various circles and lines in Felix's space.
And the way I've done things up here, the checkerboard pattern on the surface of the sphere is accurately reflected in the projected view that you see with Felix,
and the pink dot represents where the point that started at the north pole ends up after the rotation,
and that yellow circle represents where the Equator ended up after the projection
The more you put yourself in Felix's shoes right now, the easier quaterniums will be in a moment.
And as with Linus, it helps to focus on a few key reference objects, rather than trying to see the whole sphere.
This circle, passing through 1, i, -1, and -i, gets mapped onto a line which Felix sees as the horizontal axis.
It's important to remind Felix that what he sees is not the same thing as the i axis.
Remember, we're only projecting the numbers that have a distance 1 from the origin,
so most points on the actual i axis, like 0 and 2i and 31 and et cetera, are completely invisible to Felix
Similarly the circle that passes through 1, j -1, and -j gets projected onto what he sees as a vertical line.
And in general, any line that Felix sees comes from some circle on the sphere that passes through -1.
In some sense, a line is just a circle that passes through the point at infinity.
Now think about what Felix sees as we rotate the sphere.
A 90° rotation about the j axis brings 1 to i, i to -1, -1 to -i, and -i to 1.
So what Felix the Flatlander sees is an extension of the rotation that Linus the Linelander was seeing.
Notice also that this action rotates the ij unit circle to the position where the 1-j unit circle used to be
So what Felix sees is his yellow unit circle getting transformed into a vertical line,
while that red vertical line gets transformed into the unit circle.
Of course, from our perspective, we know this is all just rigid motion.
No actual stretching or more thing is taking place; all of that is just an artifact of the projection.
Similarly a rotation about the i axis involves moving 1 to j, j to -1, -1 to -j, and -j to 1.
This rotation turns the ij unit circle into the 1-i unit circle,
which, to Felix, looks like the unit circle getting transformed into a horizontal line.
A rotation about the real axis is actually quite easy for Felix to understand
since the whole projection simply gets rotated about the origin,
where the only point staying fixed in place are 1 at the origin and -1 off at infinity.
In the same way that the complex numbers included the real numbers
with a single extra quote-unquote "imaginary dimension" represented by the unit i,
and that the not-actually-a-number-system thing we had in three dimensions included a second imaginary direction j,
the quaternions include the real numbers together with three separate imaginary dimensions,
represented by the units i, j, and k.
Each of these three imaginary dimensions is perpendicular to the real number line,
and they're all perpendicular to each other somehow.
So in the same way that complex numbers are represented as a pair of real numbers,
each quaternion can be written using four real numbers, and it lives in four-dimensional space.
You often think of this as being broken up into a real or "scalar" part, and then a 3d imaginary part.
And Hamilton used a special word for quaternions that had no real part and just ijk components,
a word which was previously somewhat foreign in the lingo of math and physics: "vector".
On the one hand, you could just define quaternion multiplication by giving the rules for how i, j, and k multiply together
and saying that everything must distribute nicely.
This is analogous to defining complex multiplication by saying that i times i is -1,
and then distributing and simplifying products.
And indeed, this is how you would tell a computer to perform quaternion multiplication,
and the relative compactness of this operation compared to, say, matrix multiplication,
is what's made quaternions so useful for graphics programming and many other things.
There's also a rather elegant form of this multiplication rule written in terms of the dot product and the cross product,
and in some sense, quaternion multiplication subsumes both of these notions—at least, as they appear in three dimensions.
But just as a deeper understanding for complex multiplication comes from understanding its geometry,
that multiplying by a complex number involves a combination of scaling and rotating,
you and I are here for the four-dimensional geometry of quaternion multiplication.
And just as the magnitude of a complex number—its distance from zero—
is the square root of the sum of the squares of its components,
that same operation gives you the magnitude of a quaternion.
And multiplying quaternion, q1, by another, q2, has the effect of scaling q2 by the magnitude of q1
followed by a very special type of rotation in four dimensions.
And those special 4d rotations, the heart of what we need to understand,
correspond to the hypersphere of quaternions a distance 1 from the origin,
both in the sense that the quaternions whose multiplying action is a pure rotation live on that hyper sphere,
and in the sense that we can understand this weird 4d action just by following points on the hypersphere,
rather than trying to look at all of the points in the inconceivable stretch as a four-dimensional space.
Analogous to what we did for Linus and Felix, we stereographically project this hypersphere into 3d space
This label in the upper right is going to show a given unit quaternion,
and this little pink dot will show where that particular quaternion gets projected in our 3d space.
Just as before, we're projecting from the number -1,
which sits on the real number line that is somehow perpendicular to all of our 3d space and beyond our perception.
Just as before, the number 1 ends up projected straight into the center of our space,
and in the same way that i and -i were fixed in place for Linus,
and that the ij unit circle was fixed in place for Felix,
we get a whole sphere passing through i, j, and k on that unit hypersphere which stays in place under the projection.
So what we see as a unit sphere in our 3d space
represents the only unaltered part of the hypersphere of quaternions getting projected down on to us.
It's something analogous to the equator of a 3d sphere, and it represents all of the unit quaternions whose real part is 0.
What Hamilton would have described as unit vectors.
The unit quaternions with positive real parts between 0 and 1
end up somewhere inside this unit sphere closer to the number 1 in our 3d space,
which should feel analogous to how the northern hemisphere got mapped inside the unit circle for Felix.
On the other hand, all the unit quaternions with negative real part end up somewhere outside that unit sphere.
The number -1 is sitting off at the point at infinity, which you can easily find by walking in any direction.
Keep in mind, even though we see the projection of some of these quaternions as being closer or farther from the origin of our 3d space,
everything you're looking at represents a unit quaternion,
so everything you're looking at really has the same magnitude: the same distance from the number 0.
And that number 0 itself is nowhere to be found in this picture. Like all other non-unit quaternions, It's invisible to us.
In the same way that, for Felix, the circle passing through 1, i, -1, and -i got projected into a line through the origin,
when we see this line through the origin passing through i and -i, we should understand that it really represents a circle.
Likewise, up on the hypersphere invisible to us, there is a unit sphere passing through 1, i, j, -1, -i, and -j,
and that whole sphere gets projected into the plane that we see passing through 1, i, -i, j, -j, and -1 off at infinity:
what you and I might call the xy plane.
In general, any plane that you see here really represents the projection of a sphere
somewhere up on the hypersphere which passes through the number -1.
Now the action of taking a unit quaternion and multiplying it by any other quaternion from the left
can be thought of in terms of two separate 2d rotations happening perpendicular to
and in sync with each other in a way that could only ever be possible in four dimensions.
As a first example, let's look at multiplication by i.
We already know what this does to the circle that passes through 1 and i, which we see as a line.
1 goes to i,
i goes to -1 off at infinity,
-1 comes back around to -i, and -i goes to 1.
Remember, just like what Linus saw, all of this is the stereographic projection of a 90° rotation.
Now look at the circle passing through j and k,
which is in a sense perpendicular to the circle passing through 1 and i.
Now, it might feel weird to talk about two circles being perpendicular to each other,
especially when they have the same center, the same radius, and they don't touch each other at all,
but nothing could be more natural in four dimensions.
You can think of the action of i on this perpendicular circle as obeying a certain right-hand rule.
If you'll excuse the intrusion of my ghostly green screen hand into our otherwise pristine platonic mathematical stage,
you let that thumb of your right hand point from the number 1 to i, and you curl your fingers.
The jk circle will rotate in the direction of that curl.
How much? Well, by the same amount as the 1-i circle rotates, which is 90° in this case.
This is what I meant by two rotations perpendicular to and in sync with each other.
So j goes to k,
k goes to -j,
-j goes to -k,
and -k goes to j.
This gives us a little table for what the number i does to the other quaternions.
But I want this not to be something that you memorize,
but something that you could close your eyes and you could really see.
Computationally, if you know what a quaternion does to the numbers 1, i, j, and k,
you know what it does to any arbitrary quaternion, since multiplication distributes nicely.
In the language of linear algebra, 1, i, j, and k form a basis of our four dimensional space,
so knowing what our transformation does to them gives us the full information about what it does to all of space.
Geometrically, a four-dimensional creature would be able to look at those two perpendicular rotations that I just described
and understand that they lock you into one and only one rigid motion for the hypersphere.
We might lack the intuitions of such a hypothetical creature, but we can maybe try to get close.
Here's what the action of repeatedly multiplying by i looks like on our stereographic projection of the ijk sphere.
It gets rotated into what we see as a plane,
then gets rotated further back to where it used to be (though the orientation is all reversed now),
then it gets rotated again into what we see as a plane, and after the fourth iteration it ends up right back where it started.
As another example, think of a quaternion like q = -(√2)/2 + (√2)/2 i
which, if we pull up a picture of a complex plane, is a 135° rotation away from 1 in the direction of i.
Under our projection, we see this along the line from 1 to i somewhere outside the unit sphere.
If that sounds weird, just remember how Linus would have seen the same number.
The action of multiplying this q by all other quaternions
will look to us like dragging the point at 1 all the way to this projected version of q,
while the jk circle gets rotated 135° according to our right-hand rule.
Multiplication by any other quaternion is completely similar.
For example, let's see what it looks like for j to act on other quaternions by multiplication from the left.
The circle through 1 and j, which we see projected as a line through the origin, gets rotated 90°, dragging 1 up to j.
So j times 1 is 1, and j times j is -1.
The circle perpendicular to that one, passing through i and k,
gets rotated 90° according to this right-hand rule, where you point your thumb from 1 to j.
So j times i is -k,
and j times k is i.
In general, for any other unit quaternion you see somewhere in space,
start by drawing the unit circle passing through 1, q, and -1,
which we see in our projection as a line through the origin,
then draw the circle perpendicular to that one on what we see as the unit sphere.
You rotate the first circle so that 1 ends up where q was,
and rotate the perpendicular circle by the same amount. according to the right hand rule.
One thing worth noticing here is that order of multiplication matters: it's not, as mathematicians would say, commutative.
For example, i times j is k, which you might think of in terms of i acting on the quaternion j, rotating it up to k.
But if you think of j as acting on i, j times i, it rotates i to -k.
In fact, commutativity—this ability to swap the order of multiplication—is a way more special property than a lot of people realize,
and most groups of actions on some space don't have it. It's like how in solving a Rubik's cube, order matters a lot,
Or how rotating a cube about the z axis and then about the x axis
gives a different final state from rotating it about the x axis, then about the z axis.
And last, as one final but rather important point,
so far I've shown you how to think about quaternions as acting by left multiplication,
where when you read an expression like i times j,
you think of i as a kind of function morphing all of space and j is just one of the points that it's acting on.
But you can also think of them as a different sort of action:
by multiplying from the right, where in this expression, j would be acting on i.
In that case, the rule for multiplication is very similar. It's still the case that 1 goes to j and j goes to -1, etc.
But instead of applying the right-hand rule to the circle perpendicular to the 1-j circle, you would use your left hand.
So either way, i times j is equal to k,
but you can either think about this with your right hand curling the number j to the number k as your thumb points from 1 to i,
or as your left hand curling i to k as its thumb points from 1 to j.
Understanding this left hand rule for multiplication from the other side will be extremely useful
for understanding how unit quaternions describe rotation in three dimensions.
And so far, it's probably not clear how exactly quaternions do describe 3d rotation.
I mean, if you consider one of these actions on the unit sphere passing through i, j, and k,
it doesn't leave that sphere in place—it morphs it out of position.
So the way that this works is slightly more complicated than a single quaternion product.
It involves a process called conjugation,
and I'll make a full follow-on video all about it so that we have the time to go through some examples
In the meantime, for more information on the story of quaternions and their relation to orientation in 3d space,
Quanta, a mathematical publication I'm sure a lot of you are familiar with,
just put out a post in a kind of loose conjunction with this video. (link in the description)
If you enjoyed this, consider sharing it with some friends,
and if you felt like the narrative structure here was actually helpful for understanding
maybe reassure those friends who would be turned off by a large timestamp that good math is actually worth the time.
And many thanks to the patrons among you. I actually spent way longer than I care to admit on this project,
so your patience and support is especially appreciated this time around.