Unit - 3 Window & View Port CGM
Unit - 3 Window & View Port CGM
Window:
1. A world-coordinate area selected for display is called a window.
2. In computer graphics, a window is a graphical control element.
3. It consists of a visual area containing some of the graphical user interface of
the program it belongs to and is framed by a window decoration.
4. A window defines a rectangular area in world coordinates. You define a
window with a GWINDOW statement. You can define the window to be larger
than, the same size as, or smaller than the actual range of data values,
depending on whether you want to show all of the data or only part of the
data.
Viewport:
1. An area on a display device to which a window is mapped is called a viewport.
2. A viewport is a polygon viewing region in computer graphics. The viewport is
an area expressed in rendering-device-specific coordinates, e.g. pixels for
screen coordinates, in which the objects of interest are going to be rendered.
3. A viewport defines in normalized coordinates a rectangular area on the
display device where the image of the data appears. You define a viewport
with the GPORT command. You can have your graph take up the entire
display device or show it in only a portion, say the upper-right part.
Now the relative position of the object in Window and Viewport are same.
For x coordinate,
For y coordinate,
Example:
Lets 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 viewport
i.e ( Xv, Yv ).
First of all, calculate scaling factor of x coordinate Sx and scaling
factor of y coordinate Sy using above mentioned formula.
Sx = ( 60 - 30 ) / ( 80 - 20 ) = 30 / 60
Sy = ( 60 - 40 ) / ( 80 - 40 ) = 20 / 40
So, now calculate the point on viewport ( Xv, Yv ).
Xv = 30 + ( 30 - 20 ) * ( 30 / 60 ) = 35
Yv = 40 + ( 80 - 40 ) * ( 20 / 40 ) = 60
So, the point on window ( Xw, Yw ) = ( 30, 80 ) will be ( Xv, Yv ) = (
35, 60 ) on viewport.