KEMBAR78
2D Viewing Notes | PDF | 2 D Computer Graphics | Window (Computing)
0% found this document useful (0 votes)
55 views10 pages

2D Viewing Notes

The document discusses computer graphics concepts such as windowing, viewport, and the transformation process between them. It explains clipping techniques for points, lines, polygons, and text, detailing algorithms like Cohen-Sutherland and Sutherland-Hodgman for efficient rendering. Additionally, it covers curve clipping and the importance of coordinate transformations in displaying objects on a screen.

Uploaded by

Alok Choudhary
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)
55 views10 pages

2D Viewing Notes

The document discusses computer graphics concepts such as windowing, viewport, and the transformation process between them. It explains clipping techniques for points, lines, polygons, and text, detailing algorithms like Cohen-Sutherland and Sutherland-Hodgman for efficient rendering. Additionally, it covers curve clipping and the importance of coordinate transformations in displaying objects on a screen.

Uploaded by

Alok Choudhary
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/ 10

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 (-).

Dr. D. UDAYA / Assistant Professor AAGASC/Department of Computer Science / KKL


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) –

Dr. D. UDAYA / Assistant Professor AAGASC/Department of Computer Science / KKL


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.
Clipping
The primary use of clipping in computer graphics is to remove objects, lines, or line segments
that are outside the viewing pane. The viewing transformation is insensitive to the position of
points relative to the viewing volume − especially those points behind the viewer − and it is
necessary to remove these points before generating the view.
Point Clipping
Clipping a point from a given window is very easy. Consider the following figure, where the
rectangle indicates the window. Point clipping tells us whether the given point X,YX,Y is
within the given window or not; and decides whether we will use the minimum and
maximum coordinates of the window.

Dr. D. UDAYA / Assistant Professor AAGASC/Department of Computer Science / KKL


COMPUTER GRAPHICS

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.

Line Clipping
The concept of line clipping is same as point clipping. In line clipping, we will cut the portion
of line which is outside of window and keep only the portion that is inside the window.
Cohen-Sutherland Line Clippings
This algorithm uses the clipping window as shown in the following figure. The minimum
coordinate for the clipping region is (XWmin,YWmin)(XWmin,YWmin) and the maximum
coordinate for the clipping region is (XWmax,YWmax)(XWmax,YWmax).

We will use 4-bits to divide the entire region. These 4 bits represent the Top, Bottom, Right,
and Left of the region as shown in the following figure. Here, the TOP and LEFT bit is set to
1 because it is the TOP-LEFT corner.

Dr. D. UDAYA / Assistant Professor AAGASC/Department of Computer Science / KKL


COMPUTER GRAPHICS

There are 3 possibilities for the line −


 Line can be completely inside the window This line should be accepted.
 Line can be completely outside of the
window ThislinewillbecompletelyremovedfromtheregionThislinewillbecompletelyre
movedfromtheregion.
 Line can be partially inside the
window Wewillfindintersectionpointanddrawonlythatportionoflinethatisinsideregion
Wewillfindintersectionpointanddrawonlythatportionoflinethatisinsideregion.
Region code
– A four-digit binary code assigned to every line endpoint in a picture.
– Numbering the bit positions in the region code as 1 through 4 from right to left.

• Bit values in the region code


• Determined by comparing endpoint coordinates to the clip boundaries
• A value of 1 in any bit position: The point is in that relative position.
• Determined by the following steps:
• Calculate differences between endpoint coordinates and clipping boundaries.
• Use the resultant sign bit of each difference calculation to set the corresponding
bit value.
• The possible relationships:
• Completely contained within the window
• 0000 for both endpoints.
• Completely outside the window
• Logical and the region codes of both endpoints, its result is not 0000.
• Partially

Dr. D. UDAYA / Assistant Professor AAGASC/Department of Computer Science / KKL


COMPUTER GRAPHICS

