Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

Computer Graphics

Uploaded by

Harshini Baby
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Computer Graphics

Uploaded by

Harshini Baby
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Unit-5

Window to Viewport Transformation is the process of transforming 2D


world-coordinate objects to device coordinates. Objects inside the world
or clipping window are mapped to the viewport which is the area on the
screen where world coordinates are mapped to be displayed.

General Terms:
 World coordinate – It is the Cartesian coordinate w.r.t which we
define the diagram, like X wmin, Xwmax, Ywmin, Ywmax
 Device Coordinate –It is the screen coordinate where the objects are
to be displayed, like Xvmin, Xvmax, Yvmin, Yvmax
 Window –It is the area on the world coordinate selected for display.
 ViewPort –It is the area on the device coordinate where graphics is to
be displayed.
Mathematical Calculation of Window to Viewport:
It may be possible that the size of the Viewport is much smaller or greater
than the Window. In these cases, we have to increase or decrease the
size of the Window according to the Viewport and for this, we need some
mathematical calculations.
(xw, yw): A point on Window
(xv, yv): Corresponding point on Viewport
We have to calculate the point (xv, yv)
Now the relative position of the object in Window and Viewport are same.
For x coordinate,

For y coordinate,

So, after calculating for x and y coordinate, we get

Where sx is the scaling factor of x coordinate and s y is the scaling factor of


y coordinate

Example: Let us assume,


 for window, Xwmin = 20, Xwmax = 80, Ywmin = 40, Ywmax = 80.
 for viewport, Xvmin = 30, Xvmax = 60, Yvmin = 40, Yvmax = 60.
 Now a point ( Xw, Yw ) be ( 30, 80 ) on the window. We have to calculate
that point on the viewport
i.e ( Xv, Yv ).
 First of all, calculate the scaling factor of x coordinate S x and the
scaling factor of y coordinate S y using the above-mentioned formula.

Sx = ( 60 - 30 ) / ( 80 - 20 ) = 30 / 60
Sy = ( 60 - 40 ) / ( 80 - 40 ) = 20 / 40
 So, now calculate the point on the viewport ( X v, Yv ).

Xv = 30 + ( 30 - 20 ) * ( 30 / 60 ) = 35
Yv = 40 + ( 80 - 40 ) * ( 20 / 40 ) = 60
 So, the point on window ( X w, Yw ) = ( 30, 80 ) will be ( Xv, Yv ) = ( 35,
60 ) on viewport.

Clipping
Clipping:
In computer graphics our screen act as a 2-D coordinate system.
it is not necessary that each and every point can be viewed on our
viewing pane(i.e. our computer screen). We can view points, which lie in
particular range (0,0) and (Xmax, Ymax). So, clipping is a procedure that
identifies those portions of a picture that are either inside or outside of our
viewing pane.
In case of point clipping, we only show/print points on our window which
are in range of our viewing pane, others points which are outside the
range are discarded.

Point Clipping Algorithm:

1. Get the minimum and maximum coordinates of both viewing pane.


2. Get the coordinates for a point.
3. Check whether given input lies between minimum and maximum
coordinate of viewing pane.
4. If yes display the point which lies inside the region otherwise discard it.

Advantages :
The Point Clipping Algorithm has several advantages in computer
graphics, including:
1. Versatility: The algorithm can be applied to a wide range of objects,
including points, lines, polygons, and other complex shapes. This
makes it a versatile tool for a wide range of applications.
2. Efficiency: The algorithm is relatively efficient and can be used to
quickly identify and remove points that lie outside a specified region or
boundary. This can help improve the performance of computer
graphics applications, particularly those that involve rendering large or
complex scenes.
3. Accuracy: The Point Clipping Algorithm can be used to accurately clip
objects and ensure that only the portions of an object that are visible or
relevant are displayed. This can help improve the visual quality of
images and animations.

Line Clipping

Description:- In this algorithm, we are given 9 regions on the screen.


Out of which one region is of the window and the rest 8 regions are
around it given by 4 digit binary. The division of the regions are based
on (x_max, y_max) and (x_min, y_min).
The central part is the viewing region or window, all the lines which lie
within this region are completely visible. A region code is always
assigned to the endpoints of the given line.
To check whether the line is visible or not.

4.
Region Codes
Formula to check binary digits :- TBRL which can be defined as top,
bottom, right, and left accordingly.

