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

Transformation and Viewing (1)

Uploaded by

Tirth Patel
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)
12 views80 pages

Transformation and Viewing (1)

Uploaded by

Tirth Patel
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/ 80

2D and 3D transformation

and viewing:
Transformations (translation, rotation, scaling)
• Transformation refers to the mathematical operations or
rules that are applied on a graphical image consisting of
the number of lines, circles, and ellipses to change its
size, shape, or orientation.
• It can also reposition the image on the screen.
• Transformation means changing some graphics into
something else by applying rules.
• There are various types of transformations in computer
graphics through which an image can be processed, edited ad
altered.
• Some basic and most commonly used types of these
transformations are:
1.Translation
2.Rotation
3.Scaling
4.Reflection
5.Shearing
Translation
• Translation refers to a technique in which a point is shift from
one place to another, whose distance is known.
• Consider a point A(x1, y1) be shifted to another point B (x2, y2).
Now we only know the shifting distance tx along x-axis and
ty along y-axis.
• Now, the new coordinates (x2, y2) can be calculated as:
• x2 = x1 + tx
• y 2 = y1 + ty
For example:
Suppose we want to shift a point with coordinates at A(30,100) and
distance along x-axis is 10 units and 20 units along y-axis.
Using translation:
Here tx = 10 ;
and ty = 20
New coordinates A’ (x2, y2):
x2 = 30 + 10 = 130
y2 = 100 + 20 = 120
The point will be shifted to A’ (130, 120 ).
Rotation
• It is a process of changing the angle of the object. Rotation can
be clockwise or anticlockwise.
• For rotation, we have to specify the angle of rotation and
rotation point.
• Rotation point is also called a pivot point.
• It is print about which object is rotated.
Types of Rotation:
1.Anticlockwise
2.Counterclockwise
The positive value of the pivot point (rotation angle) rotates an object in a
counter-clockwise (anti-clockwise) direction.
The negative value of the pivot point (rotation angle) rotates an object in a
clockwise direction.
When the object is rotated, then every point of the object is rotated by the
same angle.
Straight Line: Straight Line is rotated by the endpoints with the same
angle and redrawing the line between new endpoints.
Polygon: Polygon is rotated by shifting every vertex using the same
rotational angle.
Curved Lines: Curved Lines are rotated by repositioning of all points and
drawing of the curve at new positions.
Circle: It can be obtained by center position by the specified angle.
Ellipse: Its rotation can be obtained by rotating major and minor axis of an
ellipse by the desired angle.
Scaling:
• It is used to alter or change the size of objects.
• The change is done using scaling factors.
• There are two scaling factors, i.e. Sx in x direction Sy in y-direction.
• If the original position is x and y. Scaling factors are Sx and Sy then the
value of coordinates after scaling will be x1 and y1.
• If scaling factors are less than one, then the size of the object will be
reduced. If scaling factors are higher than one, then the size of the
object will be enlarged.
• If Sxand Syare equal it is also called as Uniform Scaling.
• If not equal then called as Differential Scaling.
Matrix Representation of 2D Transformation
 Homogeneous 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,Y
can be converted to homogenous coordinates by (Xh, Yh, h)
Composite Transformation:
A composite transformation (or composition of transformations) is two or
more transformations performed one after the other
For Ex.
Step1: The object is kept at its position as in fig (a)

Step2: The object is translated so that its center coincides with the origin as in
fig (b)

Step3: Scaling of an object by keeping the object at origin is done in fig (c)

Step4: Again translation is done. This second translation is called a reverse


translation. It will position the object at the origin location.
Advantages :
• It transformations become compact.
• The number of operations will be reduced.
• Rules used for defining transformation in form of equations are complex as
compared to matrix.
 Computer Graphics Window:

• The method of selecting and enlarging a portion of a drawing is called


