Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Four pt Code Algorithm

1) Find the 4P CODE for the two point P1 and P2

2) Check for Condition 1 and Condition 2


i. If Condition 1 is satisfied line is outside the window

ii. If Condition 2 is satisfied line is inside the window

iii. If Condition 1 and Condition 2 are not satisfied proceed to step 3

3) Find the intersection with the window


Cohen-Sutherland line-clipping
Lines that are completely contained within the window boundaries have a
region code of 0000 for both endpoints, are accept.
Lines that have a 1 in the same bit position in the region codes for each
endpoint are completely outside the clipping rectangle, are reject .
The logical and operation is used to assess for total clipping with both
region codes and if the result is not 0000, the line is completely outside the
clipping region.
Lines that cannot be identified as completely inside or completely outside a
clip window by these tests are checked for intersection with the window
boundaries.
Cohen-Sutherland line-clipping
Polygon Clipping
A polygon boundary processed with a line clipper may be displayed as
a series of unconnected line segments depending on the orientation of the
polygon to the clipping window.

Algorithm for polygon clipping, must generate one or more closed


areas that are then scan converted for the appropriate area fill.
Sutherland-Hodgeman Polygon Clipping
All polygon vertices is clipped against a clip rectangle boundary to
produce a new sequence of vertices and is passed to next boundary clipper.

At each step, a new sequence of output vertices is generated and passed to


the next window boundary clipper.
Sutherland-Hodgeman Polygon Clipping - Cases
Condition of First Condition of Second Components added to Output
Vertex wrt window Vertex wrt window vertex list
boundary boundary
Outside the window Inside the window Intersection point of the polygon
boundary boundary edge with the window boundary
and the second vertex
Inside the window Inside the window Only the second vertex
boundary boundary
Inside the window Outside the window Edge intersection with the
boundary boundary window boundary
Outside the window Outside the window Nothing is added
boundary boundary
Clipping polygon against Left boundary
Condition of First Condition of First Components added to
Vertex wrt Vertex wrt Output vertex list
window window
boundary boundary 2’
1’
1 2 Noting 3

2 3 1’ and 2’ 2

3 4 3’
1
3’
4 5 4’ 6
4

5 6 5’ 5
5’
6 1 Noting 4’

With the components in the output list the same process is repeated
for the next window boundary.
Hidden Line/Surface Removal
Removing hidden lines and surfaces greatly improves the visualization of the
objects.
The appearance of the object is greatly complicated by the appearance of all
the details.

Object space
methods
HL/SR Vector
Image space
methods
Raster
Hidden Line/Surface Removal algorithm classification

Object space
methods
HL/SR Vector
Image space
methods
Raster
Raster based Hidden-surface algorithms
Back-face removal
Z-buffer (depth buffer)
Depth-sort algorithm
Back-face removal
The back face is identified based on the viewing direction and the direction
of the normal vector of a point in a plane.

V
N

this polygon is a back face


Back-face removal
Projection coordinates of normal vector
N(Ai, Bj, Ck), where (i, j, k) unit vector
and our viewing direction is parallel to the viewing Axis V = (0, 0, Vz)

Yv
Xv
To label any polygon as a back face consider the sign of C,
the component of the normal vector N
Zv
V = (0, 0, Vz)
if C < 0 and C= 0

the face can be labelled as a back face


DEPTH-BUFFER METHOD/Z BUFFER METHOD
The basic idea is to test Z-depth of each surface to determine the closet
visible surface.

Y
S3
Z
S2
(x,y)
S1

To override the closer polygon from the far ones two arrays are used.
X
Refresh Buffer: to store the intensity value of each position
Depth Buffer: to store depth value for (x,y) position
z values range from 0 at the back clipping plane to Zmax at the front clipping
plane
Procedure
It is an image space approach (Implemented in screen co-ordinate system)

It compares surface depth

1. Initialize the depth buffer and refresh buffer so that for all buffer positions (x,
y), depth (x,y)=0, refresh (x,y)= I background
2. For each position on each polygon surface, compare depth values to previously
stored values in the depth buffer to determine visibility.
 Calculate the depth for each (x, y) position on the polygon.
 If z > depth(x, y), then set depth (x,y)=z, refresh (x,y)= I surface (x,y)

After all surfaces have been processed, the depth buffer contains depth
values for the visible surfaces and the refresh buffer contains the corresponding
intensity values for those surfaces.
Advantage and Dis-advantage

Advantage
• The algorithm is simple
• The amount of storage required is also minimal.

Disadvantage
• For anti-aliasing effect the algorithm writes the pixels to the frame buffer
in an arbitrary order, and the necessary information for pre-filtering is not
easily available.
• For transparency and translucency effects, pixels may be written to the
frame buffer in incorrect order, leading to local errors.
Depth-Sort Algorithm
The depth-sort algorithms locates the polygons into the frame buffer in
the order of decreasing distance (depth) from the view point.,

It uses both image-space and object space operations

Steps Involved
• Sort all the polygons according to the smallest z-coordinate of each.
• Resolve any ambiguities when the z-coordinates of polygons overlap, by
splitting the polygons.
• Scan and convert each polygon in ascending order from back to front (in
terms of z-coordinate).

The painter’s algorithm

You might also like