0% found this document useful (0 votes)
12 views15 pages

Unit 3.1 Notes

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 15

COMPUTER GRAPHICS

2D Transformations

Transformation means changing some graphics into something else by applying rules. We
can have various types of transformations such as translation, scaling up or down, rotation,
shearing, etc. When a transformation takes place on a 2D plane, it is called 2D
transformation.

Transformations play an important role in computer graphics to reposition the graphics on the
screen and change their size or orientation.

Homogenous Coordinates

To perform a sequence of transformation such as translation followed by rotation and scaling,


we need to follow a sequential process −

 Translate the coordinates,


 Rotate the translated coordinates, and then
 Scale the rotated coordinates to complete the composite transformation.

To shorten this process, we have to use 3×3 transformation matrix instead of 2×2
transformation matrix. To convert a 2×2 matrix to 3×3 matrix, we have to add an extra
dummy coordinate W.

In this way, we can represent the point by 3 numbers instead of 2 numbers, which is
called Homogenous Coordinate system. In this system, we can represent all the
transformation equations in matrix multiplication. Any Cartesian point PX,YX,Y can be
converted to homogenous coordinates by P’ (Xh, Yh, h).

Translation

A translation moves an object to a different position on the screen. You can translate a point
in 2D by adding translation coordinate (tx, ty) to the original coordinate X,YX,Y to get the
new coordinate X′,Y′X′,Y′.
COMPUTER GRAPHICS

From the above figure, you can write that −

X’ = X + tx

Y’ = Y + ty

The pair (tx, ty) is called the translation vector or shift vector. The above equations can also be
represented using the column vectors.

P=[X][Y]P=[X][Y] p' = [X′][Y′][X′][Y′]T = [tx][ty][tx][ty]

We can write it as −

P’ = P + T

Rotation

In rotation, we rotate the object at particular angle θ thetatheta from its origin. From the
following figure, we can see that the point PX,YX,Y is located at angle φ from the horizontal
X coordinate with distance r from the origin.

Let us suppose you want to rotate it at the angle θ. After rotating it to a new location, you will
get a new point P’ X′,Y′X′,Y′.
COMPUTER GRAPHICS

Using standard trigonometric the original coordinate of point PX,YX,Y can be represented as

X=rcosϕ......(1)X=rcosϕ.....(1)

Y=rsinϕ......(2)Y=rsinϕ.....(2)

Same way we can represent the point P’ X′,Y′X′,Y′ as − x

′=rcos(ϕ+θ)=rcosϕcosθ−rsinϕsinθ.......(3)x′=rcos(ϕ+θ)=rcosϕcosθ−rsinϕsinθ........(3)

y′=rsin(ϕ+θ)=rcosϕsinθ+rsinϕcosθ.......(4)y′=rsin(ϕ+θ)=rcosϕsinθ+rsinϕcosθ.......(4)

Substituting equation 11 & 22 in 33 & 44 respectively, we will get

x′=xcosθ−ysinθx′=xcosθ−ysinθ

y′=xsinθ+ycosθy′=xsinθ+ycosθ

Representing the above equation in matrix form, [X′Y′]=[XY]

[cosθ−sinθsinθcosθ]OR[X′Y′]=[XY][cosθsinθ−sinθcosθ]OR P’ = P . R

Where R is the rotation matrix

R=[cosθ−sinθsinθcosθ]R=[cosθsinθ−sinθcosθ]

The rotation angle can be positive and

negative.

For positive rotation angle, we can use the above rotation matrix. However, for negative
angle rotation, the matrix will change as shown below −

R=[cos(−θ)−sin(−θ)sin(−θ)cos(−θ)]R=[cos(−θ)sin(−θ)−sin(−θ)cos(−θ)]

=[cosθsinθ−sinθcosθ](∵cos(−θ)=cosθandsin(−θ)=−sinθ)=[cosθ−sinθsinθcosθ](∵cos(−θ)=cosθ
andsin(−θ)=−sinθ)

Scaling

