0% found this document useful (0 votes)
67 views63 pages

CG Unit-3 PDF

The document discusses 3D computer graphics concepts including 3D transformations like translation, scaling, and rotation which are represented using matrices. It also covers 3D geometry, modeling, and projections used to produce realistic 3D scenes from 2D.
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)
67 views63 pages

CG Unit-3 PDF

The document discusses 3D computer graphics concepts including 3D transformations like translation, scaling, and rotation which are represented using matrices. It also covers 3D geometry, modeling, and projections used to produce realistic 3D scenes from 2D.
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/ 63

Computer Graphics

Unit-3

Rohit Rana
Assistant Professor
CSE/IT
Vidya College of Engineering
Three Dimensional Graphics
The three-dimensional transformations are extensions of two-dimensional transformation. In
2D two coordinates are used, i.e., x and y whereas in 3D three co-ordinates x, y, and z are
used.
For three dimensional images and objects, three-dimensional transformations are needed.
These are translations, scaling, and rotation. These are also called as basic transformations
are represented using matrix. More complex transformations are handled using matrix in 3D.
The 2D can show two-dimensional objects. Like the Bar chart, pie chart, graphs. But some
more natural objects can be represented using 3D. Using 3D, we can see different shapes of
the object in different sections.
In 3D when a translation is done we need three factors for rotation also, it is a component of
three rotations. Each can be performed along any three Cartesian axis. In 3D also we can
represent a sequence of transformations as a single matrix.
Computer Graphics uses CAD. CAD allows manipulation of machine components which are
3 Dimensional. It also provides automobile bodies, aircraft parts study. All these activities
require realism. For realism 3D is required. In the production of a realistic 3D scene from 2D
is tough. It require three dimension, i.e., depth.
3D Geometry
Three dimension system has three axis x, y, z. The orientation of a 3D coordinate system is of
two types. Right-handed system and left-handed system.
In the right -handed system thumb of right- hand points to positive z-direction and left- hand
system thumb point to negative two directions. Following gure show right-hand orientation of
the cube.
Using right-handed system co-ordinates of corners A, B, C, D of the cube
Point A x, y, z
Point B x, y, 0
Point C 0, y, 0
Point D 0, y, z

fi
Producing realism in 3D- The three-dimensional objects are made using computer
graphics. The technique used for two Dimensional displays of three Dimensional objects
is called projection. Several types of projection are available, i.e.,
1. Parallel Projection
2. Perspective Projection
3. Orthographic Projection

1. Parallel Projection: In this projection point on the screen is identi ed within a point in
the three-dimensional object by a line perpendicular to the display screen. The
architect Drawing, i.e., plan, front view, side view, elevation are nothing but lines of
parallel projections.
2. Perspective Projection: This projection has a property that it provides idea about
depth. Farther the object from the viewer, smaller it will appear. All lines in perspective
projection converge at a center point called as the center of projection.
3. Orthographic Projection: It is simplest kind of projection. In this, we take a top,
bottom, side view of the object by extracting parallel lines from the object.

fi
Three Dimensional Models
The techniques for generating different images of a solid object depend upon the type of
object. Two viewing techniques are available for viewing three-dimensional objects.
1. Geometry: It is concerned with measurements. Measurement is the location of a point
concerning origin or dimension of an object.
2. Topological Information: It is used for the structure of a solid object. It is mainly
concerned with the formation of polygons with the help of points of objects or the
creation of the object with polygons.

Three Dimensional Transformations


The geometric transformations play a vital role in generating images of three Dimensional
objects with the help of these transformations. The location of objects relative to others
can be easily expressed. Sometimes viewpoint changes rapidly, or sometimes objects
move in relation to each other. For this number of transformation can be carried out
repeatedly.
Translation
It is the movement of an object from one position to another position. Translation is done using
translation vectors. There are three vectors in 3D instead of two. These vectors are in x, y, and z
directions. Translation in the x-direction is represented using Tx. The translation is y-direction is
represented using Ty. The translation in the z- direction is represented using Tz.
If P is a point having co-ordinates in three directions (x, y, z) is translated, then after translation
its coordinates will be (x1 y1 z1) after translation. Tx Ty Tz are translation vectors in x, y, and z
directions respectively.
x1=x+ Tx
y1=y+Ty
z1=z+ Tz
Three-dimensional transformations are performed by transforming each vertex of the object. If
an object has ve corners, then the translation will be accomplished by translating all ve
points to new locations. Following gure 1 shows the translation of point gure 2 shows the
translation of the cube.

