Projecting 4D points into 3D space using matrices

P

Peter Webb

I am writing some visualisation code for 4 dimensional geometric shapes.
This is to run in the C# .NET XNA environment, so I am cross posting a maths
and C# group.

My software runs just fine for 3D objects - for example I can draw cubes,
tetrahedrons, icosahedrons etc and rotate them on screen. All of the "heavy
lifting" is done by the XNA libraries, which have transformation libraries
to map 3D constructs onto 2D with perspective. Using the standard XNA
libraries, I can draw the 3D objects as seen from any point of view in 3D
space, rotate them, etc.

My plan is to construct my 4D objects using a series of 4 Vectors specifying
each vertex. I then project these vertices onto 3D space from a particular
viewpoint and feed these 3D objects into my existing 3D code.

In 3D, to convert to 2D, I do this by defining the viewpoint as a Vector3
(say x,y,z), the point I am looking towards (which can be (0,0,0)), and an
"up" unit vector (perpendicular to (x,y,z)) which defines which way is "up"
in the presented view. XNA then does the Matrix transformation 3D -> 2D for
me.

I need to create a similar transformation matrix for 4D to 3D.

I have a viewpoint in space - say (x1, y1, z1, w1). I need to know the
co-ordinates of another point - (x2, y2, z2, w2) as a Vector3 (a,b,c) if I
am looking from my viewpoint towards (say) the origin. By analogy with the
3D to 2D case, I will need to define one or possibly two unit vectors
perpendicular to (x1,y1,z1,w1) - though not necessarily perpendicular to
each other (?) - that define the "up" direction and maybe the "left"
direction.

So I need a transformation matrix T, based on (x1,y1,z1,w1) and one or
possibly two unit vectors perpendicular to (x1,y1,z1,w1) which will map any
point (x2,y2,z2,t2) onto a 3D point (a,b,c), corresponding to where it
appears in 3D space from that 4D viewpoint.

I am pretty sure that I just need a constant 4x3 matrix T, and I multiply
each of my 4D vectors (representing vertices) by this matrix T to get the 3D
projection.

Does anybody know what T will look like? I haven't been able to find an
example on Google, and my math skills/visualisation ability is not
sufficient to construct T explicitly myself.

Alternatively, any other way to skin this cat?

TIA


Peter Webb
 
P

Peter Webb

Consider the inverse of (a 4x4) T: it will map the y-axis to your "up"
vector, the x-axis to your "right" vector, the z-axis to your
"forward" vector, and the w-axis to your "other" vector. So the
columns of this matrix will just be your view directions. Invert
that, and you have T. In the case of rotation matrices, the inverse
is just the transpose.

This is the case that I think I want!

So I am looking from V1= (x1, y1, z1, t1). I generate two other unit vectors
V2 and V3 with the property that V1.V2=V1.V3=V2.V3 = 0. These are where I
want "up" and "right" to be. (Is there an easy way to generate these
vectors?).

This gives me the first three columns of T^-1 as: [V1,V2,V3 ?] - what's the
fourth column? The zero vector?

That would appear to make sense, because after applying the transformation
one of the dimensions disappears.

So, before I code all this up, I:

1. Construct the matrix T^(-1) comprising [V1,V2,V3,0] - (do I have to
divide by the determinant to normalise it)?

2. Invert the matrix to form T. Then T*(x,y,z,t) = (a,b,c,d)

The a, b, and c are my new x, y and z; the d should be zero plus or minus
rounding errors.

Is that it?


If you just want orthographic projection, drop the "forward" vector
giving a 4x3 matrix. Otherwise leave it in, clip the resulting
shapes, and divide by the resulting z value.

No, if I am trying to assist visualisation then perspective is important. I
can always move my viewpoint a thousand times further back and use a
thousand times smaller viewing angle to get this anyway.


Really helpful response. Thank you.
 
P

Peter Webb

Peter Webb said:
Consider the inverse of (a 4x4) T: it will map the y-axis to your "up"
vector, the x-axis to your "right" vector, the z-axis to your
"forward" vector, and the w-axis to your "other" vector. So the
columns of this matrix will just be your view directions. Invert
that, and you have T. In the case of rotation matrices, the inverse
is just the transpose.

This is the case that I think I want!

So I am looking from V1= (x1, y1, z1, t1). I generate two other unit
vectors V2 and V3 with the property that V1.V2=V1.V3=V2.V3 = 0. These are
where I want "up" and "right" to be. (Is there an easy way to generate
these vectors?).

This gives me the first three columns of T^-1 as: [V1,V2,V3 ?] - what's
the fourth column? The zero vector?

That would appear to make sense, because after applying the transformation
one of the dimensions disappears.

So, before I code all this up, I:

1. Construct the matrix T^(-1) comprising [V1,V2,V3,0] - (do I have to
divide by the determinant to normalise it)?

2. Invert the matrix to form T. Then T*(x,y,z,t) = (a,b,c,d)

The a, b, and c are my new x, y and z; the d should be zero plus or minus
rounding errors.

Is that it?

This can't be correct. The determinant of a matrix with a column comprising
the zero vector can't be inverted, because the determinant is zero. This is
exactly the behaviour we want in the transformation matrix, as it reduces 4
dimensions down to 3, but we can't form it from [V1, V2, V3, 0] as its not
invertable.

Help ... please ... I've almost got it (I think).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top