Computer Graphics(clipping and window viewport mapping)
Computer Graphics(clipping and window viewport mapping)
Applications of clipping:
1. It will extract part we desire.
2. For identifying the visible and invisible area in the 3D object.
3. For creating objects using solid modeling.
4. For drawing operations.
5. Operations related to the pointing of an object.
6. For deleting, copying, moving part of an object.
Types of Clipping:
1. Point Clipping
2. Line Clipping
3. Area Clipping (Polygon)
4. Curve Clipping
5. Text Clipping
6. Exterior Clipping
Point Clipping is used to determining, whether the point is inside the window or not. For this
following conditions are checked.
1. x ≤ xmax
2. x ≥ xmin
3. y ≤ ymax
4. y ≥ ymin
The (x, y) is coordinate of the point. If anyone from the above inequalities is false, then the
point will fall outside the window and will not be considered to be visible
Line Clipping:
It is performed by using the line clipping algorithm. The line clipping algorithms are:
1. Cohen Sutherland Line Clipping Algorithm.
2. Midpoint Subdivision 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:
1. Visible
2. Not Visible
3. Clipping Case
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.
The center area is having the code, 0000, i.e., region 5 is considered a rectangle window.
Now let’s understand what is Windowing. Before that, we must know the concept of
Windows and Viewports.
A world-coordinate system selected for display is called a Window and the area on the
device coordinate to which a Window is mapped is called a Viewport.
The mapping of a part of the World-coordinate system to a device coordinate is called
viewing transformation or Window-to-viewport transformation or simply, windowing
transformation.
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.
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.
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 −
There are four possible cases for any given edge of given polygon against current clipping
edge e.
1. Both vertices are inside : Only the second vertex is added to the output list
2. First vertex is outside while second one is inside : Both the point of intersection of
the edge with the clip boundary and the second vertex are added to the output list
3. First vertex is inside while second one is outside : Only the point of intersection of
the edge with the clip boundary is added to the output list
4. Both vertices are outside : No vertices are added to the output list.
Window to Viewport Transformation :
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 Xwmin, 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,
Where sx is the scaling factor of x coordinate and sy is the scaling factor of y coordinate
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
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 −
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.
Graphics Software Standards in Computer Graphics
Graphics software standards help to create and set a standard for the development of
computer graphics, as there are mainly two categories or general classes of computer
graphics:
General programming packages and Special-purpose applications packages.
Each of these classes has its software standard, so understanding these standards is
important to get an overview of how standards are defined in computer graphics. by
understanding the classes for computer graphics it becomes easier to understand the
standards for them, lets look at two of the graphics packages in computer graphics.
Graphics Packages
Computer graphics are divided into two package classes and each of these two packages
contains one graphics software standard which is used in the computer graphics to create
working software for the graphics in computers:
General Graphics Programming Package
A general graphics programming package helps in providing a set of functions for the
graphics that are used in high-level programming languages such as C or FORTRAN etc. real-
life example of a general graphics programming package can be the GL which stands for the
graphics library system, it's used in the silicon graphics.
Some of the basic functions for a general package can include the following criteria:
• generating picture components (such as polygons, circles, lines, and other figures)
• setting color values.
• setting intensity values.
• selecting views and managing transformations etc.
Application graphics packages
Application graphics packages are those packages that are designed for non-programmers to
use, it'sthat are aredesigned so that the users can easily generate and display the graphics
without having to worry about the operations and calculations of the graphics.
Interface in these types of graphics allows the users to easily communicate with the
programs by having their own set of terms.
Some examples of the application packages are the painting programs used by various
artists such as AutoCAD etc. along with some other business and medical art softwares.
Graphics Standards in Computer Graphics
The primary goal for the graphics software's standard is portability so whenever a package is
designed with some standards for the computer graphics, then the software can be moved
from hardware system one to hardware system two in an easy way and also be implemented
more easily.
Without the standards for the programs, it becomes a complex and even impossible task to
transfer the programs which are designed for a particular hardware to be moved to another
system hardware. to solve this issue two standards were developed in computer graphics:
• GKS
• PHIGS
Understanding each of these graphics standards is important to know how the graphics
standards work for computer graphics.
GKS (Graphical Kernel System)
Graphical Kernel System is recognized as one of the first graphics software standards by the
ISO (International Standards Organization) which is the most important organization that
manages the top-level two-dimensional two-dimensional three-dimensional standards
related to computer study. the GKS standard was also recognized by the ANSI or American
National Standards Institute later.
Graphical Kernel System was originally designed as a graphics package for the two-
dimensional three-dimensional view but another extension of the GKS was later developed
that supports the three dimensional view as well.
Graphical kernel system has a 2-dimensional view which is related to the six of the output
functions used, they are as follows:
GKS (Graphical Kernel System)
Miscellaneous Functions
a. Transformations
• Translation: Moving objects along x, y, or z axes.
• Scaling: Resizing objects proportionally or non-proportionally.
• Rotation: Rotating objects about a fixed axis.
• Shearing: Skewing shapes along one or more axes.
b. Pattern Filling
• Apply predefined or custom patterns, textures, or gradients to surfaces.
c. Lighting and Shading
• Lighting Types:
o Ambient Light: Evenly distributed light in the scene.
o Point Light: Emitted from a specific location.
o Directional Light: Uniform light from a direction.
• Shadow Mapping: Simulates realistic shadows for 3D objects.
d. Exporting
• Save outputs in formats like:
o Raster Formats: PNG, BMP, TIFF.
o Vector Formats: SVG, PDF, EPS.
Advantage:
1. Easy to use
2. Not very expensive
Trackball
It is a pointing device. It is similar to a mouse. This is mainly used in notebook or laptop
computer, instead of a mouse. This is a ball which is half inserted, and by changing fingers on
the ball, the pointer can be moved.
Advantage:
1. Trackball is stationary, so it does not require much space to use it.
2. Compact Size
Spaceball:
It is similar to trackball, but it can move in six directions where trackball can move in two
directions only. The movement is recorded by the strain gauge. Strain gauge is applied with
pressure. It can be pushed and pulled in various directions. The ball has a diameter around
7.5 cm. The ball is mounted in the base using rollers. One-third of the ball is an inside box,
the rest is outside.
Applications:
1. It is used for three-dimensional positioning of the object.
2. It is used to select various functions in the field of virtual reality.
3. It is applicable in CAD applications.
4. Animation is also done using spaceball.
5. It is used in the area of simulation and modeling.
Joystick:
A Joystick is also a pointing device which is used to change cursor position on a monitor
screen. Joystick is a stick having a spherical ball as its both lower and upper ends as shown in
fig. The lower spherical ball moves in a socket. The joystick can be changed in all four
directions. The function of a joystick is similar to that of the mouse. It is mainly used in
Computer Aided Designing (CAD) and playing computer games.
Light Pen
Light Pen (similar to the pen) is a pointing device which is used to select a displayed menu
item or draw pictures on the monitor screen. It consists of a photocell and an optical system
placed in a small tube. When its tip is moved over the monitor screen, and pen button is
pressed, its photocell sensing element detects the screen location and sends the
corresponding signals to the CPU.
Uses:
1. Light Pens can be used as input coordinate positions by providing necessary
arrangements.
2. If background color or intensity, a light pen can be used as a locator.
3. It is used as a standard pick device with many graphics system.
4. It can be used as stroke input devices.
5. It can be used as valuators
Digitizers:
The digitizer is an operator input device, which contains a large, smooth board (the
appearance is similar to the mechanical drawing board) & an electronic tracking device,
which can be changed over the surface to follow existing lines. The electronic tracking device
contains a switch for the user to record the desire x & y coordinate positions. The
coordinates can be entered into the computer memory or stored or an off-line storage
medium such as magnetic tape.
Advantages:
1. Drawing can easily be changed.
2. It provides the capability of interactive graphics.
Disadvantages:
1. Costly
2. Suitable only for applications which required high-resolution graphics.
Touch Panels:
Touch Panels is a type of display screen that has a touch-sensitive transparent panel covering
the screen. A touch screen registers input when a finger or other object comes in contact
with the screen.
When the wave signals are interrupted by some contact with the screen, that located is
recorded. Touch screens have long been used in military applications.
Image Scanner
It is an input device. The data or text is written on paper. The paper is feeded to scanner. The
paper written information is converted into electronic format; this format is stored in the
computer. The input documents can contain text, handwritten material, picture extra.
By storing the document in a computer document became safe for longer period of time.
The document will be permanently stored for the future. We can change the document
when we need. The document can be printed when needed.
Scanning can be of the black and white or colored picture. On stored picture 2D or 3D
rotations, scaling and other operations can be applied.
Types of image Scanner:
1. Flat Bed Scanner: It resembles a photocopy machine. It has a glass top on its top. Glass
top in further covered using a lid. The document to be scanned is kept on glass plate. The
light is passed underneath side of glass plate. The light is moved left to right. The scanning is
done the line by line. The process is repeated until the complete line is scanned. Within 20-
25 seconds a document of 4" * 6" can be scanned.
2. Hand Held Scanner: It has a number of LED's (Light Emitting Diodes) the LED's are
arranged in the small case. It is called a Hand held Scanner because it can be kept in hand
which performs scanning. For scanning the scanner is moved over document from the top
towards the bottom. Its light is on, while we move it on document. It is dragged very slowly
over document. If dragging of the scanner over the document is not proper, the conversion
will not correct.
3. Tablet: It is also a positioning device and is used to describe a flat surface separate from
the display, on which the user draws with a stylus. There are two types of tablets:
1. Acoustic Tablet: It depends on the use of strip microphones which are mounted
along two adjacent edges of the tablet. The styles have a small piece of ceramic
mounted close to its tip, and at regular intervals, a small spark is generated across
the surface of the ceramic between two electrodes. The microphones pick up the
pulse of sound produced by the spark and two counters record the delay between
creating the spark and receiving the sound. These two delays are proportional to the
stylus distance from the two edges of the tablet where the microphones are
mounted.
2. Electro-acoustic Tablet: In this technique, the writing surface is a sheet of
magnetostrictive material acting as a row of delay lines. An electric pulse travels
through the sheet first horizontally and then vertically and is detected by a sensor in
the stylus. A counter is used to determine the delay from the time the pulse is issued
to the time it is detected; from this value, the position of the stylus can be
determined. The electro-acoustic tablet is quieter in operation than its acoustic
counterpart and is less affected by noise or air movement.
4. Joystick: A joystick consists of a small that is used to steer the screen cursor around. The
distance that the stick is moved in any direction from its center position corresponds to the
screen-cursor movement in that direction. Pressure sensitive joysticks have a non-moveable
stick. Pressure on the stick is measured with strain gauges and converted to the movement
of the cursor in the direction specified.
5. Trackball and spaceball: Trackball is a ball that can be rotated with the fingers to produces
screen-cursor movement potentiometers, attached to the ball, measure the amount and
direction of rotation. Trackballs are after mounted on keyboards, whereas space-ball
provides six degrees of freedom. Spaceballs is used for three-dimensional positioning and
selection operation in virtual reality system, modeling, animation, CAD and other
applications.
Elastic or Rubber Band Techniques
Rubber banding is a popular technique of drawing geometric primitives such as line,
polylines, rectangle, circle and ellipse on the computer screen.
It becomes an integral part and de facto standard with the graphical user interface (GUI) for
drawing and is almost universally accepted by all windows based applications.
The user specifies the line in the usual way by positioning its two endpoints. As we move
from the first endpoint to the second, the program displays a line from the first endpoint to
the cursor position, thus he can see the lie of the line before he finishes positioning it.
The effect is of an elastic line stretched between the first endpoint and the cursor; hence the
name for these techniques.
Consider the different linear structures in fig (a) and fig (d), depending on the position of the
cross-hair cursor. The user may move the cursor to generate more possibilities and select the
one which suits him for a specific application.
When the user is happy with the final position, the pressed button is released, and the line is
drawn between the start and the last position of the cursor.
Example: This is widely followed in MS-Window based Applications like in the case of a
paintbrush drawing package.
Other geometric entities can be drawn in a rubber-band fashion:
- Horizontally or vertically constructed lines
- Rectangles
- Arcs of circles
This technique is very helpful in drawing relatively complex entities such as rectangles and
arcs.
Advantage:
1. It is used for drawing all geometric entities such as line, polygon, circle, rectangle,
ellipse, and other curves.
2. It is easy to understand and implement.
Disadvantage:
1. It requires computational resources like software and CPU speed.
2. Expensive
Dragging
Dragging is used to move an object from one position to another position on the computer
screen. To drag any other object, first, we have to select the object that we want to move on
the screen by holding the mouse button down. As cursor moved on the screen, the object is
also moved with the cursor position. When the cursor reached the desired position, the
button is released.