473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Projecting 4D points into 3D space using matrices

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



Jun 27 '08 #1
4 2435
On 2008-06-04, Peter Webb <we********@DIESPAMDIEoptusnet.com.auwrote:
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.
You definitely want them perpendicular to each other, or your
projection will be "skewed".

Yes, you'll need a "forward" direction, an "up", and a "left" (or
"right"). The other 4D direction (whatever you want to call it) will
just be perpendicular to those.

I am pretty sure that I just need a constant 4x3 matrix T
A 4x3 matrix will handle rotation and orthographic projection.
However, it will not handle translation or perspective projection.

To accomplish the translation, you either need to go to 5-component
homogeneous coordinates and hence a 5x3 matrix, or subtract your eye
coordinates from the points before you apply the transformation.

For perspective, you'll need a 4x4 matrix (or 5x5 for homogeneous
coords) and clipping planes, then divide the results by the z
("forward") coordinate.

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

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.
- Tim
Jun 27 '08 #2
>
>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.

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.

>
- Tim
Really helpful response. Thank you.
Jun 27 '08 #3

"Peter Webb" <we********@DIESPAMDIEoptusnet.com.auwrote in message
news:48***********************@news.optusnet.com.a u...
>>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.

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

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

>>
- Tim

Really helpful response. Thank you.

Jun 27 '08 #4
On 2008-06-04, Peter Webb <we********@DIESPAMDIEoptusnet.com.auwrote:
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?).
There is a lot of freedom in their choice. Given V1, you can treat
V1.V2 = 0 as a linear equation in the coefficients of V2, which you
can solve - ending up with 3 free variables, though then you need to
normalize. Likewise for V3 you can treat V1.V3 = V2.V3 = 0 as a
system of two linear equations, which can also be solved, and so on.

This gives me the first three columns of T^-1 as: [V1,V2,V3 ?] -
what's the fourth column? The zero vector?
The fourth vector is uniquely determined from the other three by the
condition that it be orthogonal, unit, and the matrix having
determinant +1. (The -1 solution corresponds to a reflection rather
than a rotation)
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
....
Is that it?
No, to get perspective you then need to discard any bits with negative
d, probably clipping against the boundaries of your viewing space, and
divide (a,b,c) coordinates by d.
- Tim
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kyler Laird | last post by:
I'm trying to do some georeferencing - using points of known location (ground control points, GCPs) on an image to develop a polynomial that can be used to approximate the locations of other...
2
by: Francis il Mulo Parlante | last post by:
Hi, I have made a program in c++ that produces some points in a cubic space with cordinate x y z. I wanted to ask you if you know a library of the compiler of linux that helps me to graphically...
4
by: shan | last post by:
Can any one tell me an Input function that terminate by pressing spacebar and not return key. Functions like scanf,getchar,getc when invoked they allow whatever typed after a space they terminate...
8
by: bevanward | last post by:
Hi all I have a large data set of points situated in 3d space. I have a simple primary key and an x, y and z value. What I would like is an efficient method for finding the group of points...
9
by: John | last post by:
I'm sorry if this is sounding like somewhat of a noob question. I'm loading in a large binary array of 8x8 double precision floating point matrices, right now this is defined something like ...
1
by: Anjola | last post by:
if I haveto multiply two matrices one 3x2 and the other 2x3, what threads I have to create . I know that there are 10 of them. #include <stdio.h> #include <iostream.h> /* Allocate memory for a...
6
by: BJörn Lindqvist | last post by:
Hello, I'm looking for an algorithm to project "MUD maps" such as the following map: http://www.aww-mud.org/maps/MUD_Maps/Caerin-colour.jpg MUD:s consists of rooms, each rooms has up to four...
9
by: tomamil | last post by:
imagine that you have different matrices with different names and you want to perform the same action with each of them. is it possible to put their names into some array and to create a loop that...
3
by: itmfl | last post by:
We are writing a program that multiplies two matrices of size n x m and m x n together. The matrices are stored in a file. The user provides the filename in the command line prompt. The file is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.