Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-pcd!hpcvlx!bill
From: bill@hpcvlx.cv.hp.com (Bill Frolik)
Newsgroups: comp.graphics
Subject: Re: 3-d -----> 2-d
Message-ID: <101880012@hpcvlx.cv.hp.com>
Date: 2 Oct 89 19:10:45 GMT
References: <1133@utkcs2.cs.utk.edu>
Organization: Hewlett-Packard Co., Corvallis, OR, USA
Lines: 47


| 	Does anyone know of an algorithm for translating 3-d to 2-d so
| that I can plot on my IBM-PC?  I wish to display all axises at a

The easiest way to map [x,y,z] into [x',y'] without perspective:

			x' = x
			y' = y

The easiest way to map [x,y,z] into [x',y'] with perspective:

			x' = (x*d)/(z+d)
			y' = (y*d)/(z+d)

		where d, a constant, the distance from the
		viewer's eye to the screen, determines the
		amount of perspective.

For derivation of these equations you examine a couple of triangles.
The screen glass is at z=0, with increasing z going deeper into the
screen; the center of the screen is at x=y=0; the viewer is distance d
from the screen.  In the diagram, the ratio of the lengths of side VA
to VB will be the same as side Ap1 to Bp2.

	len(VA)   len(Ap1)           d     x'
	------- = --------    ==    --- = ---   (and similar for y')
	len(VB)   len(Bp2)          d+z    x

			     	B---------*p2
			     	|        /(x,y,z)
				|       /
		    ------------A------*p1---  <--screen (z=0)
			     |	|     /(x',y')
			     |	|    /
			     d	|   /
			     |	|  /
			     |	| /
			     |	|/
			        V  <-- viewer

A good value for d might be to set it equal to the width of the screen.
(If your screen is 1024 units wide, i.e. screen X runs from something
like -512..+511, set d=1024.)  
________________________________________

Bill Frolik	Hewlett-Packard Co.
hp-pcd!bill	Corvallis, Oregon