4D Rotation Matrix - Graph 4D
This program rotates points about the XY, YZ, XZ, XU, YU, and ZU axises. I then projects each 4D vector to the 2D canvas.
The Jar file can be downloaded here: Graph4D.jar
![]() |
![]() |
Before looking at the source, let’s take a look at some of the fundamental mathematics behind the software.
If you are uncomfortable with the thought of 4D matrix rotations, then I recommend reading Wikipedia, or checking out my article about 3D graphing, which can be found here. In this example, I will only show the 4D rotation matrices. Note that for each rotation matrix, 2 axises are held still while the vector is rotated around the other two axises. This may be hard to visualize at first, but It will become clear after a while.
![rotXY = delim{[}{matrix{4}{4}{{cos(theta)} {sin(theta)} 0 0 {-sin(theta)} {cos(theta)} 0 0 0 0 1 0 0 0 0 1}}{]} rotXY = delim{[}{matrix{4}{4}{{cos(theta)} {sin(theta)} 0 0 {-sin(theta)} {cos(theta)} 0 0 0 0 1 0 0 0 0 1}}{]}](http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_386f86decb4f40b917dfd6db830318eb.png)
![rotYZ = delim{[}{matrix{4}{4}{1 0 0 0 0 {cos(theta)} {sin(theta)} 0 0 {-sin(theta)} {cos(theta)} 0 0 0 0 1}}{]} rotYZ = delim{[}{matrix{4}{4}{1 0 0 0 0 {cos(theta)} {sin(theta)} 0 0 {-sin(theta)} {cos(theta)} 0 0 0 0 1}}{]}](http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_d339828f569aa5fef53964595e60e7dc.png)
![rotXZ = delim{[}{matrix{4}{4}{{cos(theta)} 0 {-sin(theta)} 0 0 1 0 0 {sin(theta)} 0 {cos(theta)} 0 0 0 0 1}}{]} rotXZ = delim{[}{matrix{4}{4}{{cos(theta)} 0 {-sin(theta)} 0 0 1 0 0 {sin(theta)} 0 {cos(theta)} 0 0 0 0 1}}{]}](http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_68fa0611192405b45f28bdf0af541d03.png)
![rotXU = delim{[}{matrix{4}{4}{{cos(theta)} 0 0 {sin(theta)} 0 1 0 0 0 0 1 0 {-sin(theta)} 0 0 {cos(theta)}}}{]} rotXU = delim{[}{matrix{4}{4}{{cos(theta)} 0 0 {sin(theta)} 0 1 0 0 0 0 1 0 {-sin(theta)} 0 0 {cos(theta)}}}{]}](http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_bae5dc667d825cb897c4d017c7a422d3.png)
![rotYU = delim{[}{matrix{4}{4}{1 0 0 0 0 {cos(theta)} 0 {-sin(theta)} 0 0 1 0 0 {sin(theta)} 0 {cos(theta)}}}{]} rotYU = delim{[}{matrix{4}{4}{1 0 0 0 0 {cos(theta)} 0 {-sin(theta)} 0 0 1 0 0 {sin(theta)} 0 {cos(theta)}}}{]}](http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_ab7a54a79ef160a0aa918151d9d55ce9.png)
![rotZU = delim{[}{matrix{4}{4}{1 0 0 0 0 1 0 0 0 0 {cos(theta)} {-sin(theta)} 0 0 {sin(theta)} {cos(theta)}}}{]} rotZU = delim{[}{matrix{4}{4}{1 0 0 0 0 1 0 0 0 0 {cos(theta)} {-sin(theta)} 0 0 {sin(theta)} {cos(theta)}}}{]}](http://ken-soft.com/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_941.5_75c90de6d3b518ddba1001f07fa85adf.png)
The source code can be found below as well as being bundled into the Jar file.
Transform4D.java - contains method for rotating a 4D vector











[...] Graph4D - Rotation4D - Project to 2D [...]
Thank you!
Finally! I was looking for a wireframe 4D graph to play with. Thanks.
np. glad it is useful
hmm… does this mean that to express any four dimensional rotation, you need 6 angle values?
>NeuroFuzzy
No. It just means that there are 6 different elementary ways to rotate a 4D Vector (X, Y, Z, U).
Possible rotations in 4D space include:
X vector around the Y
X vector around the Z
X vector around the U
Y vector around the Z
Y vector around the U
Z vector around the U
So this leaves 6 rotations, (of course removing symmetric rotations. i.e. XU = UX, YU = UY, etc)
in 5D space (X, Y, Z, U, W) you would then have
X vector around the Y
X vector around the Z
X vector around the U
X vector around the W
Y vector around the Z
Y vector around the U
Y vector around the W
Z vector around the U
Z vector around the W
U vector around the W
for a total of 10 rotation matrices.
thank you for the fast reply! I’m trying to make a 4 dimensional object viewer, and I’m wondering how many different user inputs i would need to be able to be able to show all possible rotations of a four dimensional object. Euler’s rotation theorem states that you only need 3 angles to describe an arbitrary rotation, but that only applies to 3 dimensions. I guess that i’ll start out using the result of six rotation matrices… but i really don’t want to if i can use fewer.
No problem. and yes these rotation matrices only describe the rotation around a specific Axis. You would need to derive a rotation matrix for rotations around any given vector (which is possible, though I honestly am not sure how to do this off the top of my head),
Refer to my 3D rotation matrices page and note that I use quaternions to define a rotation around any arbitrary axis as it is simpler. I’m going to guess that there exists a similar method for mapping 4D rotations.
As for a 4 dimension object viewer, I will be uploading various 3D function and 4D function/object viewing software I recently flung together in C++. They have correspondingly contain a Vector3D.h and Vector4D.h file with some useful rotation functions. and getUnitVector() functions.
Also, about a 4D viewer, since 4D is not directly viewable you will have to come up with some “creative” way to represent it. for example, taking a “slice” of the 4D object, which is 3D and displaying it. So in a sense draw multiple slices. Or do something like change the color of the dot depending on it’s 4D value. so High 4D values represent a White pixel and fade to Blue or Black as the values go more negative. Etc.
Also dig through the source files (included in the JAR) on this page and you’ll see how it all works.
I’m planning to have a 3d-to-2d camera, which the user views through a standard camera, controlled by the movement of the mouse. The 3d world will be given by a 4d-to-3d camera, IE 4D lines intersecting a 3d cube, as opposed to 3d lines intersecting a 2d plane.
If things get too complicated, doe to the nature of euler angles (problems like gimbal lock, and odd rotation patterns), i might limit the program to rotation on the YU axis, for now.
Besides that, i’ll definitely take a look at all the source code, it might be really helpful