Transformation and Viewing (1)
Transformation and Viewing (1)
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)
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.
• 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
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
Here,