Matrix for translation


fi
fi
fi
fi
Matrix representation of point translation
Point shown in g is (x, y, z). It become (x1,y1,z1)
after translation. Tx Ty Tz are translation vector.

Example: A point has coordinates in the x, y, z direction


i.e., (5, 6, 7). The translation is done in the x-direction by Multiply co-ordinates of point with translation
3 coordinate and y direction. Three coordinates and in matrix
the z- direction by two coordinates. Shift the object.
Find coordinates of the new position.
Solution: Co-ordinate of the point are (5, 6, 7)
Translation vector in x direction = 3
Translation vector in y direction = 3
Translation vector in z direction = 2
Translation matrix is

= [5+0+0+30+6+0+30+0+7+20+0+0+1] = [8991]
x becomes x1=8
y becomes y1=9
z becomes z1=9
fi
Scaling
Scaling is used to change the size of an object. The size can be increased or decreased. The scaling
three factors are required Sx Sy and Sz.
Sx=Scaling factor in x- direction
Sy=Scaling factor in y-direction
Sz=Scaling factor in z-direction

Matrix for Scaling


Scaling of the object relative to a xed point
Following are steps performed when scaling of objects with xed point (a, b, c). It can be
represented as below:
1. Translate xed point to the origin
2. Scale the object relative to the origin
3. Translate object back to its original position.

Note: If all scaling factors Sx=Sy=Sz.Then scaling is called as uniform. If scaling is done with
different scaling vectors, it is called a differential scaling.

In gure (a) point (a, b, c) is shown, and object whose scaling is to done also shown in steps in
g (b), g (c) and g (d).
fi
fi
fi
fi
fi
fi
fi
Rotation
It is moving of an object about an angle. Movement can be anticlockwise or clockwise. 3D rotation is
complex as compared to the 2D rotation. For 2D we describe the angle of rotation, but for a 3D angle
of rotation and axis of rotation are required. The axis can be either x or y or z.
Following figures shows rotation about x, y, z- axis
Following gure show rotation of the object about the Y axis

Following gure show rotation of the object about the Z axis


fi
fi
Rotation about Arbitrary Axis
When the object is rotated about an axis that is not parallel to any one of co-ordinate axis, i.e., x, y, z.
Then additional transformations are required. First of all, alignment is needed, and then the object is
being back to the original position. Following steps are required
1. Translate the object to the origin
2. Rotate object so that axis of object coincide with any of coordinate axis.
3. Perform rotation about co-ordinate axis with whom coinciding is done.
4. Apply inverse rotation to bring rotation back to the original position.
5. Apply inverse translation to bring rotation axis to the original position.
Matrix for representing three-dimensional rotations about the Z axis

Matrix for representing three-dimensional rotations about the X axis

Matrix for representing three-dimensional rotations about the Y axis


Following gure show the original position of object and position of object after rotation
about the x-axis
fi
For such transformations, composite transformations are required. All the above steps are
applied on points P' and P".Each step is explained using a separate gure.

Step1: Initial position of P' and P"is shown Step2: Translate object P' to origin

fi
Step3: Rotate P" to z axis so that it aligns along the z-axis

Step4: Rotate about around z- axis


Step5: Rotate axis to the original position Step6: Translate axis to the original position.
Inverse Transformations
These are also called as opposite transformations. If T is a translation matrix than inverse
translation is representing using T-1. The inverse matrix is achieved using the opposite sign.
Example1: Translation and its inverse matrix
Translation matrix Inverse translation matrix

Example2: Rotation and its inverse matrix Inverse Rotation Matrix


