Ken-Soft

Software and the World

4D Rotation Matrix - Graph 4D

Posted under General Development, Java, Mathematics, Programming by Kenny on Thursday 8 January 2009 at 3:52 pm
Bookmark and Share

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 = delim{[}{matrix{4}{4}{{cos(theta)} {sin(theta)} 0 0 {-sin(theta)} {cos(theta)} 0 0 0 0 1 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}}{]}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}}{]}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)}}}{]}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)}}}{]}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)}}}{]}

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


9 Comments »

  1. Pingback by Ken-Soft » Graph3D - Rotation3D - Project 3D to 2D — January 8, 2009 @ 4:17 pm

    [...] Graph4D - Rotation4D - Project to 2D [...]

  2. Comment by Onendehopolve — February 24, 2009 @ 4:27 am

    Thank you!

  3. Comment by Joe Whitehead — July 21, 2009 @ 1:38 am

    Finally! I was looking for a wireframe 4D graph to play with. Thanks.

  4. Comment by Kenny — July 21, 2009 @ 12:03 pm

    np. glad it is useful :)

  5. Comment by NeuroFuzzy — December 7, 2009 @ 1:30 am

    hmm… does this mean that to express any four dimensional rotation, you need 6 angle values?

  6. Comment by Kenny — December 7, 2009 @ 2:25 am

    >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.

  7. Comment by NeuroFuzzy — December 7, 2009 @ 6:18 pm

    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.

  8. Comment by Kenny — December 8, 2009 @ 12:38 am

    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.

  9. Comment by NeuroFuzzy — December 8, 2009 @ 9:40 pm

    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 :)

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Copyright © 2009 www.Ken-Soft.com