Algorithm
Steps
1) Assign the region codes to both endpoints.
2) Perform OR operation on both of these endpoints.
3) if OR = 0000,
then it is completely visible (inside the window).
else
Perform AND operation on both these endpoints.
i) if AND ? 0000,
then the line is invisible and not inside the window.
Also, it can’t be considered for clipping.
ii) else
AND = 0000, the line is partially inside the window
There are three possible cases for any given line.
1. Completely inside the given rectangle : Bitwise OR of region of two
end points of line is 0 (Both points are inside the rectangle)
2. Completely outside the given rectangle : Both endpoints share at
least one outside region which implies that the line does not cross the
visible region. (bitwise AND of endpoints != 0).
3. Partially inside the window : Both endpoints are in different regions.
In this case, the algorithm finds one of the two points that is outside the
rectangular region. The intersection of the line from outside point and
rectangular window becomes new corner point and the algorithm
repeats

Polygon clipping
Polygon:
Polygon is a representation of the surface. It is primitive which is closed in nature. It is
formed using a collection of lines. It is also called as many-sided figure. The lines
combined to form polygon are called sides or edges. The lines are obtained by
combining two vertices.
Example of Polygon:
1. Triangle
2. Rectangle
3. Hexagon
4. Pentagon
Following figures shows some polygons.

Types of Polygons
1. Concave
2. Convex
A polygon is called convex of line joining any two interior points of the polygon lies inside
the polygon. A non-convex polygon is said to be concave. A concave polygon has one
interior angle greater than 180�. So that it can be clipped into similar polygons.
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
1. 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.
2. If both vertexes are inside window boundary. Then only second vertex is added to the
output list.
3. 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.
4. If both vertices are the outside window, then nothing is added to output list.
Following figures shows original polygon and clipping of polygon against four windows.
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.

Weiler-Atherton Polygon Clipping:


When the clipped polygons have two or more separate sections, then it is the concave polygon
handled by this algorithm. The vertex-processing procedures for window boundaries are modified
so that concave polygon is displayed.
Let the clipping window be initially called clip polygon and the polygon to be clipped the subject
polygon. We start with an arbitrary vertex of the subject polygon and trace around its border in
the clockwise direction until an intersection with the clip polygon is encountered:
1. If the edge enters the clip polygon, record the intersection point and continue to trace the
subject polygon.
3. If the edge leaves the clip polygon, record the intersection point and make a right turn to
follow the clip polygon in the same manner (i.e., treat the clip polygon as subject polygon
and the subject polygon as clip polygon and proceed as before).
4. Whenever our path of traversal forms a sub-polygon we output the sub-polygon
as part of the overall result. We then continue to trace the rest of the original
subject polygon from a recorded intersection point that marks the beginning of a
not-yet traced edge or portion of an edge. The algorithm terminates when the
entire border of the original subject polygon has been traced exactly once.

For example, the number in fig (a) indicates the order in which the edges and
portion of edges are traced. We begin at the starting vertex and continue along
the same edge (from 1 to 2) of the subject polygon as it enters the clip polygon.
As we move along the edge that is leaving the clip polygon, we make a right turn
(from 4 to 5) onto the clip polygon, which is now considered the subject polygon.
Following the same logic leads to the next right turn (from 5 to 6) onto the current
clip polygon, this is the original subject polygon. With the next step done (from 7
to 8) in the same way, we have a sub-polygon for output in fig (b). We then
resume our traversal of the original subject polygon from the recorded
intersection point where we first changed our course. Going from 9 to 10 to 11
produces no output. After skipping the already traversed 6 and 7, we continue
with 12 and 13 and come to an end. The fig (b) is the final result.

Text Clipping:
Several methods are available for clipping of text. Clipping method is dependent on the
method of generation used for characters. A simple method is completely considered, or
nothing considers method. This method is also called as all or none. If all characters of
the string are inside window, then we will keep the string, if a string character is outside
then whole string will be discarded in fig (a).
Another method is discarded those characters not completely inside the window. If a
character overlap boundary of window. Those will be discarded in fig (b).
In fig (c) individual character is treated. Character lies on boundary is discarded as which
it is outside the window.

Curve Clipping:
Curve Clipping involves complex procedures as compared to line clipping. Curve
clipping requires more processing than for object with linear boundaries. Consider
window which is rectangular in shape. The circle is to consider against rectangle
window. If circle is completely inside boundary of the window, it is considered visible. So
save the circle. If a circle is in outside window, discard it. If circle cut the boundary then
consider it to be clipping case.
Exterior Clipping:
It is opposite to previous clipping. Here picture which is outside the window is
considered. The picture inside the rectangle window is discarded. So part of the picture
outside the window is saved.
Uses of Exterior Clipping:
1. It is used for displaying properly the pictures which overlap each other.
2. It is used in the concept of overlapping windows.
3. It is used for designing various patterns of pictures.
4. It is used for advertising purposes.
5. It is suitable for publishing.
6. For designing and displaying of the number of maps and charts, it is also used.

You might also like