+2  A: 

The idea is to use a standard rotation matrix. In 2D this is:

--     --   --             -- --     --
| x_new |   | cos(a) -sin(a) | | x_old |
|       | = |               | |       |
| y_new |   | sin(a)  cos(a) | | y_old |
---    --   --             -- --     --

Where a is the angle by which you're rotating.

The idea is that you're translating each and every point to a new point using this transformatoin. To get a better picture of this, consider a unit circle (which I don't know how to draw with ASCII art), and ask yourself how you can move the point (0,1) to (sqrt(2)/2,sqrt(2)/2) (a 45 degree rotation).

x_new = x_old * cos(45) - y_old * sin(45) = 1 * sqrt(2)/2 - 0 * sqrt(2)/2 = sqrt(2)/2
y_new = x_old * sin(45) + y_old * cos(45) = 1 * sqrt(2)/2 + 0 * sqrt(2)/2 = sqrt(2)/2

Now translate this to (1,0), another 45 degree rotation:

x_new = x_old * cos(45) - y_old * sin(45) = sqrt(2)/2 * sqrt(2)/2 - sqrt(2)/2 * sqrt(2)/2 = 0
y_new = x_old * sin(45) + y_old * cos(45) = sqrt(2)/2 * sqrt(2)/2 + sqrt(2)/2 * sqrt(2)/2 = 1

Extending this to 3D is pretty straightforward, all you have to do is use another mutliplication for the rotation along the XZ plane.

Nathan Fellman
+7  A: 
Peter Parker
@Peter Parker, interesting. What do you think needs to be done to resolve the issue in the above script? Divide by z-coord like you suggested or?
Mithrax
you need to make a projection for each point. usually this is simply done by intercept theorem. You need an distant eyepoint(the distance between your eye and the screen). The formula is then: x'= x * (distant_eyepoint / distant_eyepoint+z) [same for y]
Peter Parker
+1 great answer
Justicle