COMPUTER GRAPHICS-MODULE 3
Module 3
Window to viewport transformation. Cohen Sutherland Line clipping
algorithm. Sutherland Hodgeman Polygon clipping algorithm. Three
dimensional viewing pipeline. Projections- Parallel and Perspective
projections. Visible surface detection algorithms- Depth buffer
algorithm, Scan line algorithm
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
The Viewing Pipeline
Window: Area selected in world-coordinate for display is
called window. It defines what is to be viewed.
View port: Area on a display device in which window image is
displayed (mapped) is called view port. It defines where to
display.
In many case window and view port are rectangle, also other
shape may be used as window and view port.
In general finding device coordinates of view port from word
coordinates of window is called as viewing transformation.
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
Basic Steps
1 As shown in figure above first of all we construct world
coordinate scene using modeling coordinate transformation.
2 After this we convert to viewing coordinates from world
coordinates using window to viewport transformation.
3 Then we map viewing coordinate to normalized viewing
coordinate in which we obtain values in between 0 to 1.
4 At last we convert normalized viewing coordinate to device
coordinate using device driver software which provide device
specification.
5 Finally device coordinate is used to display image on display
screen.
6 By changing the viewport position on screen we can see image
at different place on the screen.
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
7 By changing the size of the window and viewport we can
obtain zoom in and zoom out effect as per requirement.
8 Fixed size viewport and small size window gives zoom in
effect, and fixed size viewport and larger window gives zoom
out effect.
9 View ports are generally defines with the unit square so that
graphics package are more device independent which we call
as normalized viewing coordinate.
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
Window-To-Viewport Coordinate Transformation
Mapping of window coordinate to viewport is called window
to viewport transformation.
We do this using transformation that maintains relative
position of window coordinate into viewport.
That means center coordinates in window must be remains at
center position in viewport.
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
Workstation Transformation
We can also map window to viewport with the set of
transformation, which include following sequence of
transformations:
1 Perform a scaling transformation using a fixed-point position
of (XWmin,YWmin) that scales the window area to the size of
the viewport.
2 Translate the scaled window area to the position of the
viewport.
For maintaining relative proportions we take (sx = sy). in
case if both are not equal then we get stretched or contracted
in either the x or y direction when displayed on the output
device.
Number of display device can be used in application and for
each we can use different window-to viewport transformation.
This mapping is called the workstation transformation.
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
As shown in figure two different display devices are used and we
map different window-to-viewport on each one.
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
Clipping Operations
Generally, any procedure that identifies those portions of a
picture that are either inside or outside of a specified region of
space is referred to as a clipping algorithm, or simply clipping.
The region against which an object is to clip is called a clip
window.
Applications of Clipping
It can be used for displaying particular part of the picture on
display screen.
Identifying visible surface in 3D views.
Creating objects using solid-modeling procedures.
Displaying multiple windows on same screen.
Drawing and painting.
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
TYPES OF CLIPPING
• Point clipping
• Line clipping(straight line segments)
• Area clipping(polygons)
• Curve clipping
• Text clipping
POINT CLIPPING
We save a point P=(X,Y) for display , if the following
inequalities are satisfied.
XWmin <= X <= XWmax
YWmin <= Y <= YWmax
where edges of clip window
(XWmin,XWmax,YWmin,YWmax)
8Clipped
Window
@
-
e
wymax
Clipped •P
5 •P
Points Within the Window
1
are Not Clipped
•pg
wymin
Clipped0
wxmin wxmax
Line Clipping
Line clipping involves several possible cases.
1 Completely inside the clipping window.
2 Completely outside the clipping window.
3 Partially inside and partially outside the clipping window.
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
3
of
30
Line Clipping
•For the image below consider which lines
and points should be kept and which ones
should be clipped
P4
Window P2
wymax
P6
P3
P1
P7 P5
P9
P8
wymin
P10
wxmin wxmax
Line which is completely inside is displayed completely. Line
which is completely outside is eliminated from display.
And for partially inside line we need to calculate intersection
with window boundary and find which part is inside the
clipping boundary and which part is eliminated.
For line clipping several scientists tried different methods to
solve this clipping procedure.
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
Cohen-Sutherland Line Clipping-Region and Region Code
In this we divide whole space into nine region and assign 4 bit code
to each endpoint of line depending on the position where the line
endpoint is located
Code is deriving by setting particular bit according to position of
area.(numbering the bit positions from right to left)
1 Set bit 1: For LEFT side of clipping window.
2 Set bit 2: For RIGHT side of clipping window. 3
Set bit 3: For BELOW clipping window.
4 Set bit 4: For TOP clipping window.
All bits as mention above are set means 1 and other are 0.
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
8
of
30
Cohen-Sutherland: World Division
World space is divided into regions based
on the window boundaries
– Each region has a unique four bit region code
– Region codes indicate the position of the
regions with respect to the window
1001 1000 1010
4 3 2 1
above below right left
0000
0001 0010
Window
Region Code
0101 0100 0110
4
of
30
Line Clipping
• A line clipping procedure involves several parts:
1. Test a given line segment to determine whether it lies
completely inside the clipping window.
2. Determine whether it lies completely outside the
window
3. If not 1 & 2, perform intersection calculations with
one or more clipping boundaries.
• A line with both endpoints inside all clipping boundaries
is saved
• A line with both endpoints outside any one of the clip
boundaries is discarded
• Other lines cross one or more clipping boundaries &
require calculation of multiple intersection points
7
of
30
Cohen-Sutherland Clipping Algorithm
•Oldest, most popular & efficient line clipping
algorithm
•It reduces the number of line intersections
that must be calculated by performing initial
tests & speeds up processing
•Every line endpoint in a picture is assigned
a 4-digit binary code called a region code
•Region code identifies the location of a point
relative to the boundaries of the clipping
rectangle
9
of
30
Cohen-Sutherland: Labelling
Every end-point is labelled with the
appropriate region code
P11 [1010]
P4 [1000]
Window
wymax
P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7 [0001]
P9 [0000] P8 [0010]
wymin
P10 [0100]
P13 [0101] P14 [0110]
wxmin wxmax
10
of
30
Cohen-Sutherland: Lines In The Window
1) Lines completely contained within the
window boundaries have region code [0000]
for both end-points so are not clipped
P11 [1010]
P4 [1000]
Window
wymax
P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7 [0001]
P9 [0000] P8 [0010]
wymin
P10 [0100]
P13 [0101] P14 [0110]
wxmin wxmax
11
of
Cohen-Sutherland: Lines Outside The
30 Window
2)Any lines with a common set bit in the region codes of
both end-points can be clipped –> lines completely outside
the window - AND operation with region codes (result –
not 0000)
P11 [1010]
P4 [1000]
Window
wymax
P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7 [0001]
P9 [0000] P8 [0010]
wymin
P10 [0100]
P13 [0101] P14 [0110]
wxmin wxmax
12
of
30
Cohen-Sutherland: Other Lines
3)Lines that cannot be identified as
completely inside or outside the window may
or may not cross the window interior
These lines are processed as follows:
– Compare an end-point outside the window to a
boundary (choose any order in which to consider
boundaries e.g. left, right, bottom, top) and determine
how much can be discarded
– If the remainder of the line is entirely inside or
outside the window, retain it or clip it respectively
13
of
30
Cohen-Sutherland: Other Lines (cont…)
– Otherwise, compare the remainder of the line
against the other window boundaries
– Continue until the line is either discarded or a
segment inside the window is found
Region codes - determine which window
boundaries should be considered for
intersection
– To check if a line crosses a particular
boundary we compare the appropriate bits in
the region codes of its end-points
– If one of these is a 1 and the other is a 0 then
the line crosses the boundary
15
of
30
Cohen-Sutherland Examples (cont…)
Consider the line P3 to P4 below
– Start at P4
– From the region codes P4’ [1001]
P4 [1000]
Window
of the two end-points wymax
we know the line P3 [0001]
crosses the left
boundary so calculate
the intersection point to wymin
generate P4’
– The line P3 to P4’ is
wxmin wxmax
completely outside the
window so is clipped
16
of
30
Cohen-Sutherland Examples (cont…)
Consider the line P7 to P8 below
– Start at P7
– From the two region Window
wymax
codes of the two
end-points we know
P7’ [0000]
the line crosses the P7 [0001] P8 [0010]
P8’ [0000]
left boundary so wymin
calculate the
intersection point to
generate P7’ wxmin wxmax
20
of Cohen Sutherland Line clipping algorithm
30
Algorithm :
[Link] two endpoints of the line P1( x1,y1) and P2(x2,y2)
[Link] two corners of the window (xwmin,ywmin and xwmax,
ywmax)
[Link] region codes for two endpoints as:
Initialize code with bits 0000
Set Bit 1 – if (x<xwmin)
Set Bit 2 – if (x>xwmax)
Set Bit 3 – if (y<ywmin)
Set Bit 4 – if (y>ywmax)
4. Check for visibility of line
a)If region codes for both endpoints are zero, then the
line is completely visible. Draw the line and go to step 6
21
of
30
Cohen Sutherland Line clipping algorithm
Algorithm ……contd :
b)If region codes for endpoints are not zero and the logical
AND of them is also nonzero, the line is completely
invisible, so reject the line and go to step 6
c)If region codes for two endpoints do not satisfy the
conditions in 4a) and 4b) the line is partially inside.
[Link] the following steps until the complete line is trivially
accepted or rejected
5 a) Start from an endpoint of the line that is outside the
window
5 b) Find the intersection point of the rectangular boundary
5 c) Replace endpoint with the intersection point and
update the region code and go to step 4 for checking
visibility of line
6. Stop
Intersection points calculation with clipping window
boundary
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
Cohen-Sutherland Line Clipping-Algorithm
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
Example
Clip a line A(-1,5) and B(3,8) using Cohen Sutherland algorithm
with window coordinates (-3,1) and (2,6)
COMPUTER GRAPHICS-MODULE 3Two dimensional transform
Polygon Clipping
For polygon clipping we need to modify the line clipping procedure
because in line clipping we need to consider about only line
segment while in polygon clipping we need to consider the area
and the new boundary of the polygon after clipping.
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
Sutherland-Hodgeman Polygon Clipping
For correctly clip a polygon we process the polygon boundary
as a whole against each window edge.
This is done by whole polygon vertices against each clip
rectangle boundary one by one.
Beginning with the initial set of polygon vertices we first clip
against the left boundary and produce new sequence of
vertices.
Then that new set of vertices is clipped against the right
boundary clipper, a bottom boundary clipper and a top
boundary clipper, as shown in figure below.
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
There are four possible cases when processing vertices in sequence
around the perimeter of a polygon.
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
Case 1: If moving from outside to inside, reject the starting
point & save the intersection point on window boundary and
second vertex
Case 2: If moving from inside to inside save the second vertex
only
Case 3: If moving from inside to outside, save the intersection
point and reject the endpoint
Case 4: If moving from outside to outside save none
When polygon clipping is done against one boundary then we
clip against next window boundary.
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
Example
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
As shown in figure above we clip against left boundary
vertices 1 and 2 are found to be on the outside of the
boundary. Then we move to vertex 3, which is inside, we
calculate the intersection and add both intersection point and
vertex 3 to output list.
Then we move to vertex 4 in which vertex 3 and 4 both are
inside so we add vertex 4 to output list, similarly from 4 to 5
we add 5 to output list, then from 5 to 6 we move inside to
outside so we add intersection pint to output list and finally 6
to 1 both vertex are outside the window so we does not add
anything.
Convex polygons are correctly clipped by the Sutherland-
Hodgeman algorithm but concave polygons may be displayed
with extraneous lines.
To overcome this problem we have one possible solution is to
divide polygon into numbers of small convex polygon and then
process one by one.
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
A polygon is said to be convex if all the interior
angles of the polygon are less than 180o. On the other
hand, a polygon is said to be concave if one or more
than one interior angles of the polygon is greater
than 180o.
Weiler-Atherton Polygon Clipping
In this algorithm vertex processing procedure for window
boundary is modified so that concave polygon also clip
correctly.
This can be applied for arbitrary polygon clipping regions as it
is developed for visible surface identification.
Main idea of this algorithm is instead of always proceeding
around the polygon edges as vertices are processed we
sometimes need to follow the window boundaries.
Other procedure is similar to Sutherland-Hodgeman algorithm.
For clockwise processing of polygon vertices we use the
following rules:
1 For an outside to inside pair of vertices, follow the polygon
boundary.
2 For an inside to outside pair of vertices, follow the window
boundary in a clockwise direction.
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
Example2
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
Three Dimensional object representation
Graphical scenes can contain many different kinds of objects
like trees, flowers, rocks, waters...etc.
No single method can be used to describe objects that will
include all features of those different materials.
To produce realistic display of scenes, we need to use
representations that accurately model object characteristics.
Simple Euclidean objects like polyhedrons and ellipsoids can
be represented by polygon and quadric surfaces
Representation schemes for solid objects are often divided into
two broad categories:
1 Boundary representations: describes a 3D object as a set of
polygonal surfaces, separate the object interior from
environment.
2 Space-partitioning representation: used to describe interior
properties, by partitioning the spatial region, containing an
object into a set of small, non-overlapping, contiguous solids.
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
Boundary Representation
Each 3D object is supposed to be formed its surface by
collection of polygon facets
Some of the boundary representation methods for 3D surface
are:
1 Polygon Surfaces
2 Quadric Surfaces
A polygonal surface can be thought of as a surface composed
of polygonal faces
The most commonly used boundary representation for a three
dimensional object is a set of polygon surfaces that enclose
the object interior
Here all surfaces can be described with linear equations
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
[Link] Tables
A polygon surface is specified with a set of vertex co-ordinates and
associated attribute parameters.
A convenient organization for storing geometric data is to create
lists
Representation of vertex coordinates, edges and other
property of polygon into table form is called polygon table.
Polygon data tables can be organized into two groups:
1 geometric table
2 attributes table.
Geometric table contains vertex coordinate and the other
parameter which specify geometry of polygon.
Attributes table stores other information like Color,
transparency etc.
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
Convenient way to represent geometric table into three
different tables namely
1 vertex table
2 edge table
3 polygon table
Vertex table stores each vertex included in the polygon.
Edge table stores each edge with the two endpoint vertex
pointers back to vertex table.
Polygon table stores each surface of polygon with edge
pointer for the each edge of the surface.
This three table representation stores each vertex one time
only and similarly each edge is also one time. So it will avoid
representation of storing common vertex and edge so it is
memory efficient method.
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
Another method to represent with two table vertex table and
polygon table but it is inefficient as it will store common edge
multiple times.
Since tables have many entries for large number of polygon
we need to check for consistency as it may be possible that
errors may occurs during input.
For dealing with that we add extra information into tables. For
example figure below shows edge table of above example with
information of the surface in which particular edge is present
Now if any surface entry in polygon table will find edge in edge
table it will verify whether this edge is of particular surface’s edge
or not if not it will detect errors and may be correct if sufficient
information is added. COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
Plane Equations-Polygon surfaces
For producing display of 3D objects we must process the input
data representation for the object through several procedures.
For this processing we sometimes need to find orientation and
it can be obtained by vertex coordinate values and the
equation of polygon plane.
Equation of plane is given as
Ax+By+Cz+D=0
Where (x, y, z) is any point on the plane and A, B, C, D are
constants by solving three plane equation for three non
collinear points.
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
Solve simultaneous equation for ratio A/D, B/D, and C/D as
follows:
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
If Ax+By+Cz+D 6= 0 point (x,y,z) is not on that plane.
If Ax+By+Cz+D < 0 the point (x,y,z) is inside the surface.
If Ax+By+Cz+D > 0 the point (x,y,z) is outside the surface.
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
[Link] Meshes
Polygon mesh is a collection of edges, vertices and faces that
defines the shape of the polyhedral object in 3D computer
graphics and solid modeling.
An edge connects two vertices and a polygon is a closed
sequence of edges.
An edge can be shared by two polygons and a vertex is shared
by at least two edges.
When object surface is to be tiled, it is more convenient to
specify the surface facets with a mesh function.
One type of polygon mesh is triangle strip. This function
produce n-2 connected triangles.
Another similar function is the quadrilateral mesh, which
generates a mesh of (n-1) by (m-1) quadrilaterals, given the
co-ordinates for an n m array of vertices.
If the surface of 3D object is planer, it is comfortable to
represent surface with meshes.
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
Quadric Surface
Quadric Surface is one of the frequently used 3D objects
surface representation.
The quadric surface can be represented by a second degree
polynomial. This includes
COMPUTER GRAPHICS-MODULE 4 Polygon Clipping & 3D rep
Projections
A 3D projection is a design technique used to display a
three-dimensional object on a two-dimensional surface.
Once world-coordinate descriptions of the objects in a scene
are converted to viewing coordinates, we can project the
three-dimensional objects onto the two-dimensional view plane
There are two projection methods namely.
1 Parallel Projection.
2 Perspective Projection.
COMPUTER GRAPHICS-MODULE 5 Projections
There are two types of oblique projections Cavalier and
Cabinet.
The Cavalier projection makes 45° angle with the projection
plane.
The Cabinet projection makes 63.4° angle with the projection
plane.
COMPUTER GRAPHICS-MODULE 5 Projections
Parallel Projections
In a parallel projection, coordinate positions are transformed
to the view plane along parallel lines
We can specify a parallel projection with a projection vector
that defines the direction for the projection lines.
It is further divide into two types
1 Orthographic parallel projection.
2 Oblique parallel projection
COMPUTER GRAPHICS-MODULE 5 Projections
Orthographic parallel projection
When the projection lines are perpendicular to the view plane,
we have an orthographic parallel projection.
Orthographic projections are most often used to produce the
front, side, and top views of an object
COMPUTER GRAPHICS-MODULE 5 Projections
Engineering and architectural drawings commonly use
orthographic projections, because lengths and angles are
accurately depicted and can be measure from the drawings.
We can also form orthographic projections that display more
than one face of an object.
Such views are called axonometric orthographic projections
COMPUTER GRAPHICS-MODULE 5 Projections
COMPUTER GRAPHICS-MODULE 5 Projections
Orthographic are projections onto one of the coordinate
planes x = 0, y = 0 or z = 0.
The standard transformation for parallel (orthographic)
projection onto the xy-plane (i.e. z=0 plane) is:
x’=x
y’=y
z’=0
In matrix form,
0
x 1 0 0 0 x
y 0 0 1 0 0 y
= ∗
z 0 0 0 0 0 z
1 0 0 0 1 1
COMPUTER GRAPHICS-MODULE 5 Projections
Oblique parallel projection
An oblique projection is obtained by projecting points along
parallel lines that are not perpendicular to the projection
plane.
COMPUTER GRAPHICS-MODULE 5 Projections
COMPUTER GRAPHICS-MODULE 5 Projections
As shown in the figure (X,Y,Z) is a point of which we are
taking oblique projection (X’,Y’) on the view plane and point
(X,Y) on view plane is orthographic projection of (X,Y,Z).
COMPUTER GRAPHICS-MODULE 5 Projections
Consider the point P(x,y,z) of an object. P is projected to P’ in the
view plane(XY plane). In XY plane, Z is 0 and therefore the new
point in the projected plane is (x’,y’,0). Take a point perpendicular
to the viewing plane and that point can be represented as (x,y,0)
since it is an orthographic projection. Let that distance be L and
making an angle α . Assume that for getting x , travel m distance
along x direction and n distance along y direction.
Then
x’=x+m
y’=y+n
Consider the angle φ and we can write the trigonometric equations
as
m/L = cosφ & n/L = sinφ
That is,
m = L ∗ cosφ & n = L ∗ sinφ
COMPUTER GRAPHICS-MODULE 5 Projections
Implies that
x’=x+L ∗ cosφ
y’= y+ L ∗ sinφ
Also, consider the distance L and tan α=z/L
L=z/tanα
Suppose 1/tanα=L1, Then
L=zL1
Thus we can write as
x’=x+zL1 ∗ cosφ
y’= y+ zL1 ∗ sinφ
In matrix form,
0
x 1 0 L1cosφ 0 x
y 0 0 1 L1sinφ 0 y
= ∗
z 0 0 0 0 0 z
1 0 0 0 1 1
COMPUTER GRAPHICS-MODULE 5 Projections
Perspective Projection
In perspective projection object positions are transformed to
the view plane along lines that converge to a point called the
projection reference point (or center of projection or vanishing
point).
COMPUTER GRAPHICS-MODULE 5 Projections
COMPUTER GRAPHICS-MODULE 5 Projections
COMPUTER GRAPHICS-MODULE 5 Projections
Triangle PAP’ and PBC are similar triangles
According to similarity rule,
PA P 0A
= = U(say ) (1)
PB CB
PA=Z-Z’ and PB=Z-Zprp
Similarly, P’A=(x’-x,y’-y) and CB=(Xprp − X , Yprp − Y )
Take X component only,Then
P’A=X’-X
CB = Xprp − X
Z − Z0
= U(say ) (2)
Z − Zprp
Z − Z 0 = U(Z − Zprp )
Z 0 = Z − U(Z − Zprp )
X − X0
= U(say ) (3)
X − Xprp
X − X 0 = U(X − Xprp )
COMPUTER GRAPHICS-MODULE 5 Projections
X 0 = X − U(X − Xprp )
Similarly, Y 0 = Y − U(Y − Yprp )
If U=0,
X’=X, Y’=Y & Z’=Z
If U=1,
X’=Xprp , Y 0 = Yprp &Z 0 = Zprp
Suppose that at view palne, Z’=Zvp
Then Equation(2) becomes
Zvp = Z − U(Z − Zprp )
Z − Zvp
U= (4)
Z − Zprp
COMPUTER GRAPHICS-MODULE 5 Projections
We an also assume that,at view plane, we can assume, X’=Xp and
Y’=Yp
Z − Zvp
Xp = X − ∗ (X − Xprp ) (5)
Z − Zprp
Z − Zvp Z − Zvp
Xp = X − X ∗ + Yprp ∗ (6)
Z − Zprp Z − Zprp
Z − Zvp Z − Zvp
Yp = Y − Y ∗ + Xprp ∗ (7)
Z − Zprp Z − Zprp
COMPUTER GRAPHICS-MODULE 5 Projections
Special Case:
Assume that, prp on Z view axis isXprp = Yprp =0
Then,
Z − Zvp
Xp = X − X ∗ (8)
Z − Zprp
Z − Zvp
Yp = Y − Y ∗ (9)
Z − Zprp
COMPUTER GRAPHICS-MODULE 5 Projections
Visible-Surface Detection Algorithms
Trying to identify, which of the polygon surfaces of the object
are visible.
It is broadly divided into two parts
1 Object-Space methods
2 Image-Space methods
Object space method compares objects and parts of objects to
each other within the scene definition to determine which
surface is visible.
In image space algorithm visibility is decided point by point at
each pixel position on the projection plane.
COMPUTER GRAPHICS-MODULE 5 Projections
Back-Face Detection
Back-Face Detection is simple and fast object –space method.
It identifies back faces of polygon based on the inside-outside
tests.
A point (x, y, z) is inside if Ax + By + Cz + D < 0 where A,
B, C, and D are constants and this equation is nothing but
equation of polygon surface.
We can simplify test by taking normal vector N= (A, B, C) of
polygon surface and vector V in viewing direction from eye as
shown in figure
COMPUTER GRAPHICS-MODULE 5 Projections
Then we check condition if V. N > 0 then polygon is back
face.
If we convert object description in projection coordinates and
our viewing direction is parallel toZv then V= (0,0,Vz ) and
V .N = Vz .C .
In right handed viewing system V is along negative Zv axis.
And in that case if C<0 the polygon is back face
In general for right handed system, if C ≤ 0 polygon is back
face.
In left handed system V is along the positive Z direction and
polygon is back face if C ≥ 0.
COMPUTER GRAPHICS-MODULE 5 Projections
Depth Buffer Method/ Z Buffer Method
Basic Steps
1 Initially each pixel of the z-buffer is set to the maximum depth
value (the depth of the back clipping plane).
2 The image buffer is set to the background color.
3 Surfaces are rendered one at a time.
4 For the first surface, the depth value of each pixel is
calculated.
5 If this depth value is smaller than the corresponding depth
value in the z-buffer (ie. it is closer to the view point), both
the depth value in the z-buffer and the color value in the
image buffer are replaced by the depth value and the color
value of this surface calculated at the pixel position.
6 Repeat step 4 and 5 for the remaining surfaces.
7 After all the surfaces have been processed, each pixel of the
image buffer represents the color of a visible surface at that
pixel.
COMPUTER GRAPHICS-MODULE 5 Projections
Depth Buffer Method/ Z Buffer Method(Algorithm)
Initialize the depth buffer and refresh buffer so that for all buffer
positions (x,y)
depth(x,y)=0 and refresh(x,y)= Ibackgnd
For each position on each polygon surface, compare depth
values to previously stored values in the depth buffer to
determine visibility.
Calculate the depth z for each (x, y) position on the polygon.
If z > depth(x, y), then set
depth(x,y)=z and (z values range from 0 at the back clipping
plane to zmax at the front clipping plane.)
refresh(x,y)= Isurf (x, y )
where Ibackgnd is the value for the background intensity, and
Isurf (x, y ) is the projected intensity value for the surface at
pixel position (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.
COMPUTER GRAPHICS-MODULE 5 Projections
It is image space approach.
It compares surface depth at each pixel position on the
projection plane.
It is also referred to as z-buffer method since generally depth
is measured in z-direction.
Each surface of the scene is process separately one point at a
time across the surface.
We are starting with pixel position of view plane and for
particular surface of object.
If we take orthographic projection of any point (x,y,z) of the
surface on the view plane we get two dimension coordinate
(x,y) for that point to display.
Here we are taking (x,y) position on plane and find particular
surface is at how much depth.
We can implement depth buffer algorithm in normalized
coordinates so that z values range from 0 at the back clipping
plane to zmax at the front clipping plane.
COMPUTER GRAPHICS-MODULE 5 Projections
COMPUTER GRAPHICS-MODULE 5 Projections
Zmax value can be 1 for unit cube or the largest value.
Here two buffers are required. A depth buffer to store depth
value of each (x,y) position and refresh buffer to store
corresponding intensity values.
Initially depth buffer value is 0 and refresh buffer value is
intensity of background.
Each surface of polygon is then process one by one scan line
at a time.
Calculate the z values at each (x,y) pixel position.
If calculated depth value is greater than the value stored in
depth buffer it is replaced with new calculated values and store
intensity of that point into refresh buffer at (x,y) position.
Depth values are calculated from plane equation
Ax+By+Cz+D= 0 as:
−Ax − By − D
z=
C
COMPUTER GRAPHICS-MODULE 5 Projections
From position (x,y) on a scan line, the next position across
the line has coordinates (x+1,y), and the position immediately
below on the next line has coordinates (x,y-1).
For horizontal line next pixel’s z values can be calculated by
putting x’=x+1 in above equation
−A(x + 1) − By − D
z0 =
C
A
z0 = z −
C
COMPUTER GRAPHICS-MODULE 5 Projections
Similarly for vertical line pixel below the current pixel has
y’=y-1 so it’s z values can be calculated as follows:
−Ax − B(y − 1) − D
z0 =
C
B
z0 = z +
C
If we are moving along polygon boundary then it will improve
performance by eliminating extra [Link] this if we
move top to bottom along polygon boundary we get
x 0 = x − 1/m and y’=y-1, so z value is obtain as follows:
1
−A(x − m) − B(y − 1) − D
z0 =
C
A/m + B
z0 = z +
C
COMPUTER GRAPHICS-MODULE 5 Projections
A Buffer Method
It is an extension of the depth-buffer method
The A buffer method represents an antialiased, area averaged,
accumulation-buffer
A drawback of the depth-buffer method is that it can only
find one visible surface at each pixel position.
The A-buffer method expands the depth buffer so that each
position in the buffer can reference a linked list of surfaces.
Thus, more than one surface intensity can be taken into
consideration at each pixel position, and object edges can be
antialiased.
Each position in the A-buffer has two fields:
1 depth field - stores a positive or negative real number
2 intensity field - stores surface-intensity information or a pointer
value.
COMPUTER GRAPHICS-MODULE 5 Projections
If the depth field is positive, the number stored at that
position is the depth of a single surface overlapping the
corresponding pixel area.
The intensity field then stores the RGB components of the
surface color at that point and the percent of pixel coverage
If the depth field is negative, this indicates multiple-surface
contributions to the pixel intensity.
The intensity field then stores a pointer to a linked list of
surface data.
COMPUTER GRAPHICS-MODULE 5 Projections
Data for each surface in the linked list includes:
1 RGB intensity components
2 opacity parameter (percent of transparency)
3 depth
4 percent of area coverage
5 surface identifier
6 pointer to next surface
COMPUTER GRAPHICS-MODULE 5 Projections
Scan Line Method
Image space method
It is an extension of the scan-line algorithm for polygon filling
Instead of filling just one surface, we now deal with multiple
surfaces.
In this method, as each scan line is processed, all polygon
surfaces intersecting that line are examined to determine
which are visible.
Across each scan line, depth calculations are made for each
overlapping surface to determine which is nearest to the view
plane. When the visible surface has been determined, the
intensity value for that position is entered into the image
buffer.
COMPUTER GRAPHICS-MODULE 5 Projections
COMPUTER GRAPHICS-MODULE 5 Projections
Here tables are set up for the various surfaces, which include
both an edge table and a polygon table.
The edge table contains coordinate endpoints for each line
in-the scene, the inverse slope of each line, and pointers into
the polygon table to identify the surfaces bounded by each
line.
The polygon table contains coefficients of the plane equation
for each surface, intensity information for the surfaces, and
possibly pointers into the edge table.
To facilitate the search for surfaces crossing a given scan line,
we can set up an active list of edges from information in the
edge table. This active list will contain only edges that cross
the current scan line, sorted in order of increasing x
COMPUTER GRAPHICS-MODULE 5 Projections
In addition, we define a flag for each surface that is set on or
off to indicate whether a position along a scan line is inside or
outside of the surface.
Scan lines are processed from left to right. At the leftmost
boundary of a surface, the surface flag is turned on; and at
the rightmost boundary, it is turned off.
Scan lines crossing the projection of two surfaces S1 and S2 in
the view plane. Dashed lines indicate the boundaries of hidden
surfaces
The active list for scan line 1 contains information from the
edge table for edges AB, BC, EH, and FG. For positions along
this scan line between edges AB and BC, only the flag for
surface S1 is on.
Therefore no depth calculations are necessary, and intensity
information for surface S1, is entered from the polygon table
into the refresh buffer.
COMPUTER GRAPHICS-MODULE 5 Projections
Similarly, between edges EH and FG, only the flag for surface
S2 is on. No other positions along scan line 1 intersect
surfaces, so the intensity values in the other areas are set to
the background intensity.
For scan lines 2 and 3 , the active edge list contains edges
AD, EH, BC, and FG.
Along scan line 2 from edge AD to edge EH, only the flag for
surface S1, is on.
But between edges EH and BC, the flags for both surfaces are
on.
COMPUTER GRAPHICS-MODULE 5 Projections