There are 2 common 3D clipping volumes
Each of these volumes are six-side; see illustration below.
The Cohen-Sutherland and Cyrus-Beck line-clipping algorithms can be extended for 3D. For 3D clipping, a 6-bit end point code is used. Bit#1 is the rightmost bit.
Canonical Parallel View Volume |
|
Bit |
Condition Test |
bit#1 |
point is above the view volume ( y > 1 ) |
bit#2 |
point is below the view volume ( y < -1 ) |
bit#3 |
point is right of the view volume ( x > 1 ) |
bit#4 |
point is left of the view volume ( x < -1 |
bit#5 |
point is behind the view volume ( z < -1 ) |
bit#6 |
point is in front of the view volume ( z > 0 ) |
Canonical Perspective View Volume |
|
Bit |
Condition Test |
bit#1 |
point is above the view volume ( y > -z ) |
bit#2 |
point is below the view volume ( y < z ) |
bit#3 |
point is right of the view volume ( x > -z ) |
bit#4 |
point is left of the view volume ( x < z ) |
bit#5 |
point is behind the view volume ( z < -1 ) |
bit#6 |
point is in front of the view volume ( z > z(min) ) |
Line ===> P0(x0, y0, z0) to P1(x1, y1, z1)
Note: t varies from 0 to 1
Let's consider the y = 1 plane ( Parallel )
2. --> 1 = y0 + t * (y1 - y0) or t = 1 - y0 / y1 - y0, if t is [0, 1] then substitute
for t in equations below
1. --> x = x0 + 1 - y0 / y1 - y0 * (x1 - x0)
3. --> z = z0 + 1 - y0 / y1 - y0 * ( z1 - z0)
Let's consider the y = z plane ( Perspective )
2. & 3. --> y0 + t * (y1 - y0) = z0 + t * (z1 - z0) or t = z0 - y0 / (y1 - y0) - (z1 - z0)
1. --------> x = x0 + (x1 - x0) * ( z0 - y0) / (y1 - y0) - (z1 - z0)
2. --------> y = y0 + ( y1 - y0) * ( z0 - y0) / (y1 - y0) - (z1 - z0)
3. --------> z = y
The reason for choosing this canonical view volume is to simplify the intersection computations.
Simplification and efficiency - Transform the perspective-projection canonical view volume into the parallel-projection
view volume and the sam clip procedure for both cases.
Clipping must be done in homogeneous coordinates to ensure correct results. This type of clipping is typically
implemented in hardware.
Homogenization can cause problems in 3D clipping if w < 0
Parallel Projection View Volume |
Inequalities in homogeneous coordinates |
Corresponding Plane equations |
-1 <= x <= 1 |
-1 <= X/W <= 1 |
-W <= X <= W |
-1 <= y <= 1 |
-1 <= Y/W <= 1 |
-W <= Y <= W |
-1 <= z <= 0 |
-1 <= Z/W <= 0 |
-W <= Z <= 0 |
Constraints
Solutions:
Cohen-Sutherland Clipping Example ---> Run Here , Source Code ---> Here