# 3d to 2d mapping

Discussion in 'Java' started by Miguel De Anda, Jun 27, 2003.

1. ### Miguel De AndaGuest

I'm trying to write a little script that draws dots into a 3d space. It is
very small and has only 30 dots (5 by 6). These dots are on fixed x, y
positions but I need to position them on various z positions. I want to make
the z axis to be vertical (on the screen) and the x to be to the right (and
down a little bit) and the y to be back into the screen (and right a little
bit). I took a linear algebra class that covered how to do such
transformations but my brother has the book right now. Can anybody help me?
I simply need some matrix or something that I can multiply my [x, y, z] by
to get my new [x, y] positions that would appear to be in 3d on the screen.
This is just going to be for a demo that I need to do. Thanks.
Miguel De Anda, Jun 27, 2003

2. ### pete kirkhamGuest

Miguel De Anda wrote:

> I'm trying to write a little script that draws dots into a 3d space. It is
> very small and has only 30 dots (5 by 6). These dots are on fixed x, y
> positions but I need to position them on various z positions. I want to make
> the z axis to be vertical (on the screen) and the x to be to the right (and
> down a little bit) and the y to be back into the screen (and right a little
> bit). I took a linear algebra class that covered how to do such
> transformations but my brother has the book right now. Can anybody help me?
> I simply need some matrix or something that I can multiply my [x, y, z] by
> to get my new [x, y] positions that would appear to be in 3d on the screen.
> This is just going to be for a demo that I need to do. Thanks.
>
>

http://pages.infinit.net/jstlouis/3dbhole/mathematics_of_3d_graphics.html#Transformations
has some sample transformation matrices which will do.

Take your 3d point, translate and rotate so the translated x and y axes
align to your screen x and y (eg: rot X 90, rot Y ~10, rot X ~10 for Z
up, X right and down a bit, translate by <[screen-width - mean
X]/2,[screen-height - mean Y]/2, [distance-to-eye + lowest-z]> will give
about what you describe) , then (optionally) divide by the transformed z
value for perspective, not plottin all points whose z-values are greater
than the distance from the eye to the screen.

Pete
pete kirkham, Jun 27, 2003