To change the size of an object, scaling transformation is used. In the scaling process, you
either expand or compress the dimensions of the object. Scaling can be achieved by
multiplying the original coordinates of the object with the scaling factor to get the desired
result.

Let us assume that the original coordinates are X,YX,Y, the scaling factors are (S X, SY), and
the produced coordinates are X′,Y′X′,Y′. This can be mathematically represented as shown
below −
COMPUTER GRAPHICS

X' = X . SX and Y' = Y . SY

The scaling factor SX, SY scales the object in X and Y direction respectively. The above
equations can also be represented in matrix form as below −

(X′Y′)=(XY)[Sx00Sy](X′Y′)=(XY)[Sx00Sy]

OR

P’ = P . S

Where S is the scaling matrix. The scaling process is shown in the following figure.

If we provide values less than 1 to the scaling factor S, then we can reduce the size of the
object. If we provide values greater than 1, then we can increase the size of the object.

Reflection

Reflection is the mirror image of original object. In other words, we can say that it is a rotation
operation with 180°. In reflection transformation, the size of the object does not change.

The following figures show reflections with respect to X and Y axes, and about the origin
respectively.
COMPUTER GRAPHICS

Shear

A transformation that slants the shape of an object is called the shear transformation. There
are two shear transformations X-Shear and Y-Shear. One shifts X coordinates values and
other shifts Y coordinate values. However; in both the cases only one coordinate changes its
coordinates and other preserves its values. Shearing is also termed as Skewing.

X- Shear

The X-Shear preserves the Y coordinate and changes are made to X coordinates, which
causes the vertical lines to tilt right or left as shown in below figure.
COMPUTER GRAPHICS
The transformation matrix for X-Shear can be represented as −

Xsh=𝖥⎣⎢100shx10001⎤⎦⎥Xsh=[1shx0010001]

Y' = Y + Shy . X

X’ = X

Y-Shear

The Y-Shear preserves the X coordinates and changes the Y coordinates which causes the
horizontal lines to transform into lines which slopes up or down as shown in the following
figure.

The Y-Shear can be represented in matrix from as −

Ysh𝖥⎣⎢1shy0010001⎤⎦⎥Ysh[100shy10001]

X’ = X + Shx . Y

Y’ = Y

Matrix representation of transformations.

For translation,
P‘= P+T
x‘ = x + tx
y‘ y ty

This can also be written as ,


x‘ = 1 0 tx . x
y‘ 0 1 ty y
1 001 1
COMPUTER GRAPHICS

For rotation,
x‘ = Cosθ -Sinθ . x
y‘ Sinθ Cosθ y

This can be written as,


x‘ = Cos@ -Sin @ 0 . x
y‘ Sin @ Cos @ 0 y
1 0 0 11

For scaling,
P‘= S.P

This can be written as,


x‘ = Sx 0 0. x
y‘ 0 Sy 0 y
1 0 0 1 1

Composite Transformation

If a transformation of the plane T1 is followed by a second plane transformation T2, then the
result itself may be represented by a single transformation T which is the composition of T1
and T2 taken in that order. This is written as T = T1∙T2.

Composite transformation can be achieved by concatenation of transformation matrices to


obtain a combined transformation matrix.

A combined matrix −

[T][X] = [X] [T1] [T2] [T3] [T4] …. [Tn]

Where [Ti] is any combination of

 Translation
 Scaling
 Shearing
 Rotation
 Reflection

The change in the order of transformation would lead to different results, as in general matrix
multiplication is not cumulative, that is [A] . [B] ≠ [B] . [A] and the order of multiplication.
The basic purpose of composing transformations is to gain efficiency by applying a single
composed transformation to a point, rather than applying a series of transformation, one after
another.

For example, to rotate an object about an arbitrary point (X p, Yp), we have to carry out three
steps −
COMPUTER GRAPHICS

 Translate point (Xp, Yp) to the origin.


 Rotate it about the origin.
 Finally, translate the center of rotation back where it belonged.

