4d Java Help

Discuss interdimensional programming, Java applets and so forth.

4d Java Help

Postby Nick » Wed Oct 04, 2006 11:22 pm

Hello,
I am learning Java in school and I recently downloaded Java 3d. I would like to use Java 3d to start making rotating 4d images in scripts of some sort. However, I don't know anything about rotating 4d objects. So, this is a programming noob looking for help. Anybody willing? :)
I am the Nick formerly known as irockyou.
postcount++;
"All evidence of truth comes only from the senses" - Friedrich Nietzsche

Image
Nick
Tetronian
 
Posts: 841
Joined: Sun Feb 19, 2006 8:47 pm
Location: New Jersey, USA

Postby pat » Thu Oct 05, 2006 3:22 pm

Java3d will help you represent polygons, segments, and points in three-dimensional space. To display rotating 4d objects, you'll need a few things:
  • coordinates for the vertexes of a 4d object
  • knowledge of which vertexes are connected by edges
  • (optional, if wireframing) knowledge of which vertexes are on the same face
  • (optional) knowledge of which vertexes on the same facet
  • a way to rotate the vertexes
  • a way to project the vertexes from 4d down to 3d


The hypercube is the easiest to describe. The vertexes coordinates are { +/- 1, +/- 1, +/- 1, +/- 1 }. Two vertexes are connected by an edge if they differ in only one coordinate. Four vertexes are on the same face if no vertex differs from any other vertex on more than two coordinates. Eight vertexes are on the same facet if no vertex differs from any other vertex on more than three coordinates.

The usual internal representation is that one keeps an array of vertexes. Then, one keeps a list of faces or edges that refer to the vertexes (either just a direct reference or by the index of the vertex in the array).

Rotating an object involves matrix multiplication. (Technically, you could do it with quaternions, too... but it's not clear to me how to specify a particular 4d rotation using quaternions.... I understand how to use quaternions for 3d rotation, but I haven't had time to explore using them for 4d rotation.... anyhow... quaternions won't help you with 5d next month). Java3d has stuff in there to let you multiply matrixes, but it will be awkward to use since Java3d is geared toward 3-dimensional stuff. You're going to need to multiply together 4x4 or 5x5 matrixes.

For now, say you've got a matrix R that represents a tiny increment of rotation and another matrix O that represents the object's current orientation. Then, to rotate the object a little more to get its new orientation matrix O', you do: O' = O * R.

Then, to represent the object on the screen, you take the original coordinates for each vertex and multiply them by the orientation matrix to get a rotated coordinate. I suggest leaving the original coordinates inviolate and keeping a separate array for rotated coordinates.

Then, you have to project the coordinates down from 4d to 3d. Then, you have to render the object.

I'd suggest starting with some classes like this, to get you going:
Code: Select all
public class Vertex4D {
    private double[] originalCoords = new double[ 4 ];
    private double[] rotatedCoords = new double[ 4 ];
    private double[] projectedCoords = new double[ 3 ];

    public Vertex4D( double[] _coords ) {
        // copy _coords into this.originalCoords
    };

    public void rotate( Matrix _mm ) {
        // multiply this.originalCoords by matrix, put into this.rotatedCoords
    };

    public void projectCoords( /* params? */ ) {
        // project this.rotatedCoords into this.projectedCoords
    };

    public void render() {
        // glVertex3d( this.projectedCoords[0], this.projectedCoord[1], ... );
    };
};

public class Edge4D {
    private Vertex4D aa;
    private Vertex4D bb;

    public Edge( Vertex4D _aa, Vertex4D _bb ) {
        this.aa = _aa;
        this.bb = _bb;
    };

    public void render() {
         // glBegin( GL_LINES );
         //     this.aa.render();
         //     this.bb.render();
         // glEnd();
    };
};

public Shape4D {
    private Vertex4D[] vertexes;
    private Edge4D[] edges;

    ...

    public void rotate( Matrix _mm ) {
         // rotate each vertex
    };
    public void render() {
         // project each vertex
         // render each edge
    };
};


In practice, people usually use "homogeneous coordinates" where instead of keeping {x, y, z, w }, they keep { x, y, z, w, 1 }. Then, they use 5x5 matrices for things. If you understand why, bonus. If not, more on that some other time.
pat
Tetronian
 
Posts: 563
Joined: Tue Dec 02, 2003 5:30 pm
Location: Minneapolis, MN

Postby Nick » Fri Oct 06, 2006 7:46 pm

I do not understand the significance, or the purpose of [] after the variables... does [] mean their arrays? :sweatdrop:
I am the Nick formerly known as irockyou.
postcount++;
"All evidence of truth comes only from the senses" - Friedrich Nietzsche

Image
Nick
Tetronian
 
Posts: 841
Joined: Sun Feb 19, 2006 8:47 pm
Location: New Jersey, USA

Postby Keiji » Fri Oct 06, 2006 8:11 pm

yes
User avatar
Keiji
Administrator
 
Posts: 1984
Joined: Mon Nov 10, 2003 6:33 pm
Location: Torquay, England

Postby Nick » Fri Oct 06, 2006 8:36 pm

Sorry, I forgot to meantion the "_" before certain words; what does that mean? :\
I am the Nick formerly known as irockyou.
postcount++;
"All evidence of truth comes only from the senses" - Friedrich Nietzsche

Image
Nick
Tetronian
 
Posts: 841
Joined: Sun Feb 19, 2006 8:47 pm
Location: New Jersey, USA

Postby Keiji » Fri Oct 06, 2006 8:37 pm

Nothing, it's just a part of the variable name./
User avatar
Keiji
Administrator
 
Posts: 1984
Joined: Mon Nov 10, 2003 6:33 pm
Location: Torquay, England

Postby pat » Fri Oct 06, 2006 9:56 pm

In many Java programs, it's hard to tell what things are member variables, what things are local variables, and what things are method arguments. In all of my code, I explicitly reference member variables with "this.", and I have method arguments start with an underscore. Then, if you see a variable without "this." and without a leading underscore, you know it was defined in that method.
pat
Tetronian
 
Posts: 563
Joined: Tue Dec 02, 2003 5:30 pm
Location: Minneapolis, MN

Postby Nick » Fri Oct 06, 2006 10:22 pm

Hmmmm... it looks like I need to read up on some more java3d stuff to understand this code...
I am the Nick formerly known as irockyou.
postcount++;
"All evidence of truth comes only from the senses" - Friedrich Nietzsche

Image
Nick
Tetronian
 
Posts: 841
Joined: Sun Feb 19, 2006 8:47 pm
Location: New Jersey, USA


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron