Welcome to A Coding Challenge, where I will enter...
The fourth dimension.
Well, I didn't really time it, I expected some dramatic moment to happen with the music
there but it didn't happen.
So alright, this is A Coding Challenge, I am so crazily excited about this.
If this actually works I think that, I don't know what's going to happen, stuff will just
like, smoke, and brain matter will start just like leaking out of my nostrils.
I don't even know, so wait 'til the end of this video to see.
Now what I'm starting with here looks like a plain old spinning cube and actually that's
what it is.
What I want to do is not just make a plain old spinning cube in three dimensions, I want
to make a hypercube spinning in the...
Fourth dimension.
So I want to make something that looks like this, right?
So this is a hypercube, otherwise known as a tesseract.
And I'm going to, before I start coding any of this I'm going to explain to you what that
is exactly.
So let me come over here, so I, I think my favorite dimension is one dimension.
No, zero, let's start with zero dimensions.
A point is a shape that exists in 0D, that's a zero.
Now the line which is bound by two points is something that exists in one dimensional
space.
This is one dimensional space.
A rectangle, a square, a plane which is bound by one, two, three, four lines exists in two
dimensional space.
Now notice the pattern here.
This is bound by two lines, this is bound by four.
I'm sorry, this is bound by two points, this is bound by four lines.
Now if I create two planes and then connect all the edges I have what is commonly referred
to as a cube.
This is something that exists in three dimensions, are the number of dimensions that we live
in on this planet where we live and it is bound by six planes.
So you can see a pattern here.
I was going to say you double it but this is not bound by anything I guess so this sort
of makes sense.
This is bound by zero things, this is the beginning.
Now what does it mean, then, to have four dimensions?
Well I'm not really going to be able to draw this too easily but we could make the case,
right, if I'm following this pattern, that four dimensions is bound by eight cubes.
And this is mathematically true, this is accurate.
The problem is I'm going to sit here and I'm going to visualize this in my head.
Are you doing this with me?
I can't, I just cannot do it at all.
Human beings did not evolve to understand the world in an dimensions higher than three.
Anyway, I could keep going on about this since this is a mathematical truth, why isn't there
some way that we could somehow unlock is and see this on a computer screen in some way?
And in fact, there is, so this is how.
How do we even see this?
How do we even see this 3D shape on a 2D computer screen?
Well the way we do that is by writing code like this one that I've done right here.
Now the truth of the matter is, in processing, which the programming language environment
I'm using right now, I could just say box and I would get that because I'm in the P3D
renderer.
And the P3D renderer knows how to take the mathematics of a 3D shape and project it into
a 2D canvas to create the illusion of the third dimension.
And it totally makes sense to our brains 'cause we're so used to 3D.
We can imagine it, we can see the 2D version of it and imagine it in three dimensions.
And I did, you don't have to have watched that video to watch this one but I did a whole
previous Coding Challenge where I made exactly this put only using the P2D renderer.
So I did the math of taking 3D points and projecting them into 2D, so if I can do that,
why can't I create the math for a 4D shape, do the projection into 3D and render it with
the P3D renderer?
The truth of the matter is I could then project it into 2D and render it with the P2D renderer
as well, but I'm lazy, I'm just going to do one projection.
And if this is true there's no reason why I couldn't create a 5D shape and a 6D shape
and a 7D shape.
And I project 7D into 6D into 5D into 4D and then into 3D and visualize it.
So this is what I'm going to attempt to do in this video.
It is going to require matrices.
There are other ways to do it without it or create the visual illusion of it but I'm going
to be using matrices and the matrices are going to be used for a couple things.
I need a projection matrix, this is a matrix that takes a 4D point and turns it into a
3D point.
And I'm going to also need a rotation matrix.
I don't need the rotation matrix but the rotation matrix is what's going to make this funbecause
I can start to rotate around weird axis to see crazy things happen.
So this is kind of like optional but this is what's going to make the visualizations,
so I'm going to do the most basic wire frame version of this and hopefully you are then
going to make beautiful, interesting, weird things about this.
If somebody watching this, but who can go to the highest dimension possible in processing?
I would like to see that as a challenge.
Now if you want to learn more or see a condensed version of the explanation of what the tester
act is and how this works I would highly recommend, for me, I'm making this coding challenge because
of this particular video.
From, how do you pronounce that?
Anybody know how you say this?
Okay, I can't figure out how to pronounce it, I'm going to guess, LeiosOS.
But this is a wonderful, wonderful YouTube channel with many excellent explanatory videos
and this one about understanding 4D, the tesseract, is excellent.
So you could pause this, go watch that, come back later, all of the above.
Okay, alright so now I think we're good, we're good, we're good, and I minimize the browser
and here I am.
Okay, alright, now what do I need?
The first thing I need to do, if I'm going to make something 4D, to do something in 3D
I make heavy use of this idea of a PVector which is a data structure that holds an X,
Y, and a Z.
I need something that can hold an X, Y, Z, and W for that fourth dimension so I'm going
to make a new tab and I'm going to call it P4Vector and I'm going to say class P4Vector
and I'm going to say it has an X, Y, Z, and a W and it needs a constructor.
And it can get a X, a Y, a Z, and a W. And then I'm going to say this.x, isn't it fun
when you have to use the this.
in java 'cause it's like so rare?
Every once in a while you do.
Z, W, X, Y, Z, W, so now this is my P4Vector.
Alright, P4Vector, there we go, and now I am going to make this cube, this very cube,
all the points of the cube and actually one thing I want to do just not, I'll leave it
right now, I'm going to make it in 4D.
Zero, zero, the fourth dimension And then while I'm adding the fourth dimension I got
to change these P4Vector.
Then I've got to change this P4Vector, P4Vector.
And now this stuff I'm going to worry about later.
And let's see, we're going to watch, it's going to be four dimensions now, everybody.
Here it comes, four dimensions.
Look away This is the same exact cube, right?
It's the same, is that four dimensions?
Oh I'm so confused.
Well how are you even going to see this fourth dimension?
First of all, all the points are on zero.
So what you can think about it is it's flat.
I took a four dimensional shape and flattened it, flattened it, you know, we say flat 'cause
usually we're taking a three dimensional shape and flattening it into 2D so a cube if you
flatten it would just be a square.
So I took this hypercube and flattened it and I just have the cube so I need to make
the hypercube.
You know what, I'm going to, against my better judgment I'm just going to extend this array
to have 16 points.
Right, a hypercube is made up of 16 vertices because it's basically two cubes with all
the points connected.
So I am going to, I was going to make like a cube object and a hypercube as two cubes
but I'm going to just keep going.
So I'm going to say eight, nine, 10, 11, 12, 13, 14, 15.
And then I'm actually going to put this in 4D.
So all of these zeroes, right, they should all be 100.
The rest of them at negative 100.
I know I'm doing this in a highly manual way but first of all I find it kind of relaxing
sometimes just to sit here and copy paste the same thing over and over again, you should
try it, it's very soothing.
And then also I can always refactor it later but just so I really know that it's working,
okay.
I've got 16 four dimensional points,, I am going to now draw them again.
Okay, so it still just looks like those points.
What's missing here?
Well I'm not actually doing the projection so now it's time for me, like, I'm just taking
the 4D point, ignoring that v.w part and then doing a projection.
So really what I need to do right now is think about how I do the projection so I'm going
to create a projection matrix for a 4D point.
So this is the point X,Y,W,Z.
The projection matrix to take a 4D point and turn it into, oh wait, X, Y, Z, W. And project
it into something I can draw in 3D, X,Y,Z.
The idea is I want to look at the shadow of the 4D object in 3D, just like I might look
at the shadow of a 3D object in 2D so to do that I need a matrix that has four columns
and three rows so the typical way to do that would be like this.
One, zero, zero, zero, zero, one, zero, zero.
Zero, zero, one, zero, right, I think I got everything.
The idea here, if I actually use this matrix and perform matrix multiplication which I'll
link to two videos where I go through that in more detail, this actually gives me literally
this.
It's like, just chopping off the W. So let's actually put this in our code and see what
happens.
So I'm going to create a matrix.
Now one thing I didn't mention is I'm working with a set of helper functions and I worked
these functions out into separate video if you're interested but it's not, too much,
it's way too much to be in this video.
That has actually the matrix multiplication math in it, as well as some helper stuff to
do matrix multiplication with a matrix and a vector.
I'm going to have to change this to P4Vector, I'm just realizing that, but that's no problem.
Okay so what I first want to do is create that projection matrix.
So I'm just going to do it right here as a local variable and a little bit later it'll
sort of make sense why.
So I'm going to say, float projection equals, so I need to make that matrix which is an
array or arrays.
So there are three rows, 0, 1, 0, 0, and then 0, 0, 1, 0.
This is the equivalent of orthographic projection, if you've heard that term before.
Okay so now we've done that, then what I'm going to say is, P4Vector, actually P Vector,
I don't need it to be a P4Vector, I'm taking the 3D point.
P Vector equals matrix multiplication, the projection times V, okay?
So now it's telling me it doesn't know how to do matrix multiplication with a projection,
matrix, and V which is a P4Vector, which is strange because if I go in here it has a function
to matrix multiply a two dimensional array and a P Vector.
But I need this to be a P4Vector, okay.
Oh, vecToMatrix, doesn't know how to make a P4Vector, so I'm just going to change these
functions to deal with 4D.
M3 equals VW, so again if you want to see on a separate video where I wrote all this
code and now I'm just adjusting it to add this fourth dimension.
And then matrix to vec is going to be, you know what, I'm going to always be doing this,
this is fine, this stays the same, so that stays the same 'cause I still want, what I'm
going to get is a 3D vector inside a matrix and I want to turn it into a P Vector so let's
see.
Nobody's complaining at me and now I want to look at the projected points, projected,
projected, projected.
Here we go, oh what's wrong here?
Vec to matrix... array out of bounds exception.
I have an error somewhere, where is this called?
Oh this has to be four, this has to be a four.
So I forget that I'm in java and I really have to specify types and lengths of things
so that has to be a four.
Is there anywhere else where I need to do that?
We'll find out soon enough.
Okay, let's try this one more time, we're entering the fourth dimension.
Whoa, okay, it's still the same Why?
There are eight points in four dimensions.
Well guess what, if I took a cube and I showed it to you in orthographic projection facing
the camera basically it would look like just four points.
The four points on the back of the cube would be sitting right exactly behind the four points
at the front and you wouldn't see them as different.
Same thing is going on here, so what I actually need is not orthographic projection, I need
stereographic projection, I need to create that perspective.
And the way to do that is with moving, sort of thinking of a light source that has a certain
distance from the object that I'm casting a shadow.
So I'm going to create a variable, distance, and this is going to be, oh, you know one
thing I really should do is I'm going to take all these 100s and make them just the number
one.
I'm going to normalize my shape to just have all ones, it looks like a completely insane
person wrote this code.
And in fact, a completely insane person did write that code.
So I'm going to think of the camera as two units away and then the projection W is one
divided by that distance minus V.W, this is a sort of tried and true formula for creating
perspective projection.
And then I can put that W in here and now see what happens.
Do we have four dimensions?
Oh, I'm so close, I'm so close.
So I forgot that all my numbers are one so I'm just going to scale, there's a variety
of ways I could scale things up but I'm just going to do it right here.
So I multiply by 100 and now, oh look at that.
It kind of looks like that tesseract thing.
Wait a second, wait a second, wait a second, wait a second.
Oh this crazy, oh I got to connect the lines.
So first of all I need more, I guess I should make this smaller, let's make this 50, do
you see it?
That's that tesseract looking thing, the fourth dimension.
Our brains can't do this.
Connecting it will help, I'm going to connect all the lines.
Let's do that, I had a function that connects all the edges, I think I did this in the video
where I was just making a cube.
And these are P4Vectors now, oh no they're not, they're still P Vectors and I need to
connect, oh, I need to make, alright, everything's going to be okay, everybody, I'm going to
make an array P Vector projected.
Projected 3D which is an array is a new P Vector also with 16 points in it and I'm just
going to take projected 3D index i, there's no index, I'm going to add an index, that
is, I'm using this enhanced loop, I probably should just make it a four loop, let's make
it a four loop.
I got time to do that, you'll watch me do this.
Four int I equals zero, I is less than points.length, I plus plus and then P4Vector V equals points
index i.
So I'm manually iterating through it because now I can have this index and then with this
index, here, I can say I equals that projected v, projected, and then I can still draw these
here but now I can say projected 3D so I want to connect the various points there.
And so now I should see, that's just one, oh right, 'cause I got to do this twice.
Oh no, I got to do this all the way.
Oh, this is confusing I got to use the second half of the array which would be from like
eight to 12, I don't know.
I equals eight...that's not right.
Seven?
Zero, one, two, three, four, five, six, seven.
Eight, zero to four because if I want all the, oh module is, module is four plus eight.
Oh I made a horror-show out of this.
I went out of bounds, stop the presses!
Okay, I now realize that, I try not to do this, I try to have my videos be very self
contained and there's, you know, there's a few things that you might have to watch a
previous video for but I think it's worth explaining this just for a second.
So basically what I did in this connect function is this is a connect function to just take
two of the points and draw a line between them, and to draw a cube, right, normally
I might just say box or begin shape, end shape and it's going to sort of like make all these
connections for me but what I'm doing, what I'm doing is I basically have points zero,
one, two, three, four, five, actually it's zero, one, two, three, four, five, six, seven.
So that function is basically saying, connect zero and one, connect one and two, connect
two and three, connect three and zero, connect four and five, connect five and six, connect
six and seven, connect seven and four and then connect zero and four, one and five,
two and six, three and seven.
That's what that function is doing.
And so now I have two of them.
If I have another one, basically, it's along the four dimensional axis, I don't even know
where to draw that.
SO first of all all of its points start at eight, nine, 10, 11, 12, and this is not,
somebody watching this will give me some nice adjustments about how to completely refactor
this in a better way.
But you can see now I just need to connect these.
So the way I think I'm going to approach that is by I'm going to add another, I think if
I just add, like, an offset, like I can add an offset, this is kind of silly.
Here and then that offset could be zero.
And then that offset could be seven, right, 'cause then just want to do this.
And so this would just be I plus offset, J plus offset, so if I do this twice, and again
I could do this in one loop right, I could add an offset that's eight, is it eight?
I think it's eight.
There we go, ha, so now you can see I connected both cubes.
Now interestingly enough, what's the fourth dimension with this kind of perspective?
The fourth dimension is actually like, is W. W is expressed as kind of the distance
between these cubes.
Again we can only think about it, I can only describe it to you in three dimensional terms.
So for example you see this here, like if I were to put one of these points like at
negative five, look, it's all the way out there.
So this hypercube isn't perfectly symmetrical.
One of the points, it's W location, is all the way out along that axis and I make this
a variable and I could slide it around and do stuff like that, but I'm not going to do
that.
I haven't actually finished the connections, though, because what I want here is I need
to connect all these points to those points for the visualization to be fully complete,
that's actually going to be pretty easy.
Because all I'm doing in my array of 16 points, zero connects to eight, one connects to nine,
four connects to 12, five connects to three.
So that's actually easy, that's just another loop all the way through all the points and
I'm going to have with an offset of zero I connected to I plus eight.
So this should do this last set of connections.
Whoops, no somethings wrong here.
Oh, no, no, I only need to go through half the points 'cause the first half are connected
to the second bunch.
Alright, is this right?
This looks right to me.
Oh why is it going towards the center?
Something is wrong here.
Okay so if you're out of abrupt edit, you're not watching this live, you're watching the
recorded version, I just spent about 45 minutes trying to debug a problem and I went off completely
in the wrong direction.
Although it was a really interesting, lots of interesting tangents, I encourage you,
I'll link to the time code of the livestream where you can watch that whole part.
But I was trying to figure out why these points aren't connecting properly an I started doing
things like drawing numbers where all the points were and all sorts of stuff, but actually
the mistake, which you may have already seen and been singing to me about it, perhaps,
is right here.
Notice these parenthesis here, the formula for the perspective projection requires one
minus one divided by the distance minus the actual W point.
As soon as I put that in now all of the points are in the right place and those connections
are doing what they should do.
The actual draw points are little bit too large for my taste right now, I'm going to
take this to eight.
And this looks better now, okay.
So there we can see, there's our hyper cube in 3D.
Sort of, okay, let's take a deep breath here 'cause that was a lot of stuff and I got to
figure out where I am.
Oh, oh yes, rotation, before I get to rotation actually let me just mention one more thing
about this.
It was pointed out in the chat by many people that instead of trying to write some kind
of kooky, nonsensical, crazy person algorithm like I did here to figure out where all the
connections are, that you could actually just test for unit distance between the points,
right, because if you think about a square, right, you don't connect the diagonals 'cause
they're not distance, they have a different distance.
So if I look at the distance between all the points I'll find all the connections there.
So that's an interesting side project for any of you as an extra to do while you're
watching this.
But I want to talk about rotation.
So how is this rotation even happening in the first place?
I'm rotating in the third dimension, which is not really what I want to do.
I want to rotate in the fourth dimension, then project that down to the third dimension.
So let's try to back up, let's try to create exactly this by rotating in the fourth dimension
and then projecting back down in the third dimension.
The reason why I'm not actually doing the rotation in the fourth dimension is 'cause
the rotation is happening right here with the built in native rotate Y function.
That means rotating around the Y axis.
So how does rotation actually happen?
Well rotation happens with a rotation matrix.
So here I am on the Wikipedia page and you can see this rotation matrix right here.
So let's come back over here and let's think about that.
So this is rotation matrix, cosign of theta, negative sign of theta, sign of theta, cosign
of theta.
Did I get that right, looks like I did.
Alright so this is a 2D rotation matrix.
If I were to take this rotation matrix and do a matrix multiplication with any given
2D point this is exactly the math behind rotate in processing byte data.
This is exactly that.
So then what is the math behind rotate Y or rotate X or rotate Z?
And in fact is indeed also a rotation matrix only it's three by three rotation matrix.
And in fact if I come over here on this Wikipedia page about rotation matrices and keep scrolling,
keep scrolling and keep scrolling and keep scrolling, there we go, here it is, this is
the rotation matrix for around the Y axis and you can see a pattern here, right?
That's that 2D rotation but it's here within the Y and Z which is rotating around the X
axis.
Same pattern but between the X and the Z, between the X and the Y, that's how I get
all those different rotations.
But I want to do this in four dimensions so what I need do to, rotation in four dimensions,
is the following.
I need to pick which axis I want and I need a four by four matrix and in this case the
axis that I want, I'm going to use the X and Y axis and I'm going to say cosign theta,
negative sign theta, sign theta, cosign theta.
Oh and this has to be a one, apologies, and this has to be a one, right, 'cause it's the
identity matrix for Y and Z, basically.
The identity being just a one in those areas.
So I don't know if that's actually the right way to phrase it but anyway this is the rotation
matrix.
I'm going to call this, for 4D, this is rotation X, Y.
And actually what I was doing in rotate Y would be X, Z.
But anyway, we come back to the computer, I'm going to comment out rotate Y, so now
there's no rotation.
And actually just to be clear I'm going to start with rotate X, no rotate Z, I think
that'll be the simplest.
So I'm going to start with rotate Z, so I'm going to recreate exactly this.
This doesn't look super interesting 'cause of how flat it is but that's what I'm going
to start with.
'Cause I think that'll be the easiest one to do.
I want to recreate that with the matrix.
So the first thing I have to do is before I do the projection I have to create a rotation
matrix and I'm going to call this X, Y rotation.
And that is going to equal a matrix that has, I forgot already, cosign of the angle, negative
sign of the angle zero, zero, sign of the angle, cosign of the angle zero, zero and
then zero, zero, one, zero, zero, zero, zero, one, so this is my rotation XY matrix.
Autoformat, there we go, okay, so now what I need to do is I need to say P4Vector, right,
I want to get a rotated point which is the rotation, which is the matrix multiplication
result of the rotation matrix X,Y with V. That point V, now this is telling me it doesn't
know how to do this, remember I have all those helper functions?
The helper functions do these matrix multiplication operations, well I do have a helper function,
a matrix times a P4Vector, I have that.
But look at it, it returns a P Vector 'cause I have the one to give me a 3P Vector back.
I should probably just leave everything as P4Vectors, it would make our life so much
easier.
There's not really any reason for me to use P Vector at this point 'cause I could always,
but I'm going to, I've done what I've done We can think about refactoring it later which
is like a little bit of my mantra and I'm going to say...
This still works, so I want to say if, so this is matrix to vec, I need another one
of these which does, I'm just going to write this function.
I don't think I need this anymore 'cause it's always going to have three dimensions.
That was sort of an extra thing, just to simplify this I'm going to make another function that's
going to be called matrix to vec four, and I'll make a P4Vector and then I'm going to
say V.W is this, so I made a different function and this returns a P4Vector, P4Vector.
So I just made a helper function that takes a, oh I don't have that up, zero, zero, zero,
zero.
That basically takes a matrix that has one column, right, this is what it is, it's a
matrix with one column and four rows and turns this into a P4Vector.
I need that because down here I now want to say, I'm going to say results equals matmul
A and M and then I'm going to say, if result.length.
So how many rows, do I have four rows or not?
Equals four, then return, oh no wait, I can't have it return two different types.
I'll just have to do this, oh, java is a weird place.
Right, it can't return something of a different type.
So I'm going to just pass a bullion in I'm going to pass our dimensions like int dim.
So I don't even need to figure it out, if dimensions equal four, oh no it's the same
problem.
Oh, oh I couldn't, oh no, I could just overload it.
Alright, I'm going to overload it, sorry everybody.
So this is...
Sorry for these digressions and making this video extra long, yay for me.
This is what it was before, right?
Returning a matrix to vec, oh no, return, sorry, sorry everybody, this...
There, this is what it was before.
Now what I'm going to do is I'm going to just, this is very awkward but I'm going to add,
I'm going to say a bullion or a fourth, this is sort of silly, and I'm just going to say,
matrix to vec four and it returns a P4Vector.
Okay so I made two versions of this function.
This is very silly, I should've just made, but it is what it is Okay, could we get back
to what we were doing?
Which was important, so now I'm going to say mat mole rotation X,Y true so this should
return a 4D vector then now I want to get the W of the rotated vector, right?
'Cause I'm about to calculate the projection matrix, I'm not going to use the original
point, I want to use the point that's been calculated after the rotation and now we should
seeI projected V again so this down here needs
to be rotated also.
There we go, I have now created exactly zero rotation with my own rotation matrix.
We're getting really close everybody, this is very exciting.
So now I have a rotation X,Y, just to prove a point let's do rotation, what was the one
we saw with it spinning like this?
Let's do rotation X,Z meaning zero goes here.
Meaning a one goes here, a zero goes here.
Let's look at this, is this right?
I think this is rotation with X and Z, one in the Y and one in the W. So let's now change
that to X, Z here and then look.
There we go, I have it just rotating around what looks like the Y axis, okay, exciting.
Now watch this, what if I want to apply more than one rotation?
So here I've rotated by XZ, now I can just rotate again by rotating by X, Y, what's wrong
here?
Multiply rotation X, Y by rotated true.
Oh so I don't want to redeclare the variable.
And here we go, now we see both rotation.
But everything still feels very much like all I did was make two 3D cubes and connect
the corners.
So that's what you're seeing, right, because that's the shadow of what the four dimensional
shape in the only way our brains can process, 3D.
But let's really try to stretch our brains for a second.
What if I include, this is really where things are going to go nuts, what if I include the
W axis?
What does it mean to rotate around the W axis?
Think about that for a second.
Okay rotate around the Y, rotate around the X, rotate around the Z,, you can't even, that
W axis that was kind of like extruding, who knows what that's even going to be.
Let's see what that looks like.
We are now really about to enter the fourth dimension.
Okay, okay, okay, let's try, what do I want?
X, W, I don't know what's a good one to start with.
Let's try X, W, so I'm going to make a rotation matrix X, W. Okay here we go, so X and a zero
goes here, then that stays the same then this should be in the bottom and a zero goes here,
get rid of this comma, get rid of this zero, and then the one goes here.
So let's actually just for, I'm afraid to add too many rotations so let's do X, W and
let's comment these out.
So I am only using rotation around the X, W axis.
We're entering the fourth dimension.
This isn't right Something is wrong there.
It did something interesting though Alright, what's it that, oh, you know what most people
do, I think actually, is not Z, W, so let's do Z, W. Let's put this here and then these
go away.
I mean, I just want to see that I'm doing this correctly.
And then this would be one, zero, zero, one, so let's try Z, W and let's see what this
does.
Okay this is actually correct.
Now it looks really weird but I think I'm going to be able to fix this, I'm just going
to do something really quickly just as a test, just want to like rotate it on its side.
It would be this side.
No, something is still wrong.
I'm back again, I was trying to figure out why this was wrong and then I realized, oh,
this is actually right.
I'm used to seeing a certain pattern and I've just got the viewing angle slightly wrong
or slightly different.
So basically let me comment this line rotate Y out.
The two rotations that I'm doing right now are X,Y, Z,W. And if we do that just natively,
the way that I drew the cube, you sort of see the Z rotation and that W rotation projected
into the 3D world, it's like kind of coming in and out, almost looks like breathing.
And so what I actually want to do is just rotate along the X axis to put things on the
side.
And I could do that with a rotation matrix but because I have a full 3D renderer I'm
going to say rotate X, negative pi divided by two and there we go.
Now this should look like the tesseract visualization that you're used to seeing.
This is that W rotation like rotating.
And by the way, we have now...
Entered the fourth dimension.
You know, it was a little bit anticlimatic I guess.
But here, we're done, this coding challenge is complete.
And I just want to stop, I'm not going to do anymore because I'm going to leave this
for you.
Let's think about all the kinds of things you could do to this to make this more beautiful
or interesting or weird.
First of all, you know, what are all sorts of other rotation matrices you could apply?
What's like a three axis rotation?
You could certainly do that, right?
What multi, how many, this is a double rotation.
Could you do a triple or quadruple?
What if you tried a bunch of different other axis with the W axis, you know, I'm just drawing
these little points and connecting them with lines.
There are probably so many other ways you could think to visualize the pattern of the
tesseract.
You can now enter the fourth dimension, project it into the third dimension, and see a result.
I'll also make a javascript version of this using the P5GS Library which has a web GL
renderer, although in theory I don't even need a 3D renderer 'cause I could project
the 4D points to 3D and then project the 3D points to 2D.
If you really want a hard problem try doing that.
Ah, but really, I ask you, how many, how, what dimension can you project down into three
dimensions and visualize?
Can you get up to five, to six, to seven, what happens?
So I encourage you, I challenge you to try all sorts of weird stuff, to make some beautiful
art and enjoy spending time in the fourth dimension.