Download Cubes and Parallelepipeds

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
Transcript
CS 446 Notes VIII! Ray Tracing – Cubes & Parallelepipeds !
Cubes & Parallelepipeds
corner + edge 2
edge 2
corner + edge 3
corner edge
3
edge 1
(0, 1, 0)
y
corner + edge 1
z
(0, 0, 0)
(0, 0, 1)
x
(1, 0, 0)
The illustration shows the unit cube and a solid with parallelogram sides, a parallelepiped.
The parallelepiped is described by the matrix:
⎡ edge1x
⎢ edge1
y
BOX = ⎢
⎢ edge1z
⎢
⎣ 0
edge2 x
edge2 y
edge2 z
0
edge3x
edge3y
edge3z
0
cornerx ⎤
cornery ⎥
⎥
cornerz ⎥
⎥
1 ⎦
This matrix can be used to relate points in the unit cube and points in the parallelepiped.
The formula:
point in parallelepiped = BOX · point in unit cube
which expands to:
⎡ point in parallelepiped x ⎤
⎢ point in parallelepiped ⎥
y⎥
⎢
=
⎢ point in parallelepipedz ⎥
⎢
⎥
1
⎣
⎦
⎡ edge1x edge2 x edge3x cornerx ⎤ ⎡ point in unit cubex ⎤
⎢ edge1 edge2 edge3 corner ⎥ ⎢ point in unit cube ⎥
y
y
y
y⎥ ⎢
y⎥
⎢
×
⎢ edge1z edge2 z edge3z cornerz ⎥ ⎢ point in unit cubez ⎥
⎢
⎥ ⎢
⎥
0
0
1 ⎦ ⎣
1
⎣ 0
⎦
obtains points in the parallelepiped from points in the unit cube.
Points in the unit cube are obtained from points in the parallelepiped by:
point in unit cube = BOX–1 · point in parallelepiped
page 2
! !CS 446 Notes VIII
Ray Tracing – Cubes & Parallelepipeds
"
Clipping a Quadratic Surface with a Parallelepiped
1." Choose a parallelepiped and describe it with a BOX matrix.
2." Obtain the inverse of the BOX matrix.
3." When a candidate value for t is obtained, compute the point on the surface and then
compute the point BOX–1 · point on surface.
4." If the computed point is inside the unit cube, the point on the surface is inside the
parallelepiped, otherwise it is not.
A box matrix can be transformed by the techniques used to transform points in assignment 2.
Such transforms can be used to keep a box correlated with a transformed surface.
For example, to transform a box matrix so that the box it describes is rotated by 45°
around the z-axis, use the computation:
BOX = zRotate45° · BOX
Finding a Point on a Parallelepiped
It is relatively complex to directly find a point on the parallelepiped. It is much easier to
solve a corresponding problem using the standard unit cube.
eye
direction
corner + edge 2
edge 2
(0, 1, 0)
y
corner + edge 3
corner edge 3
edge 1
corner + edge 1
z
standardDirection
(0, 0, 0)
(0, 0, 1)
x
(1, 0, 0)
standardEye
Multiplying the vectors eye and grid ( = direction – eye) by the matrix BOX–1 gives the vectors standardEye and standardGrid whose relation to the unit cube is the same as the relation of the eye and grid vectors with the parallelepiped.
To compute standardDirection, use standardDirection = standardGrid – standardEye.
The vectors standardEye and standardDirection can then be compared with the unit cube to
find t. This is the same t that the would be found using the original eye, grid and BOX.
!
!
!
page 3
CS 446 Notes VIII Ray Tracing – Cubes & Parallelepipeds
Finding the Point on the Unit Cube
To find the t value of the vector from the eye to the front face of the cube:
1." Check that the eye is pointed toward the xy-plane (which contains the front face)
2." Find the point where the line of sight crosses the xy-plane.
3." Check to see if the crossing point is within the unit square.
if
!
!
!
!
!
!
!
(dirz > 0)
{
t = -eyez / dirz;
double x = eyex + t * dirx;
double y = eyey + t * diry;
if (0 <= x && x <= 1 && 0 <= y && y <= 1)
! ...This t is good for the front face...
}
To find the t value of the vector from the eye to the back face of the cube:
1." Check that the eye is pointed toward the plane ‘z=1’
2." Find the point where the line of sight crosses the plane ‘z=1’.
3." Check to see if the crossing point is within the unit square.
if
!
!
!
!
!
!
!
(dirz < 0)
{
t = (1 - eyez) / dirz;
double x = eyex + t * dirx;
double y = eyey + t * diry;
if (0 <= x && x <= 1 && 0 <= y && y <= 1)
! ...This t is good for the back face...
}
The other four faces are checked by using x (or y) in place of z.
Finding the Point on the Parallelepiped
Do this the same way you did for a quadratic surface. The point vector is the eye vector
plus t times the direction vector.
Finding a Normal Vector
If the point is on the front or back face, the cross product of the x and y vectors in the
BOX matrix will be normal to the correct side of the parallelepiped.
If the point is on the top or bottom face, the cross product of the x and z vectors in the
"
BOX matrix will be normal to the correct side of the parallelepiped.
If the point is on the left or right face, the cross product of the y and z vectors in the
" BOX matrix will be normal to the correct side of the parallelepiped.