windowing.
• The area chosen for this display is called a window. The window is selected
by world-coordinate.
• Window: Area selected in world-coordinate for display is called window. It
defines what is to be viewed.
Sometimes we are interested in some portion of the object and not
in full object. So we will decide on an imaginary box. This box will
enclose desired or interested area of the object. Such an imaginary
box is called a window.
Viewing Pipeline
• Viewport: An area on display device to which a window is mapped [where it
is to displayed].
• In many case window and viewport are rectangle, also other shape may be
used as window and viewport.
• Basically, the window is an area in object space.
• In general finding device coordinates of viewport from word coordinates of
window is called as viewing transformation
In computer graphics terminology, the term window originally referred to an
area of a picture that is selected for viewing.
window-to-viewport transformation
shows the window to viewport mapping.
A point at position (xw, yw) in window mapped into position (xv, yv) in the
associated viewport.
Equation (1) and Equation (2) can also be derived with a set of transformation
that converts the window or world coordinate area into the viewport or screen
coordinate area. This conversation is performed with the following sequence of
transformations:
1.Perform a scaling transformation using a fixed point position (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. Relative
proportions of objects are maintained if the scaling factors are the same (sx=sy).
 Clipping :
• Clipping in computer graphics refers to removing objects or parts of
objects outside of the visible area of a computer screen or viewport.
• Clipping, as a fundamental process in computer graphics, displays only
the part of a scene which is needed to be displayed and rejects all others.
• In two dimensions, the clipping process can be applied to a variety of
geometric primitives such as points, lines, polygons or curves.
•In computer graphics, any procedure that eliminates those
portions of a picture that are either inside or outside a
specified region of space is referred to as a clipping
algorithm or simply clipping.
•The region against which an object is to be clipped is called
a clipping object.
•For deciding the visible and invisible portion, a particular
process called clipping is used. Clipping determines each
element into the visible and invisible portion. Visible portion is
selected. An invisible portion is discarded.
Types of Lines in clipping :
Lines are of three types:
1.Visible: A line or lines entirely inside the window is considered visible
2.Invisible: A line entirely outside the window is considered invisible
3.Clipped: A line partially inside the window and partially outside is clipped. For
clipping point of intersection of a line with the window is determined.
Clipping can be applied through hardware as well as software.
In some computers, hardware devices automatically do work of clipping.
In a system where hardware clipping is not available software clipping applied.
Types of Clipping:
1.Point Clipping
2.Line Clipping
3.Area Clipping (Polygon)
4.Curve Clipping
Point Clipping:
Point Clipping is used to determining, whether the point is inside the window or not.
For this following conditions are checked.
Wx ≤ xmax
Wx ≥ xmin
Wy ≤ ymax
Wy ≥ ymin

The X-coordinate of the given point is inside the window, if X lies in between Wx1 ≤ X
≤ Wx2. Same way, Y coordinate of the given point is inside the window, if Y lies in
between Wy1 ≤ Y ≤ Wy2.

The Point Clipping Algorithm is a fundamental algorithm used in Computer Graphics to


determine whether a point lies inside or outside a specific region or boundary. It is
particularly useful when dealing with objects that have complex shapes or when
displaying only a portion of an image.
Line clipping
• A line-clipping algorithm processes each line in a scene through a series of tests and
intersection calculations to determine whether the entire line or any part of it is to be
saved.
• It also calculates the intersection position of a line with the window edges so its major
goal is to minimize these calculations.
• The line clipping algorithms are:
 Cohen Sutherland Line Clipping Algorithm
 Midpoint Subdivision Line Clipping Algorithm
 Liang-Barsky Line Clipping Algorithm
Cohen Sutherland Line Clipping Algorithm:
In the algorithm, first of all, it is detected whether line
lies inside the screen or it is outside the screen.
All lines come under any one of the following
categories:

• Visible
• Not Visible
• Clipping Case or partially visible
1. Visible: If a line lies within the window, i.e., both endpoints of the line lies within the
window. A line is visible and will be displayed as it is.
2. Not Visible: If a line lies outside the window it will be invisible and rejected. Such lines
will not display. If any one of the following inequalities is satisfied, then the line is
considered invisible. Let A (x1,y2) and B (x2,y2) are endpoints of line.
xmin,xmax are coordinates of the window.
ymin,ymax are also coordinates of the window.
x1>xmax
x2>xmax
y1>ymax
y2>ymax
x1<xmin
x2<xmin
y1<ymin
y2<ymin
3. Clipping Case:
If the line is neither visible case nor invisible case.
It is considered to be clipped case.
First of all, the category of a line is found based on nine regions given below.
All nine regions are assigned codes. Each code is of 4 bits.
If both endpoints of the line have end bits zero, then the line is considered to be
visible.
Mid Point Subdivision Line Clipping Algorithm:
• It is used for clipping line. The line is divided in two parts.
• Mid points of line is obtained by dividing it in two short segments.
• Again division is done, by finding midpoint.
• This process is continued until line of visible and invisible category is obtained.
• Let (xi,yi) are midpoint
x5lie on point of intersection of boundary of window.
Advantage of midpoint subdivision Line Clipping:
• It is suitable for machines in which multiplication and division
operation is not possible.
• Because it can be performed by introducing clipping divides in
hardware.
The Liang-Barsky algorithm is a line clipping algorithm.
• This algorithm is more efficient than Cohen–Sutherland line clipping
algorithm and can be extended to 3-Dimensional clipping.
• This algorithm is considered to be the faster parametric line-clipping
algorithm.
Parametric Equation
Polygon Clipping
• For polygon clipping, we require an algorithm that wiIl generate one or
more closed areas that are then scan converted for the appropriate area fill.
• What we reaIly want to display is a bounded area after clipping.
Sutherland-Hodgeman Polygon Clipping:
It is performed by processing the boundary of polygon against each
window corner or edge.
First of all entire polygon is clipped against one edge, then resulting
polygon is considered, then the polygon is considered against the second
edge, so on for all four edges.
Four possible situations while processing
If the first vertex is an outside the window, the second vertex is inside
the window. Then second vertex is added to the output list. The point of
intersection of window boundary and polygon side (edge) is also added
to the output line.
If both vertexes are inside window boundary. Then only second vertex is
added to the output list.
If the first vertex is inside the window and second is an outside window.
The edge which intersects with window is added to output list.
If both vertices are the outside window, then nothing is added to output
list.
Disadvantage of Cohen Hodgmen Algorithm:
This method requires a considerable amount of memory.
The first of all polygons are stored in original form. Then clipping
against left edge done and output is stored.
Then clipping against right edge done, then top edge. Finally, the
bottom edge is clipped. Results of all these operations are stored
in memory.
So wastage of memory for storing intermediate polygons.
3D displays methods: Projection
• Representing n – dimensional object into n-1 dimension is
known as projection.
• It is a process of converting 3D object into 2D object.
• It is also defined as a mapping of transformation of the object
in projection plane or view plane
Such images may be for later display or for real-time viewing.
we can divide projection into two categories: parallel and
perspective.:
•Parallel Projection.
•Perspective Projection.
Parallel Projection
In this type of projection, the object in the real world is projected onto a
plane exactly parallel to the 3D object.
Additionally, here the lines of projection remain a straight line or parallel
lined
Further, we can visualize parallel projection using an example:
Computer Graphics Curves
• In computer graphics, we often need to draw different types of objects
onto the screen.
• Objects are not flat all the time and we need to draw curves many times to
draw an object.
Types of Curves
A curve is an infinitely large set of points.
Each point has two neighbors except endpoints.
Curves can be broadly classified into three categories
− explicit, implicit, and parametric curves.
Implicit curve:
• If a point is present on the curve then you said it is
implicit.
• Implicit curve representations define the set of points on
a curve by employing a procedure that can test to see if a
point in on the curve.
• an implicit curve is defined by an implicit function of the
form −

• F( x,y) = 0
F means Scalar function=> it returns a single real numbers.
Explicit Curves
• A mathematical function y = f (x) can be plotted as a curve.
Such a function is the explicit representation of the curve.
The explicit representation is not general, since it cannot
represent vertical lines and is also single-valued. For each
value of x, only a single value of y is normally computed by
the function.
Parametric Curves

Curves having parametric form are called parametric curves.


The explicit and implicit curve representations can be used only when the function is
known.
In practice the parametric curves are used. A two-dimensional parametric curve has the
following form −

P(t) = f(t) , g(t) or


P(t)= x(t), y (t) for 2D
Bezier Curves
Bezier Curve may be defined as-
• Bezier Curve is parametric curve defined by a set of control points.
• Two points are ends of the curve.
• Other points determine the shape of the curve.

The concept of bezier curves was given by Pierre Bezier.


Bezier Curve Example-

The following curve is an example of a bezier curve-


Here,
• This bezier curve is defined by a set of control points b0, b1, b2 and b3.
• Points b0 and b3 are ends of the curve.
• Points b1 and b2 determine the shape of the curve.
Bezier Curve Properties-
1. Bezier curve is always contained within a polygon called as convex
hull (Boundary) of its control points.
2 Bezier curve generally follows the shape of its defining polygon.
•The first and last points of the curve are coincident with the first and last points of the
defining polygon.

3. The degree of the polynomial defining the curve segment is one less than the total
number of control points.
Degree = Number of Control Points – 1

Bezier Curve Equation-

A bezier curve is parametrically represented by-


Cubic Bezier Curve-

•Cubic bezier curve is a bezier curve with degree 3.


•The total number of control points in a cubic bezier curve is 4.

Here,

This curve is defined by 4 control


points b0, b1, b2 and b3.
The degree of this curve is 3.
So, it is a cubic bezier curve.
B-Spline Curve

• In Bezier curve it is based in control point. The curve is drawn based on


completely control point. In this curve any one point is change the
whole curve is (Complete structure is )changed that is called global
Control
• In B-spline curve if any of the point is changed the affect is in that point
only so that is called local control

You might also like