Friday, December 5, 2008

3D Graphics

This is a brief explanation of how to create basic 3D graphics. There are many different packages that will allow you to program using pre written 3D graphics library's, such as Java 3D but this is aimed at using and understanding the actual formula that can be used to draw the graphics yourself.

This assumes you are looking straight ahead from a single point and will map points in the 3D space in front of you onto a single plane at a fixed distance in front of you, probably 1 unit to keep it simple.

First of all consider the vertical direction, y axis. If we consider the right angled triangle formed by taking the line from you eye to the point, the line from your eye to beneath the point (ie the line where y =0) and the final verical equal to the y cordinate, we can use trigonometry to work out the height that need to be displayed.

From this we can work out the angle at your eye would be tan-1(y/(x2+z2))
This is because the length of the "opposite" is equal to the y co-ordinate and the adjacent can be found using pythagoras from the x and z co-ordinates.

We now can use the angle we have found to work out where the point needs to be displayed in our plane. Again we need to form a triangle similar to the first one but where the top corner is the final position of the point when it is projected. Ie the opposite is the y co-ordinate we need.
therefore,
y = tan(t)((x/z)2+1)
y=y((x/z)2+1)
(x2+z2)

No comments:

Post a Comment

Please comment if any information is incorrect, could be expanded or you have a question about it.