Re ection
It is also called a mirror image of an object. For this re ection axis and re ection of plane is
selected. Three-dimensional re ections are similar to two dimensions. Re ection is 180° about
the given axis. For re ection, plane is selected (xy,xz or yz). Following matrices show
re ection respect to all these three planes.

Re ection relative to XY plane


fl
fl
fl
fl
fl
fl
fl
fl
Re ection relative to YZ plane

Re ection relative to ZX plane


fl
fl
Shearing
It is change in the shape of the object. It is also called as deformation. Change can be in the x
-direction or y -direction or both directions in case of 2D. If shear occurs in both directions, the
object will be distorted. But in 3D shear can occur in three directions.
Matrix for shear
3D Clipping
3D Viewing Pipeline
Primitives
Object space
Modeling Transformation
World space
Viewing Transformation
Camera space

Hidden Surface Removal

Lighting & Shading

3D-Clipping

Projection
Normalized view space
Scan conversion, Hiding
Image space,
Device coordinates
Image
3D Clipping
• Just like the case in two dimensions, clipping removes objects
that will not be visible from the scene

• The point of this is to remove computational effort

• 3-D clipping is achieved in two basic steps


– Discard objects that can’t be viewed
• i.e. objects that are behind the camera, outside the field of view, or too far away
– Clip objects that intersect with any clipping plane
3D Clipping
• Discarding objects that cannot possibly be seen involves
comparing an objects bounding box/sphere against the
dimensions of the view volume
– Can be done before or after projection
3D Clipping
• Objects that are partially within the viewing volume need to be
clipped – just like the 2D case
The Clipping Volume
• In case of Parallel projections the infinite Parallelepiped is
bounded by Near/front/hither and far/back/yon planes for
clipping.
The Clipping Volume
• In case of Perspective projections the semi Infinite Pyramid is
also bounded by Near/front/hither and far/back/yon planes for
clipping
The Clipping Volume
• After the perspective transformation is complete the frustum
shaped viewing volume has been converted to a parallelepiped
- remember we preserved all z coordinate depth information
Clipping Strategies
• Because of the extraordinary computational effort
required, two types of clipping strategies are followed:
– Direct Clipping: The clipping is done directly against the
view volume.
– Canonical Clipping: Normalization transformations are
applied which transform the original view volume into
normalized (canonical) view volume. Clipping is then
performed against canonical view volume.
Clipping Strategies
• The canonical view volume for parallel projection is the unit
cube whose faces are defined by planes
x=0;x=1 y = 0; y = 1 z = 0; z = 1
Clipping Strategies
• The canonical view volume for perspective projection is the
truncated normalized pyramid whose faces are defined by
planes
x = z ; x = -z y = z; y = -z z = zf; z = 1

y y
clipped line
clipped line
x 1 x
1
near far
z 0 1 z
image plane

near
far
Clipping Strategies
• We perform clipping after the projection transformation and
normalizations are complete.

• So, we have the following:


⎡ xh ⎤ ⎡ x⎤
⎢y ⎥ ⎢ y⎥
⎢ h⎥ = M ⋅⎢ ⎥
⎢ zh ⎥ ⎢z⎥
⎢ ⎥ ⎢ ⎥
⎣h⎦ ⎣1 ⎦

• We apply all clipping to these homogeneous coordinates


Clipping Strategies
• The basis of canonical clipping is the fact that intersection of
line segments with the faces of canonical view volume require
minimal calculations.

• For perspective views, additional clipping may be required to


avoid perspective anomalies produced by the projecting objects
that are behind view point.
Clipping Algorithms
3D clipping algorithms are direct adaptation of 2D clipping
algorithms with following modifications:

1. For Cohen Sutherland: Assignment of out codes


2. For Liang-Barsky: Introduction of new equations
3. For Sutherland Hodgeman: Inside/Out side Test
4. In general: Finding the intersection of Line with plane.
3D Cohen-Sutherland Line Clipping
• Similar to the case in two dimensions, we divide the world into
regions
• This time we use a 6-bit region code to give us 27 different
region codes
• The bits in these regions codes are as follows:

bit 1 bit 2 bit 3 bit 4 bit 5 bit 6


Above Below Right Left Behind Front
3D Cohen-Sutherland Line Clipping

