rayDirectionSolution

advertisement
QUESTION:
Suppose the viewpoint is at world coordinates (5, 2, 4).
Compute a unit length vector through the pixel at col 225 row 125.
SOLUTION:
First of all, you are missing the window dimensions and also the world dimensions!
So, let’s say the window dimensions are 600 X 400 (i.e. 601 X 401);
and the world dimensions are 8 X 6 (remember, these are doubles, so they are 8.0 X 6.0).
Now what???????????
Working backwards:
1.
2.
To compute the unit length vector, you need the length of the vector.
But, we don’t yet know the vector that we need the length of.
The vector that we need is the one from the viewpoint (V) through the pixel at column 225, row 125
so the first thing we need to do is to calculate the world_dimensions of that pixel:
world_x = world_size_x * (win_x / win_size_x-1)
world_x = 8.0 * (225 / 600) = 3.0
world_y = world_size_y * (win_y / win_size_y-1)
world_y = 6.0 * (125 / 400) = 1.88
world_z = 0.0
3.
So, now we have two points in (x,y,z) notation. The viewpoint (V) is (5.0, 2.0, 4.0). The pixel (P) represented in
world coordinates is (3.0, 1.88, 0.0)
To compute the vector from V to P, we subtract V from P:
D=P–V
D = (3.0, 1.88, 0.0) – (5.0, 2.0, 4.0)
D = (-2, -.12, -4)
That’s the vector that we want to compute the unit length of. Now we can do the calculations to answer the original
question at the top of the page.
4. The formula for determining the unit length of a vector requires the length of the vector.
So, the length of that vector is:
||D|| = sqrt (-22 + -.122 + -42)
||D|| = sqrt (20.0144)
||D|| = 4.47
5. Finally, the unit vector is:
U = (1/||D||) * D
U = (1/4.47) * (-2, -.12, -4)
U = (.2237 * -2, .2237 * -.12, .2237 * -4)
U = (-.45, -.03, -.89)
So - - that’s the answer to the question at the top of the page. Follow through these steps, see if they make sense, do the
math, and let me know if you get a different answer in case I made a typo.
Download