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