Computer Graphics
3D Cohen-Sutherland Line Clipping

Now we use a 6 bit out


code to handle the near
and far plane.
The testing strategy is
virtually identical to the 2D
case.
3D Cohen-Sutherland Line Clipping
CASE – I Assigning region codes to endpoints for Canonical
Parallel View Volume defined by:
x = 0 , x = 1; y = 0, y = 1; z = 0, z = 1

The bit codes can be set to true(1) or false(0) for depending on


the test for these equations as follows:
Bit 1 ≡ endpoint is Above view volume = sign (y-1)
Bit 2 ≡ endpoint is Below view volume = sign (-y)
Bit 3 ≡ endpoint is Right view volume = sign (x-1)
Bit 4 ≡ endpoint is Left view volume = sign (-x)
Bit 5 ≡ endpoint is Behind view volume = sign (z-1)
Bit 6 ≡ endpoint is Front view volume = sign (-z)
3D Cohen-Sutherland Line Clipping
CASE – II Assigning region codes to endpoints for Canonical
Perspective View Volume defined by:
x = -z , x = z; y = -z, y = z; z = zf , z = 1

The bit codes can be set to true(1) or false(0) for depending on


the test for these equations as follows:
Bit 1 ≡ endpoint is Above view volume = sign (y-z)
Bit 2 ≡ endpoint is Below view volume = sign (-z-y)
Bit 3 ≡ endpoint is Right view volume = sign (x-z)
Bit 4 ≡ endpoint is Left view volume = sign (-z-x)
Bit 5 ≡ endpoint is Behind view volume = sign (z-1)
Bit 6 ≡ endpoint is Front view volume = sign (zf-z)
3D Cohen-Sutherland Line Clipping
• To clip lines we first label all end points with the appropriate
region codes.
• Classify the category of the Line segment as follows
– Visible: if both end points are 000000
– Invisible: if the bitwise logical AND is not 000000
– Clipping Candidate: if the bitwise logical AND is 000000
• We can trivially accept all lines with both end-points in the
[000000] region.
• We can trivially reject all lines whose end points share a
common bit in any position.
3D Cohen-Sutherland Line Clipping
3D Cohen-Sutherland Line Clipping
• For clipping equations for three dimensional line segments are
given in their parametric form.
• For a line segment with end points P1(x1h, y1h, z1h, h1) and
P2(x2h, y2h, z2h, h2) the parametric equation describing any
point on the line is:
P = P1 + ( P2 − P1 )u 0 ≤ u ≤1
• From this parametric equation of a line we can generate the
equations for the homogeneous coordinates:
x h = x1h + ( x 2 h − x1h )u
y h = y1h + ( y 2 h − y1h )u
z h = z1h + ( z 2 h − z1h )u
h = h1 + (h 2 − h1)u
3D Cohen-Sutherland Line Clipping
• Consider the line P1[000010] to P2[001001]
• Because the lines have different values in bit 2 we know the line crosses the right
boundary
3D Cohen-Sutherland Line Clipping
• Since the right boundary is at x = 1 we now know the following
holds:
xh x1h + ( x 2 h − x1h )u
xp = = =1
h h1 + (h 2 − h1)u
• which we can solve for u as follows:
x1h − h1
u=
( x1h − h1) − ( x 2 h − h 2)

• using this value for u we can then solve for yp and zp similarly
• Then simply continue as per the two dimensional line clipping
algorithm
Projection in Computer Graphics
Projection Introduction: The Types of Projection:
technique projection was invented
by the Swiss mathematician,
engineer, and
astronomer “Leonhard Euler
Around” in 1756. The “Episcope”
was the first projection system.
“Projection is a technique or
process which is used to transform
a 3D object into a 2D plane.” In
other words, we can
define “projection as a mapping of
points P (x, y, z) on to its image
P’ (x,’ y,’z’) in the projection plane or
view plane, which create the display
surface.”
There are two types of projection:
1. Perspective Projection.
2. Parallel Projection.

