Computer Graphics Unit-4
Computer Graphics Unit-4
3D Translation
Consider a point object O has to be moved from one position to another in a 3D plane.
Let-
This translation is achieved by adding the translation coordinates to the old coordinates of the
object as-
Problem-
Given a 3D object with coordinate points A(0, 3, 1), B(3, 3, 2), C(3, 0, 0), D(0, 0, 0). Apply the
translation with the distance 1 towards X axis, 1 towards Y axis and 2 towards Z axis and obtain
the new coordinates of the object.
Solution-
Given-
·
Old coordinates of the object = A (0, 3, 1), B(3, 3, 2), C(3, 0, 0), D(0, 0, 0)
· Translation vector = (Tx, Ty, Tz) = (1, 1, 2)
· Xnew = Xold + Tx = 0 + 1 = 1
· Ynew = Yold + Ty = 3 + 1 = 4
· Znew = Zold + Tz = 1 + 2 = 3
· Xnew = Xold + Tx = 3 + 1 = 4
· Ynew = Yold + Ty = 3 + 1 = 4
· Znew = Zold + Tz = 2 + 2 = 4
· Xnew = Xold + Tx = 3 + 1 = 4
· Ynew = Yold + Ty = 0 + 1 = 1
· Znew = Zold + Tz = 0 + 2 = 2
· Xnew = Xold + Tx = 0 + 1 = 1
· Ynew = Yold + Ty = 0 + 1 = 1
· Znew = Zold + Tz = 0 + 2 = 2
Thus, New coordinates of the object = A (1, 4, 3), B(4, 4, 4), C(4, 1, 2), D(1, 1, 2).
3D Rotation
3D Rotation is a process of rotating an object with respect to an angle in a three
dimensional plane.
Consider a point object O has to be rotated from one angle to another in a 3D plane.
Let-
● Rotation angle = θ
● X-axis Rotation
● Y-axis Rotation
● Z-axis Rotation
● Xnew = Xold
● Ynew = Yold
● Znew = Zold
Problem-01:
Given a homogeneous point (1, 2, 3). Apply rotation 90 degree towards X, Y and Z axis and
find out the new coordinate points.
Solution-
Given-
● Xnew = Xold = 1
● Ynew = Yold = 2
● Znew = Zold = 3
3D Scaling
Let-
● Xnew = Xold x Sx
● Ynew = Yold x Sy
● Znew = Zold x Sz
Problem-01:
Given a 3D object with coordinate points A(0, 3, 3), B(3, 3, 6), C(3, 0, 1), D(0, 0, 0). Apply
the scaling parameter 2 towards X axis, 3 towards Y axis and 3 towards Z axis and obtain
the new coordinates of the object.
Solution-
Given-
● Old coordinates of the object = A (0, 3, 3), B(3, 3, 6), C(3, 0, 1), D(0, 0, 0)
● Xnew = Xold x Sx = 0 x 2 = 0
● Ynew = Yold x Sy = 3 x 3 = 9
● Znew = Zold x Sz = 3 x 3 = 9
● Xnew = Xold x Sx = 3 x 2 = 6
● Ynew = Yold x Sy = 3 x 3 = 9
● Znew = Zold x Sz = 6 x 3 = 18
● Xnew = Xold x Sx = 3 x 2 = 6
● Ynew = Yold x Sy = 0 x 3 = 0
● Znew = Zold x Sz = 1 x 3 = 3
● Xnew = Xold x Sx = 0 x 2 = 0
● Ynew = Yold x Sy = 0 x 3 = 0
● Znew = Zold x Sz = 0 x 3 = 0
There are two approaches for removing hidden surface problems − Object-Space
method and Image-space method. The Object-space method is implemented in physical
coordinate system and image-space method is implemented in screen coordinate system.
In this method each surface is processed separately one pixel position at a time across the
surface. The depth values for a pixel are compared and the closest smallest surface
determines the color to be displayed in the frame buffer.
It is applied very efficiently on surfaces of polygon. Surfaces can be processed in any order.
To override the closer polygons from the far ones, two buffers named frame
buffer and depth buffer, are used.
Depth buffer is used to store depth values for x,yx,y position, as surfaces are
processed 0≤depth≤10≤depth≤1.
The frame buffer is used to store the intensity value of color value at each position x,yx,y.
The z-coordinates are usually normalized to the range [0, 1]. The 0 value for z-coordinate
indicates back clipping pane and 1 value for z-coordinates indicates front clipping pane.
Algorithm:
Depthbuffer x,yx,y = 0
Advantages
● It is easy to implement.
Scan-Line Method
It is an image-space method to identify visible surface. This method has a depth
information for only single scan-line. In order to require one scan-line of depth values, we
must group and process all polygons intersecting a given scan-line at the same time before
processing the next scan-line. Two important tables, edge table and polygon table, are
maintained for this.
The Edge Table − It contains coordinate endpoints of each line in the scene, the inverse
slope of each line, and pointers into the polygon table to connect edges to surfaces.
The Polygon Table − It contains the plane coefficients, surface material properties, other
surface data, and may be pointers to the edge table.
To facilitate the search for surfaces crossing a given scan-line, an active list of edges is
formed. The active list stores only those edges that cross the scan-line in order of increasing
x. Also a flag is set for each surface to indicate whether a position along a scan-line is either
inside or outside the surface.
● Pixel positions across each scan-line are processed from left to right. At the left
intersection with a surface, the surface flag is turned on and at the right, the flag is
turned off. You only need to perform depth calculations when multiple surfaces have
their flags turned on at a certain scan-line position.
Area-Subdivision Method
The area-subdivision method takes advantage by locating those view areas that represent
part of a single surface. Divide the total viewing area into smaller and smaller rectangles
until each small area is the projection of part of a single visible surface or no surface at all.
Continue this process until the subdivisions are easily analyzed as belonging to a single
surface or until they are reduced to the size of a single pixel. An easy way to do this is to
successively divide the area into four equal parts at each step. There are four possible
relationships that a surface can have with a specified area boundary.
● Overlapping surface − One that is partly inside and partly outside the area.
The tests for determining surface visibility within an area can be stated in terms of these
four classifications. No further subdivisions of a specified area are needed if one of the
following conditions is true −
● A surrounding surface obscures all other surfaces within the area boundaries.
Back-Face Detection
A fast and simple object-space method for identifying the back faces of a polyhedron is
based on the "inside-outside" tests. A point x,y,zx,y,z is "inside" a polygon surface with plane
parameters A, B, C, and D if When an inside point is along the line of sight to the surface, the
polygon must be a back
face weareinsidethatfaceandcannotseethefrontofitfromourviewingpositionweareinsidethat
faceandcannotseethefrontofitfromourviewingposition.
We can simplify this test by considering the normal vector N to a polygon surface, which
has Cartesian components A,B,CA,B,C.
V.N > 0
So that we only need to consider the sign of C the component of the normal vector N.
In a right-handed viewing system with viewing direction along the negative ZVZV axis, the
polygon is a back face if C < 0. Also, we cannot see any face whose normal has z component
C = 0, since your viewing direction is towards that polygon. Thus, in general, we can label
any polygon as a back face if its normal vector has a z component value −
C <= 0
Similar methods can be used in packages that employ a left-handed viewing system. In
these packages, plane parameters A, B, C and D can be calculated from polygon vertex
coordinates specified in a clockwise
direction unlikethecounterclockwisedirectionusedinaright−handedsystemunlikethecounter
clockwisedirectionusedinaright−handedsystem.
Also, back faces have normal vectors that point away from the viewing position and are
identified by C >= 0 when the viewing direction is along the positive ZvZv axis. By
examining parameter C for the different planes defining an object, we can immediately
identify all the back faces.