0% found this document useful (0 votes)
21 views

Computer Graphics Unit-4

Uploaded by

tanishaanmol5519
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Computer Graphics Unit-4

Uploaded by

tanishaanmol5519
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

RENAISSANCE UNIVERSITY, INDORE

School of Computer Science


BCA/BSC V Sem

Subject: Computer Graphics


Unit 4

3D Transformations in Computer Graphics


Transformation is a process of modifying and re-positioning the existing graphics.

3D Transformations take place in a three dimensional plane.

3D Translation

3D Translation is a process of moving an object from one position to another in a three


dimensional plane.

Consider a point object O has to be moved from one position to another in a 3D plane.

Let-

· Initial coordinates of the object O = (Xold, Yold, Zold)


· New coordinates of the object O after translation = (Xnew, Ynew, Zold)
· Translation vector or Shift vector = (Tx, Ty, Tz)

Given a Translation vector (Tx, Ty, Tz)-

· Tx defines the distance the Xold coordinate has to be moved.


· Ty defines the distance the Yold coordinate has to be moved.
· Tz defines the distance the Zold coordinate has to be moved.

This translation is achieved by adding the translation coordinates to the old coordinates of the
object as-

· Xnew = Xold + Tx (This denotes translation towards X axis)


· Ynew = Yold + Ty (This denotes translation towards Y axis)
· Znew = Zold + Tz (This denotes translation towards Z axis)
In Matrix form, the above translation equations may be represented as-

PRACTICE PROBLEM BASED ON 3D TRANSLATION

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)

For Coordinates A(0, 3, 1)

Let the new coordinates of A = (Xnew, Ynew, Znew).

Applying the translation equations, we have-

· Xnew = Xold + Tx = 0 + 1 = 1
· Ynew = Yold + Ty = 3 + 1 = 4
· Znew = Zold + Tz = 1 + 2 = 3

Thus, New coordinates of A = (1, 4, 3).

For Coordinates B(3, 3, 2)

Let the new coordinates of B = (Xnew, Ynew, Znew).

Applying the translation equations, we have-

· Xnew = Xold + Tx = 3 + 1 = 4
· Ynew = Yold + Ty = 3 + 1 = 4
· Znew = Zold + Tz = 2 + 2 = 4

Thus, New coordinates of B = (4, 4, 4).

For Coordinates C(3, 0, 0)

Let the new coordinates of C = (Xnew, Ynew, Znew).


Applying the translation equations, we have-

· Xnew = Xold + Tx = 3 + 1 = 4
· Ynew = Yold + Ty = 0 + 1 = 1
· Znew = Zold + Tz = 0 + 2 = 2

Thus, New coordinates of C = (4, 1, 2).

For Coordinates D(0, 0, 0)

Let the new coordinates of D = (Xnew, Ynew, Znew).

Applying the translation equations, we have-

· Xnew = Xold + Tx = 0 + 1 = 1
· Ynew = Yold + Ty = 0 + 1 = 1
· Znew = Zold + Tz = 0 + 2 = 2

Thus, New coordinates of D = (1, 1, 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-

● Initial coordinates of the object O = (Xold, Yold, Zold)

● Initial angle of the object O with respect to origin = Φ

● Rotation angle = θ

● New coordinates of the object O after rotation = (Xnew, Ynew, Znew)


In 3 dimensions, there are 3 possible types of rotation-

● X-axis Rotation

● Y-axis Rotation

● Z-axis Rotation

For X-Axis Rotation-

This rotation is achieved by using the following rotation equations-

● Xnew = Xold

● Ynew = Yold x cosθ – Zold x sinθ

● Znew = Yold x sinθ + Zold x cosθ

In Matrix form, the above rotation equations may be represented as-

For Y-Axis Rotation-

This rotation is achieved by using the following rotation equations-

● Xnew = Zold x sinθ + Xold x cosθ

● Ynew = Yold

● Znew = Yold x cosθ – Xold x sinθ

In Matrix form, the above rotation equations may be represented as-


For Z-Axis Rotation-

This rotation is achieved by using the following rotation equations-

● Xnew = Xold x cosθ – Yold x sinθ

● Ynew = Xold x sinθ + Yold x cosθ

● Znew = Zold

In Matrix form, the above rotation equations may be represented as-

PRACTICE PROBLEMS BASED ON 3D ROTATION

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-

● Old coordinates = (Xold, Yold, Zold) = (1, 2, 3)

● Rotation angle = θ = 90º

For X-Axis Rotation-

Let the new coordinates after rotation = (Xnew, Ynew, Znew).

Applying the rotation equations, we have-

● Xnew = Xold = 1

● Ynew = Yold x cosθ – Zold x sinθ = 2 x cos90° – 3 x sin90° = 2 x 0 – 3 x 1 = -3

● Znew = Yold x sinθ + Zold x cosθ = 2 x sin90° + 3 x cos90° = 2 x 1 + 3 x 0 = 2

Thus, New coordinates after rotation = (1, -3, 2).

For Y-Axis Rotation-

Let the new coordinates after rotation = (Xnew, Ynew, Znew).

Applying the rotation equations, we have-

● Xnew = Zold x sinθ + Xold x cosθ = 3 x sin90° + 1 x cos90° = 3 x 1 + 1 x 0 = 3

● Ynew = Yold = 2

● Znew = Yold x cosθ – Xold x sinθ = 2 x cos90° – 1 x sin90° = 2 x 0 – 1 x 1 = -1

Thus, New coordinates after rotation = (3, 2, -1).

For Z-Axis Rotation-

Let the new coordinates after rotation = (Xnew, Ynew, Znew).

Applying the rotation equations, we have-

● Xnew = Xold x cosθ – Yold x sinθ = 1 x cos90° – 2 x sin90° = 1 x 0 – 2 x 1 = -2

● Ynew = Xold x sinθ + Yold x cosθ = 1 x sin90° + 2 x cos90° = 1 x 1 + 2 x 0 = 1

● Znew = Zold = 3
3D Scaling

In computer graphics, scaling is a process of modifying or altering the size of objects.

● Scaling may be used to increase or reduce the size of object.

● Scaling subjects the coordinate points of the original object to change.

● Scaling factor determines whether the object size is to be increased or reduced.

● If scaling factor > 1, then the object size is increased.

● If scaling factor < 1, then the object size is reduced.

Consider a point object O has to be scaled in a 3D plane.

Let-

● Initial coordinates of the object O = (Xold, Yold,Zold)

● Scaling factor for X-axis = Sx

● Scaling factor for Y-axis = Sy

● Scaling factor for Z-axis = Sz


● New coordinates of the object O after scaling = (Xnew, Ynew, Znew)

This scaling is achieved by using the following scaling equations-

● Xnew = Xold x Sx

● Ynew = Yold x Sy

● Znew = Zold x Sz

In Matrix form, the above scaling equations may be represented as-

PRACTICE PROBLEMS BASED ON 3D SCALING

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)