Algorithm
Step 1 − Assign a region code for each endpoints.
Step 2 − If both endpoints have a region code 0000 then accept this line.
Step 3 − Else, perform the logical AND operation for both region codes.
Step 3.1 − If the result is not 0000, then reject the line.
Step 3.2 − Else you need clipping.
Step 3.2.1 − Choose an endpoint of the line that is outside the window.
Step 3.2.2 − Find the intersection point at the window boundary base on region code
Step 3.2.3 − Replace endpoint with the intersection point and update the region code.
Step 3.2.4 − Repeat step 2 until we find a clipped line either trivially accepted or trivially
rejected.
Step 4 − Repeat step 1 for other lines.

Liang-Barsky Line Clipping


Rewrite the line parametric equation as follows:

• pk = 0, parallel to one of the clipping boundary


• qk < 0, outside the boundary
• qk >= 0, inside the parallel clipping boundary
• pk < 0, the line proceeds from outside to the inside
• pk > 0, the line proceeds from inside to outside

Dr. D. UDAYA / Assistant Professor AAGASC/Department of Computer Science / KKL


COMPUTER GRAPHICS

Polygon Clipping
Sutherland Hodgman Algorithm
A polygon can also be clipped by specifying the clipping window. Sutherland Hodgeman
polygon clipping algorithm is used for polygon clipping. In this algorithm, all the vertices of
the polygon are clipped against each edge of the clipping window.
First the polygon is clipped against the left edge of the polygon window to get new vertices
of the polygon. These new vertices are used to clip the polygon against right edge, top edge,
bottom edge, of the clipping window as shown in the following figure.

Dr. D. UDAYA / Assistant Professor AAGASC/Department of Computer Science / KKL


COMPUTER GRAPHICS

While processing an edge of a polygon with clipping window, an intersection point is found
if edge is not completely inside clipping window and the a partial edge from the intersection
point to the outside edge is clipped. The following figures show left, right, top and bottom
edge clippings −

Text Clipping
Various techniques are used to provide text clipping in a computer graphics. It depends on the
methods used to generate characters and the requirements of a particular application. There
are three methods for text clipping which are listed below −
 All or none string clipping
 All or none character clipping
 Text clipping

Dr. D. UDAYA / Assistant Professor AAGASC/Department of Computer Science / KKL


COMPUTER GRAPHICS

The following figure shows all or none string clipping −

In all or none string clipping method, either we keep the entire string or we reject entire string
based on the clipping window. As shown in the above figure, STRING2 is entirely inside the
clipping window so we keep it and STRING1 being only partially inside the window, we
reject.
The following figure shows all or none character clipping −

This clipping method is based on characters rather than entire string. In this method if the
string is entirely inside the clipping window, then we keep it. If it is partially outside the
window, then −
 You reject only the portion of the string being outside
 If the character is on the boundary of the clipping window, then we discard that entire
character and keep the rest string.
The following figure shows text clipping −

Dr. D. UDAYA / Assistant Professor AAGASC/Department of Computer Science / KKL


COMPUTER GRAPHICS

This clipping method is based on characters rather than the entire string. In this method if the
string is entirely inside the clipping window, then we keep it. If it is partially outside the
window, then
 You reject only the portion of string being outside.
 If the character is on the boundary of the clipping window, then we discard only that
portion of character that is outside of the clipping window.
Curve Clipping
Curve-clipping procedures will involve nonlinear equations and this requires more processing
than for objects with linear boundaries. The bounding rectangle for a circle or other curved
object can be used first to test for overlap with a rectangular clip window.
If the bounding rectangle for the object is completely inside the window, we save the
object.
If the rectangle is determined to be completely outside window, we discard the object. In
either case, there is no further computation necessary. But if the bounding rectangle test fails,
we can look for other computation-saving approaches.
For a circle, we can use the coordinate extents of individual quadrants and then octants for
preliminary testing before calculating curve-window intersections.
For an ellipse, we can test the coordinate extents of individual quadrants Fig: Clipping a
filled Circle

Dr. D. UDAYA / Assistant Professor AAGASC/Department of Computer Science / KKL

You might also like