We have learnt matrix representations of transformation. We can set up a matrix for


any sequence of transformations as a composite transform matrix by calculating the
matrix product of the individual transform.

For e.g. suppose we want to perform rotation of an object about an arbitrary point.
This can be performed by applying a sequence of three simple transforms a
translation, followed by a rotation followed by another translation. For e.g. suppose
we are asked to rotate the triangle through 900 .

This can be done by first translate the object to the origin. Rotate it by 900 and again translate
it by tx = 2, ty=0.

Translate the object to tx=2, ty= 0

Here we have done one translation, one rotation , one translation again. Complex
transformation can be described as concatenation of simple ones. Suppose we wish to derive
a transformation which will rotate a point through a clockwise angle @ about the point (Rx,
Ry). The rotation transformation be applied to rotate points only about the origin. So we must
translate points so that (Rx, Ry) becomes the origin.

x‘ = x . 1 0 -Rx

y‘ y 0 1 -Ry

1 1 0 0 1
then rotation can be applied

x‘‘ = x‘ Cos@ -Sin@ 0


y‘‘ y‘ Sin@ Cos@ 0
1 1 0 0 1
Finally, we translate point so that the origin is returned to
(Rx,Ry)
x‘‘‘ = x‘‘ 1 0 Rx
y‘‘‘ y‘‘ 0 1 Ry
1 1 0 0 1

Window to view port co-ordinate transformation


“The process of selecting and viewing an image with different views, called windowing.”
All the objects in the real world have a size. We can measure the size and location of an
object by the unit.
COMPUTER GRAPHICS

For Example-We use the meter unit to measure both size and the location of the object.
When we represent the image of an object on the screen, then we use the screen coordinate
system. The screen coordinate system is used to define the location of the object. When we
select the screen coordinate system, then the image can be displayed on the screen.
“The Capability to show some part of an object in a window is known as windowing.”
“The rectangular area describes in the world coordinate system is called the
window.” Viewport:
“The viewport can be defined as an area on the screen which is used to display the object.”
The window is an area space for the object. Viewport surrounds the object. We need the
coordinate transformation to display the object on the screen. We can define many viewports
on a different area of the screen and also see the same object from a different angle in the
viewport.
Window to Viewport transformation:
“Window to viewport transformation is a process of converting two-dimensional or world
into a device coordinate.”
The object inside the clipping window is mapped to the viewport. The viewport is displayed
inside the interface window on the screen. We can use the clipping window to select the part
of an object, and the viewport is used to display the selected part of the object on the screen
or output device.

Steps for Window to Viewport Transformation: We can follow the following steps for
transform window to viewport:
Step 1: Translation of the window towards the Origin– If we shift the window towards the
origin, the upper left, and the lower-left corner of the window will be negative (-). The
translation factor also should be negative (-).
COMPUTER GRAPHICS

Step 2: Resize the window to viewport size– To Convert the size of the window into the
size of the viewport, we will use the following formulas:
Sx = XVmax – XVmin / XWmax – XWmin
Sy = YVmax – YVmin / YWmax – YWmin
Step 3: Translation of window (Position of window and viewport must be same)– If the
lower-left corner of viewport is (0, 0), then the window lower-left corner is already shifted on
origin after following step 1.
If the lower-left corner is not equal to (0, 0), then the translation factor should be positive (+).

It may be possible that sometimes the size of viewport is greater or smaller than the
window. In that situation, we have to enlarge or compress the size of the window
according to the viewport. We can perform it using some mathematical calculations.
A point on window = (XW, YW)
Corresponding point on viewport = (XV, YV)
 To calculate (XV, YV) –
COMPUTER GRAPHICS

Normalized point on window = (XW- XWmin / XWmax – XWmin)


(YW- YWmin / YWmax – YWmin)

Normalized point on viewport = (XV- XVmin / XVmax – XVmin)

(YV- YVmin / YVmax – YVmin)

 Now, the position of object in viewport and window are same-


For Coordinate x:
(XW- XWmin / XWmax – XWmin) = (XV- XVmin / XVmax – XVmin)

