[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

1067.0. "3D transformation into 2D?" by KNOWAY::WOLFF (Conformism is for little minds.) Sat Apr 22 1989 17:18

        I am trying to find a function F(x,y,z) which transforms
a 3D picture in a 2D picture. In other words:

	    3	  2
        F: R  -> R  : (x,y,z) |-> (x',y')

For example this picture, top view

	    Z
           ^
           |
        +--+--+
        |  |  |
 -------+--+--+-------> X
        |  |  |
        +--+--+
           |

which is a rectangular area sitting one unit of measurement above the
Y axis, with the coordinates:

        X   Y   Z
	1   1   1
        1   1  -1
       -1   1   1
       -1   1  -1

What I want to do is transform this picture to a 2D picture which preserves
the 3D effect, so that the transformation function would yield something
like this:

          ^ Y
          |
       +--+--+
      /   | /
     +----++
          |
----------+-----------> X
          |
          |

I have already experimented with all kinds of rotations and trasnformations
but none of them had any satisfying results. Any help would be appreciated.

        Julian.
    
T.RTitleUserPersonal
Name
DateLines
1067.1try thisCTCADM::ROTHIf you plant ice you'll harvest windSun Apr 23 1989 12:2948
   You could just do a parallel projection along the Z axis after doing a
   shear transformation in the XZ plane followed by a shear in the YZ plane.

   For the XZ plane use

	x' = x-a*z		(a = amount of shear to apply; 0.2 or so.)
	y' = y
	z' = z

   For the YZ plane use

	x' = x
	y' = y-b*z		(b = amount of shear to apply, as above)
	z' = z

    Apply these linear transformations in succession and then plot
    your object by showing the XY coordinates, ignoring the Z axis.

    These transformations can be written as homogenous matrices, and
    combined by normal matrix multiplication, for example

	|x'|   | 1  0  0  0 | | 1  0 -a  0 | |x|
	|y'| = | 0  1 -b  0 |*| 0  1  0  0 |*|y|
	|z'|   | 0  0  1  0 | | 0  0  1  0 | |z|
	|w'|   | 0  0  0  1 | | 0  0  0  1 | |1|

    This assumes you have a right handed system with the Z axis pointing to
    the viewer, as in your picture below:

                  ^ Y
                  |
               +--+--+
              /   | /
             +----++
                  |
        ----------+-----------> X
	          |
                  |

    The transformations could have been combined of course, but writing
    them separately is more flexible - you can combine any combination
    of rotations, translations, etc, in perspective or parallel, with whatever
    number of vanishing points are desired.

    Look at Newman and Sproull for a clear explanation of this.  (N&S is
    better than Foley and VanDam in my opinion.)

    - Jim
1067.2did I miss something?PULSAR::WALLYWally Neilsen-SteinhardtWed Apr 26 1989 18:3817
    Sounds to me like what you want is the standard projective mapping
    functions, which are used for this all the time.  I don't remember
    the details, although I programmed them once in Fortran for a GT40.
    
    What I remember is that you represent the XYZ as a vector, and then
    multiply it by matrices to represent translations, rotations and
    projections.  The last step is the simplest, you just ignore the
    z coords and use the xy as the 2 dim coords.
    
    Or you use the z coords to do hidden line stuff, which is what I
    was doing.
    
    I also vaguely remember that there is a fourth coord, which starts
    off always 1, and gets changed in the projections somehow.
    
    I have not got a reference now, but I got this out of some standard
    text on computer graphics.
1067.3Look there!NIZIAK::YARBROUGHI PREFER PIThu Apr 27 1989 15:457
>    I also vaguely remember that there is a fourth coord, which starts
>    off always 1, and gets changed in the projections somehow.

The 4th coordinate is introduced to make the equations homogeneous and 
dimensionless; this allows you to move your viewing point anywhere without
the transformation matrices suddenly becoming singular. The '1' changes 
with the scale of the coordinate system, e.g. when you zoom in or out.
1067.4KNOWAY::WOLFFConformism is for little minds.Fri Apr 28 1989 22:434
    Thanks a lot, I'll try that.
    
    	Julian.
    
1067.5Similar Triangles ?ESASE::HEGARTYMon May 01 1989 14:381
    
1067.6The text of .5ESASE::HEGARTYMon May 01 1989 14:4978
    Sorry this was ment to be included in .5.
    
If I understand the question properly, I would think that for a simple answer 
some geometry and similar triangles might give the required result.

Excuse to bad drawing, (3D on an 80x24 character screen is not easy...)


		     Y-axis
			|    
			|  
			|  
			|  /  .(x,y,z)
			| /
			|/    .(x,0,z)
	----------------+--------------X-axis
		       /
		      /
	             /
                    �(0,0,�)

Consider a the triangle 	(0,0,�);(x,0,z);(0,0,z)
this is 'similar' to the triangle 
				(0,0,�);(x',0,0);(0,0,0)

			where x' is the intersection point of the X-axis and
						a line from (0,0,�) to (x,0,z).
From this we can say,

	SQR(x'�+߲)    SQR(x�+(�-z)�)
	-----------  = --------------
	     �        	    |�-z|   
			      ^
			      |
			      +---- Distance from � to z.
	  �x
=> x' = -------  
        |� - z|


Similarly,

	  �y
   y' = -------
	|� - z|


Thus the projection of (x,y,z) onto the z=0 plane for the above is given by,

	   (	�x          �y   )
	   (--------- ' ---------)
           ( |� - z|     |� - z| )


To use this approach it is assumed that the view point for the 2D projection is 
on the Z axis in front of the plane of projection.

Does this make sense ?


For the square given in .1, a view from the Z axis will give,

			      ^Y
			      |
			+-----|-----+
			\     |     /
			 \    |    /      (Looking up at a floating square)
			  +---|---+
			      |
		--------------+---------->X
			      |


Moving the vantage point to one side (or moving the square, say ynew=y-2) gives
the 2D view desired in .1.


Paul.