Take the 2-minute tour ×

I'm trying to implement a simple ray-tracing algorithm so the first step is to convert pixel coordinates into uvw coordinates system iam using those two equations that i found in a book enter image description here

where l,r,b,t are the view frustum points , (i,j) are the pixel indexes , (nx,ny) are the scene width and height

then to calculate canonical coordinate i use

enter image description here

i want to understand the previous equations and why they give uwv coordinates for perspective projection not for orthogonal projection (when i use orthogonal projection the equation still gives the result as if perspective projection is used)

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Let's assume your camera is some sort of a pyramid. It has a bottom face which I'll refer to as the "camera screen", and the height of the pyramid, also known as the focal length, will be marked as F (or in your equations, Ws).

       |\       /|
       | \     / |
       |  \   /  |
       |   \ /   |
L(eft) |    *E(ye| R(ight)
       |   / \   |
       |  /   \  |
       | /     \ |
       |/       \|

Let's assume j goes from the bottom to the top (from -Ny/2 to +Ny/2 in steps of 1/Ny), and i goes from left to right (from -Nx/2 to +Nx/2 in steps of 1/Nx). Note that if Ny is even, j goes up to Nx/2-1 (and similar when Nx is even).

As you go from bottom to top in the image, on the screen, you move from the B value to the T value. At the fraction d (between 0=bottom and 1=top) of your way from bottom to top, your height is

Vs = T + (B-T) * d

A bit of messing around shows that the fraction d is actually:

d = (j + 0.5) / Ny


Vs = T + (B-T) * (j + 0.5) / Ny

And similarly:

Us = L + (R-L) * (i + 0.5) / Nx

Now, let's denote U as the vector going from left to right, V from bottom to top, 'W' going from the eye forward. All these vectors are normalized.

Now, assume the eye is located directly above (0,0) where that is exactly above the center of the rectangular face of the pyramid.

To go from the eye directly to (0,0) you would go:

Ws * W

And then to go from that point to another point on the screen at indexes (i,j) you would go:

Us * U + Vs * V

You will be able to see that Us = 0 for i = 0 and Vs = 0 for j = 0 (since B = -T and L = -R, as the eye is directly above the center of the rectangle).

And finally, if we compose it together, a point on the screen at indexes (i,j) is

S = E + Us * U + Vs * V + Ws * W


share|improve this answer
great illustration , thanks :) –  Ahmed Kotb Aug 18 '11 at 1:35
I fixed a flipped bottom and top in my explanation. The equations were right though. So if something didn't make sense somewhere, try re-reading. Glad to be helpful :) –  LightningIsMyName Aug 18 '11 at 19:54

Your Answer


