4D Rotation Matrix - Graph 4D

Posted on by Kenny Cason
tags = [ 3d, 4d, graph, java, matrix, projection, rotation, transformation, vector ]

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

4D rotation matrix java 4D rotation matrix java

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 = \left[\begin{array}{cccc} cos(\theta) & sin(\theta) & 0 & 0 \\ -sin(\theta) & cos(\theta) & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{array}\right]

rotYZ = \left[\begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & cos(\theta) & sin(\theta) & 0 \\ 0 & -sin(\theta) & cos(\theta) & 0 \\ 0 & 0 & 0 & 1 \end{array}\right]

rotXZ = \left[\begin{array}{cccc} cos(\theta) & 0 & -sin(\theta) & 0 \\ 0 & 1 & 0 & 0 \\ sin(\theta) & 0 & cos(\theta) & 0 \\ 0 & 0 & 0 & 1 \end{array}\right]

rotXU = \left[\begin{array}{cccc} cos(\theta) & 0 & 0 & sin(\theta) \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ -sin(\theta) & 0 & 0 & cos(\theta) \\
\end{array}\right]

rotYU = \left[\begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & cos(\theta) & 0 & -sin(\theta) \\ 0 & 0 & 1 & 0 \\ 0 & sin(\theta) & 0 & cos(\theta) \end{array}\right]

rotZU = \left[\begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & cos(\theta) & -sin(\theta) \\ 0 & 0 & sin(\theta) & cos(\theta)
\end{array}\right]

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

Transform4D.java

Point4D.java

Graph4D.java

comments powered by Disqus