Perspective Projection:
In the perspective projection, the distance of the project plane from the center of
projection is finite. The object size keeps changing in reverse order with distance.
Perspective projection is used to determine the projector lines come together at a single
point. The single point is also called “project reference point” or “Center of projection.”


Characteristic of Perspective Projection:
• The Distance between the object and projection center is finite.
• In Perspective Projection, it is difficult to define the actual size and shape of the
object.
• The Perspective Projection has the concept of vanishing points.
• The Perspective Projection is realistic but tough to implement.

Vanishing Point: Vanishing point can be defined as a point in image plane where all
parallel lines are interlinked. The Vanishing point is also called “Directing Point.”

Use of Vanishing Point:


• It is used in 3D games and graphics editing.
• It is also used to represent 3D objects.
• We can also include perspective in the background of an image.
• We can also insert the shadow effect in an image
Types of Perspective Projection:

There are three types of Perspective Projection.


1.One Point: A One Point perspective contains only one vanishing point on the horizon line.
It is easy to draw.

Use of One Point– The One Point projection is mostly used to draw the images of roads,
railway tracks, and buildings.
Two Point: It is also called “Angular Perspective.” A Two Point perspective contains two
vanishing points on the line.

Use of Two Point– The main use of Two Point projection is to draw the two corner roads.
Three-Point– The Three-Point Perspective contains three vanishing points. Two points lie on the
horizon line, and one above or below the line.
It is very difficult to draw.
When we see an object from above, than the third point is below the ground. If we see an object
from the below, than the third point is in the space above.

Use of Three-Point: It is mainly used in skyscraping.

Advantages:
1. Better Look
2. Clear Representation
Disadvantages:
1. Difficult to Draw
2. Not Suitable for many-dimensional
images
Parallel Projection:
In Parallel Projection, the distance of project plane from the center of projection is infinite. We
can specify the direction of projection instead of the center of the projection. We can connect the
projected vertices through the line segment.
The parallel Projection eliminates the Z-Coordinate. And the parallel lines from each vertex in the
object are enhanced until the lines intersect the view plane.
Characteristic of parallel Projection-

• In parallel Projection, the projection lines are parallel to each other.


• There is the least amount of distortion within the object.
• The lines that are parallel to the object are also parallel to the drawing.
• The view of Parallel Projection is the less realistic cause of no foreshortening.
• The Parallel Projections are good for accurate measurements.

Types of Parallel Projection

There are two kind of parallel Projection:

1. Orthographic Projection
2. Oblique Projection
Orthographic projection: In the Orthographic Parallel Projection, the Projection is
perpendicular to the view plane.

The Orthographic Projection is divided into two parts-

Multi-view Orthographic Projection: In Multiview Orthographic Projection, we can represent


the two-dimensional Orthographic image into a three-dimensional object. The Multiview
Orthographic Projection Includes-

• Front View
• Top View
• Side View
Axonometric Orthographic Projection: The Axonometric Orthographic Projection is used to
construct the pictorial representation of an object. The sight lines are perpendicular to the
projection plane.

The Axonometric Orthographic Projection includes–


1. Isometric: In Isometric, we can represent the three-dimensional objects into two-dimensional
drawings visually. The Angle between the two co-ordinate is 120 degrees.
2. Dimetric: In Dimetric Projection, the view direction of the
two axes are equal, and the direction of the third axis is
defined individually.

3. Trimetric: In the Trimetric Projection, the view direction of all


three axes is unequal. The scale of all three angles is
defined individually.
Oblique Projection: In the Oblique Parallel Projection, the direction of projection is not normal
to projection of plane. It is a simple technique that is used to construct two-dimensional images
of three-dimensional objects.

The Oblique Projection is mostly used in technical drawing.

The Oblique Projection is divided into two parts-

• Cavalier
• Cabinet

Cavalier- In cavalier Projection, there is an angle between


the Projection and Projection Plane is 45 degrees.
Cabinet: In Cabinet Projection, there is an angle
between Projection and Projection Plane is 63.4
degrees.

Advantages:
1.Good for exact Measurement
2.Parallel lines remain parallel
Disadvantages:
1.Less Realistic Looking
2.Angles are not preserved
3.
Thank You

You might also like