For Coordinate y:
(YW- YWmin / YWmax – YWmin) = (YV- YVmin / YVmax – YVmin)
Now, we get
XV = XVmin + (XW- XWmin) Sx

YV = YVmin + (YW- YWmin) Sy

Here Sx and Sy are the scaling factor for x and y coordinate.


Sx = XVmax – XVmin / XWmax – XWmin
Sy = YVmax – YVmin / YWmax – YWmin
Some Important Points:
1. We can select the world coordinate system according to the application program.
2. We can select the screen coordinate system according to the desired design.
3. Viewing transformation is a connection between the world and the screen coordinates.
Advantages:
We can easily represent images on the display screen according to the user’s needs.

THREE DIMENSIONAL DISPLAY METHODS


To obtain display of a three-dimensional scene that has been modeled in world coordinates.
We must first set up a coordinate reference for the "camera". This coordinate reference
defines the position and orientation for the plane of the camera film which is the plane we
want to us to display a view of the objects in the scene. Object descriptions are then
transferred to the camera reference coordinates and projected onto the selected display plane.
We can then display the objects in wireframe (outline) form, or we can apply lighting surface
rendering techniques to shade the visible surfaces.
COMPUTER GRAPHICS
In the 2D system, we use only two coordinates X and Y but in 3D, an extra coordinate Z is
added. 3D graphics techniques and their application are fundamental to the entertainment,
games, and computer-aided design industries. It is a continuing area of research in scientific
visualization.
Furthermore, 3D graphics components are now a part of almost every personal computer
and, although traditionally intended for graphics-intensive software such as games, they are
increasingly being used by other applications.

Parallel Projection

Parallel projection discards z-coordinate and parallel lines from each vertex on the object are
extended until they intersect the view plane. In parallel projection, we specify a direction of
projection instead of center of projection.
The appearance of the solid object can be reconstructed from the major views

In parallel projection, the distance from the center of projection to project plane is infinite.
In this type of projection, we connect the projected vertices by line segments which
correspond to connections on the original object.
Parallel projections are less realistic, but they are good for exact measurements. In this type
of projections, parallel lines remain parallel and angles are not preserved. Various types of
parallel projections are shown in the following hierarchy.
COMPUTER GRAPHICS

Orthographic Projection

In orthographic projection the direction of projection is normal to the projection of the plane.
There are three types of orthographic projections −

 Front Projection
 Top Projection
 Side Projection

Oblique Projection

In oblique projection, the direction of projection is not normal to the projection of plane. In
oblique projection, we can view the object better than orthographic projection.
There are two types of oblique projections − Cavalier and Cabinet. The Cavalier projection
makes 45° angle with the projection plane. The projection of a line perpendicular to the view
plane has the same length as the line itself in Cavalier projection. In a cavalier projection,
the foreshortening factors for all three principal directions are equal.
The Cabinet projection makes 63.4° angle with the projection plane. In Cabinet projection,
lines perpendicular to the viewing surface are projected at ½ their actual length. Both the
projections are shown in the following figure −
COMPUTER GRAPHICS

Isometric Projections

Orthographic projections that show more than one side of an object are called axonometric
orthographic projections. The most common axonometric projection is an isometric
projection where the projection plane intersects each coordinate axis in the model
coordinate system at an equal distance. In this projection parallelism of lines are preserved
but angles are not preserved. The following figure shows isometric projection −

Perspective Projection

In perspective projection, the distance from the center of projection to project plane is finite
and the size of the object varies inversely with distance which looks more realistic.
The distance and angles are not preserved and parallel lines do not remain parallel. Instead,
they all converge at a single point called center of projection or projection reference
point. There are 3 types of perspective projections which are shown in the following chart.
 One point perspective projection is simple to draw.
 Two point perspective projection gives better impression of depth.
 Three point perspective projection is most difficult to draw.
COMPUTER GRAPHICS

The following figure shows all the three types of perspective projection −

You might also like