# 4d rotation of a cube

This topic is 4328 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am experimenting with rotations in 4d, and I am currently rotating a simple 3d cube in 4d. When I rotate on the ZW plane, the cube rotates exactly how I would expect it to. However, if I rotate around the XW plane, the cube seems to flatten itself into the shape of a square and rotate on the XZ plane, which seems very wrong to me. If I add another rotation on the XZ or YZ plane, the cube begins to turn inside out and such like I would expect it to. Is this correct behavior, or have I done something wrong? I have the rotation matrices set up like so:
XW plane:
cos  0  0  sin 0
0    1  0  0   0
0    0  1  0   0
-sin 0  0  cos 0
0    0  0  0   1

YW plane:
1 0   0  0    0
0 cos 0  -sin 0
0 0   1  0    0
0 sin 0  cos  0
0 0   0  0    1

ZW plane:
1    0  0    0   0
0    1  0    0   0
0    0  cos  sin 0
0    0  -sin cos 0
0    0  0    0   1



##### Share on other sites
I'm definitely not sure about this, but if I imagine a square rotating in 3d it appears to flatten into a line while rotating about an axis. I'm guessing that the cube is doing the same thing in 4d.

To a 2d observer, the square rotating in 3d (with the third dimension inaccessible to the observer) looks like a square flattening into a line while wobbling back and forth (actually growing larger and smaller, but a 2d observer can't see this).

Try rotating your view in 4 dimensions and see if you can get a subspace where it looks the way you expect.

##### Share on other sites
I understand what you mean; the cube should seem to flatten into a square as it rotates through the 4th dimension. However, the cube does not flatten, expand, and turn itself inside out like I would expect. Instead, it just stays the same width (which is 0) and rotates on the XZ plane, which I find very strange. It's the same effect as scaling the Z dimensions to 0 and rotation on the XZ plane. Though, since I can't find much information about 4d rotation on the internet, I'm not even sure if this is incorrect behavior.

4D gimbal lock?

##### Share on other sites
I'm not familiar with gimbal lock in 4d, but I don't think it would happen with just a single isolated rotation. Can anyone with knowledge of 4d rotations verify that my matrices are correct?

##### Share on other sites
I'm not sure of the details but at worst your matrices are rotating by -theta instead of theta, since transposing them inverts them and the sines and cosines are set up in such a way that the matrices must be rotations (the determinant is always 1 and not -1, so they're all pure rotations without reflections).

What are you actually rendering? Are you projecting the 4d points into three dimensions, which then goes through the graphics pipeline as usual, so you're really rendering a sort of 3d "shadow" of the cube in the fourth dimension?

##### Share on other sites
That is exactly what I am doing. From what you have said, the matrices appear to be correct (if the sines are reversed that's no big deal). I have seen other tesseract rotations in 4d, and I think the type of rotation I am getting is incorrect. However, it does seem to be correct when I rotate on the ZW plane, unless I rotate it 90 degs on the YZ plane first. It all seems very strange to me, though perhaps this is just normal behavior. Does anyone know?

##### Share on other sites
I just came across this page that explains four dimensional cubes, and along the way it demonstrates rotation of a 3d cube in four dimensions, in a short downloadable video. The rotation causes the cube to wave back and forth with one of the axes appearing to periodically invert itself (because of the 4 dimensional rotation turning the cube inside out).

It seems really likely that there's a bug in your code somewhere.

##### Share on other sites
Thanks a lot Vorpy. I checked out that link to see what the rotations should be looking like from that perspective, and it turns out that it was a bug in my code. I had used OpenGL's translate function, which translated the cube -5 on the z-axis (so I could see the cube). I didn't think to realize that OpenGL performs the translation after the projection from 4d to 3d. When I moved the translation so it was before the projection, it rotated just as the link depicted.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634092
• Total Posts
3015437
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!