● Scaling factor along X axis = 2

● Scaling factor along Y axis = 3

● Scaling factor along Z axis = 3


For Coordinates A(0, 3, 3)

Let the new coordinates of A after scaling = (Xnew, Ynew, Znew).

Applying the scaling equations, we have-

● Xnew = Xold x Sx = 0 x 2 = 0

● Ynew = Yold x Sy = 3 x 3 = 9

● Znew = Zold x Sz = 3 x 3 = 9

Thus, New coordinates of corner A after scaling = (0, 9, 9).

For Coordinates B(3, 3, 6)

Let the new coordinates of B after scaling = (Xnew, Ynew, Znew).

Applying the scaling equations, we have-

● Xnew = Xold x Sx = 3 x 2 = 6

● Ynew = Yold x Sy = 3 x 3 = 9

● Znew = Zold x Sz = 6 x 3 = 18

Thus, New coordinates of corner B after scaling = (6, 9, 18).

For Coordinates C(3, 0, 1)

Let the new coordinates of C after scaling = (Xnew, Ynew, Znew).

Applying the scaling equations, we have-

● Xnew = Xold x Sx = 3 x 2 = 6

● Ynew = Yold x Sy = 0 x 3 = 0

● Znew = Zold x Sz = 1 x 3 = 3

Thus, New coordinates of corner C after scaling = (6, 0, 3).


For Coordinates D(0, 0, 0)

Let the new coordinates of D after scaling = (Xnew, Ynew, Znew).

Applying the scaling equations, we have-

● Xnew = Xold x Sx = 0 x 2 = 0

● Ynew = Yold x Sy = 0 x 3 = 0

● Znew = Zold x Sz = 0 x 3 = 0

Thus, New coordinates of corner D after scaling = (0, 0, 0).

Visible Surface Detection


When we view a picture containing non-transparent objects and surfaces, then we cannot
see those objects from view which are behind from objects closer to eye. We must remove
these hidden surfaces to get a realistic screen image. The identification and removal of
these surfaces is called Hidden-surface problem.

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.

When we want to display a 3D object on a 2D screen, we need to identify those parts of a


screen that are visible from a chosen viewing position.

Depth Buffer Z−BufferZ−Buffer Method


This method is developed by Cutmull. It is an image-space approach. The basic idea is to
test the Z-depth of each surface to determine the closest visible surface.

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:

Step-1 − Set the buffer values −

Depthbuffer x,yx,y = 0

Framebuffer x,yx,y = background color

Step-2 − Process each polygon OneatatimeOneatatime

For each projected x,yx,y pixel position of a polygon, calculate depth z.

If Z > depthbuffer x,yx,y

Compute surface color,

set depthbuffer x,yx,y = z,

framebuffer x,yx,y = surfacecolor x,yx,y

Advantages

● It is easy to implement.

● It reduces the speed problem if implemented in hardware.

● It processes one object at a time.


Disadvantages

● It requires large memory.

● It is time consuming process.

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.

● Surrounding surface − One that completely encloses the area.

● Overlapping surface − One that is partly inside and partly outside the area.

● Inside surface − One that is completely inside the area.

● Outside surface − One that is completely 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 −

● All surfaces are outside surfaces with respect to the area.

● Only one inside, overlapping or surrounding surface is in the area.

● 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.

In general, if V is a vector in the viewing direction from the


eye or"camera"or"camera" position, then this polygon is a back face if

V.N > 0

Furthermore, if object descriptions are converted to projection coordinates and your


viewing direction is parallel to the viewing z-axis, then −

V = (0, 0, Vz) and V.N = VZC

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.

You might also like