























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Complete notes study material full notes
Typology: Study notes
1 / 63
This page cannot be seen from the preview
Don't miss anything!
























































(Approved by AICTE, Accredited by NBA, Affiliated to JNTU Kakinada) BHIMAVARAM – 534 202
Overview of Computer Graphics
Computer-Aided Design for engineering and architectural systems etc. Objects maybe displayed in a wireframe outline form. Multi-window environment is also favored for producing various zooming scales and views. Animations are useful for testing performance.
Presentation Graphics To produce illustrations which summarize various kinds of data. Except 2D, 3D graphics are good tools for reporting more complex data.
Computer Art Painting packages are available. With cordless, pressure-sensitive stylus, artists can produce electronic paintings which simulate different brush strokes, brush widths, and colors. Photorealistic techniques, morphing and animations are very useful in commercial art. For films, 24 frames per second are required. For video monitor, 30 frames per second are required.
Entertainment Motion pictures, Music videos, and TV shows, Computer games
Education and Training Training with computer-generated models of specialized systems such as the training of ship captains and aircraft pilots.
Visualization For analyzing scientific, engineering, medical and business data or behavior. Converting data to visual form can help to understand mass volume of data very efficiently.
Image Processing Image processing is to apply techniques to modify or interpret existing pictures. It is widely used in medical applications.
Graphical User Interface Multiple window, icons, menus allow a computer setup to be utilized more efficiently.
Illustration of a shadow-mask CRT
The light emitted by phosphor fades very rapidly, so it needs to redraw the picture repeatedly. There are 2 kinds of redrawing mechanisms: Raster-Scan and Random-Scan
The electron beam is swept across the screen one row at a time from top to bottom. As it moves across each row, the beam intensity is turned on and off to create a pattern of illuminated spots. This scanning process is called refreshing. Each complete scanning of a screen is normally called a frame.
The refreshing rate, called the frame rate , is normally 60 to 80 frames per second, or described as 60 Hz to 80 Hz.
Picture definition is stored in a memory area called the frame buffer. This frame buffer stores the intensity values for all the screen points. Each screen point is called a pixel (picture element).
On black and white systems, the frame buffer storing the values of the pixels is called a bitmap. Each entry in the bitmap is a 1-bit data which determine the on (1) and off (0) of the intensity of the pixel.
On color systems, the frame buffer storing the values of the pixels is called a pixmap (Though nowadays many graphics libraries name it as bitmap too). Each entry in the pixmap occupies a number of bits to represent the color of the pixel. For a true color display, the number of bits for each entry is 24 (8 bits per red/green/blue channel, each channel 2^8 = levels of intensity value, ie. 256 voltage settings for each of the red/green/blue electron guns).
The CRT's electron beam is directed only to the parts of the screen where a picture is to be drawn. The picture definition is stored as a set of line-drawing commands in a refresh display file or a refresh buffer in memory.
Random-scan generally have higher resolution than raster systems and can produce smooth line drawings, however it cannot display realistic shaded scenes.
For a raster display device reads the frame buffer and generates the control signals for the screen, ie. the signals for horizontal scanning and vertical scanning. Most display controllers include a color map (or video look-up table). The major function of a color map is to provide a mapping between the input pixel value to the output color.
On dealing with integer pixel positions, jagged or stair step appearances happen very usually. This distortion of information due to under sampling is called aliasing. A number of ant aliasing methods have been developed to compensate this problem.
One way is to display objects at higher resolution. However there is a limit to how big we can make the frame buffer and still maintaining acceptable refresh rate.
In computer graphics, a hardware or software implementation of a digital differential analyzer (DDA) is used for linear interpolation of variables over an interval between start and end point. DDAs are used for rasterization of lines, triangles and polygons. In its simplest implementation the DDA Line drawing algorithm interpolates values in interval [(xstart, ystart), (xend, yend)] by computing for each xi the equations xi = xi−1+1/m, yi = yi−1 + m, where Δx = xend − xstart and Δy = yend − ystart and m = Δy/Δx.
The dda is a scan conversion line algorithm based on calculating either dy or dx. A line is sampled at unit intervals in one coordinate and corresponding integer values nearest the line path
At succeeding x locations, if p has been smaller than 0, then, we increment p by 2 * vertical height of the line, otherwise we increment p by 2 * (vertical height of the line - horizontal length of the line)
All the computations are on integers. The incremental method is applied to
void BresenhamLine(int x1, int y1, int x2, int y2)
{ int x, y, p, const1, const2; /* initialize variables / p=2(y2-y1)-(x2-x1); const1=2(y2-y1); const2=2((y2- y1)-(x2-x1));
x=x1; y=y1; SetPixel(x,y); while (x<xend) { x++; if (p<0) { p=p+const1; } else { y++; p=p+const2; } SetPixel(x,y); } }
However, unsurprisingly this is not a brilliant solution!
Firstly, the resulting circle has large gaps where the slope approaches the vertical
Secondly, the calculations are not very efficient The square (multiply) operations The square root operation – try really hard to avoid these!
We need a more efficient, more accurate solution.
The first thing we can notice to make our circle drawing algorithm more efficient is that circles
centred at ( 0, 0 ) have eight-way symmetry
Similarly to the case with lines, there is an incremental algorithm for drawing circles – the mid- point circle algorithm In the mid-point circle algorithm we use eight-way symmetry so only ever calculate the points for the top right eighth of a circle, and then use symmetry to get the rest of the points
Assume that we have just plotted point (xk, yk) The next point is a choice between (xk+1, yk) and (xk+1, yk-1)
To ensure things are as efficient as possible we can do all of our calculations incrementally First consider:
pk 1 fcircxk 1 1 , yk 1 1
(^22) 1
2 2 [( x (^) k 1 ) 1 ] yk^1 r pk 1 pk 2 ( xk 1 ) ( y^2 k 1 yk^2 ) ( yk 1 yk ) 1
where yk+1 is either yk or yk- 1 depending on the sign of pk
The first decision variable is given as:
p 0 (^) fcirc ( 1 , r^1
)^22 2 1 ( r^1 r (^54) r
Then if pk < 0 then the next decision variable is given as:
pk 1 pk 2 xk 1 1
If pk > 0 then the decision variable is:
pk 1 pk 2 xk 1 1 2 yk 1
Input radius r and circle centre (xc, yc) , then set the coordinates for the first point on the circumference of a circle centred on the origin as:
( x 0 , y 0 ) ( 0 , r )
p (^) 0 54 r
pk 1 pk 2 xk 1 1
Otherwise the next point along the circle is (xk+1, yk-1) and: pk 1 pk 2 xk 1 1 2 yk 1 Determine symmetry points in the other seven octants Move each calculated pixel position (x, y) onto the circular path centred at (xc, yc) to plot the coordinate values:
x x xc y y yc Repeat steps 3 to 5 until x >= y
To see the mid-point circle algorithm in action lets use it to draw a circle centred at (0,0) with radius 10
void BoundaryFill(int x, int y, COLOR fill, COLOR boundary)
{ COLOR current; current=GetPixel(x,y); if (current<>boundary) and (current<>fill) then { SetPixel(x,y,fill); BoundaryFill(x+1,y,fill,boundary); BoundaryFill(x-1,y,fill,boundary); BoundaryFill(x,y+1,fill,boundary); BoundaryFill(x,y-1,fill,boundary); } }
void BoundaryFill(int x, int y, COLOR fill, COLOR old_color) { if (GetPixel(x,y)== old_color) { SetPixel(x,y,fill); BoundaryFill(x+1,y,fill,boundary); BoundaryFill(x-1,y,fill,boundary); BoundaryFill(x,y+1,fill,boundary); BoundaryFill(x,y-1,fill,boundary); }
Translation of vertex (20,10):
x' 1 0 5 20 1* 20 0 *10 5 1 25 y' (^) = 0 1 10 10 = 0 * 20 110 10 *1 (^) = 20
1 0 0 1 1 0 * 20^ 0 10^ 11^1
The resultant coordinates of the triangle vertices are (15,30), (15,20), and (25,20) respectively.
Exercise: translate a triangle with vertices at original coordinates (10,25), (5,10), (20,10) by tx=15, ty=5. Roughly plot the original and resultant triangles.
3.1.2 Rotation About the Origin
To rotate an object about the origin (0,0), we specify the rotation angle ?. Positive and negative values for the rotation angle define counterclockwise and clockwise rotations respectively. The followings is the computation of this rotation for a point:
x' = x cos? - y sin? y' = x sin? + y cos?
Alternatively, this rotation can also be specified by the following transformation matrix: cos sin 0 sin cos^0
0 0 1
Then we can rewrite the formula as:
x' cos sin 0 x y' =^ sin^ cos^0 y
1 0 0 1 1
For example, to rotate a triange about the origin with vertices at original coordinates (10,20), (10,10), (20,10) by 30 degrees, we compute as followings:
cos sin 0 cos 30 sin 30 0 0.866 0.5 0 sin cos 0 = sin 30 cos 30 0 = 0.5 0.866 0
0 0 1 0 0 1 0 0 1
Rotation of vertex (10,20):
x' 0.866 0.5 0 10 0.866 *10 ( 0.5) * 20 0 *1 1. y' =^ 0.5^ 0.866^0 20 =^ 0.5 *10^ 0.866 * 20^ 0 *1^ =^ 22. 1 0 0 1 1 0 10 0 * 20 11 1
2
Rotation of vertex (10,10):
x' 0.866 0.5 0 10 0.866 *10 ( 0.5) *10 0 *1 3. y' (^) = 0.5 0.866 0 10 = 0.5 *10 0.866 *10 (^0) *1 = 13. 1 0 0 1 1 0 *10 0 10 11 1
Rotation of vertex (20,10):
x' 0.866 0.5 0 20 0.866 * 20 ( 0.5) *10 0 *1 12. y' =^ 0.5^ 0.866^0 10 =^ 0.5 * 20^ 0.866 *10^ 0 *1^ =^ 18. 1 0 0 1 1 0 * 20 0 10 11 1
The resultant coordinates of the triangle vertices are (-1.34,22.32), (3.6,13.66), and (12.32,18.66) respectively.
Exercise: Rotate a triange with vertices at original coordinates (10,20), (5,10), (20,10) by 45 degrees. Roughly plot the original and resultant triangles.
We scale a 2D object with respect to the origin by setting the scaling factors sx and sy, which are multiplied to the original vertex coordinate positions (x,y):
x' = x * sx, y' = y * sy
Alternatively, this scaling can also be specified by the following transformation matrix:
sx 0 0 Then we can rewrite the formula as:
x' sx y' = 0
1 0
0 0 s y 0
0 1
0 0 x s (^) y 0 y
0 1 1
For example, to scale a triange with respect to the origin, with vertices at original coordinates (10,20), (10,10), (20,10) by sx=2, sy=1.5, we compute as followings:
Scaling of vertex (10,20):
x' 2 0 0 10 2 *10 0 * 20 0 *1 20 y' =^0 1.5^0 20 =^ 0 *10^ 1.5 * 20^ 0 *1^ =^30
1 0 0 1 1 0 10^ 0 * 20^ 11^1
3
Example: Rotate a triangle with vertices (10,20), (10,10), (20,10) about the origin by 30 degrees and then translate it by tx=5, ty=10,
We compute the rotation matrix:
cos 30 sin 30 0 0.866 0.5 0 B = sin 30 (^) cos 30 0 = 0.5 (^) 0.866 0
0 0 1 0 0 1 And we compute the translation matrix:
1 0 5 A= 0 1 10
(^0 0 ) Then, we compute M=A·B
1 0 5 0.866 0.5 0 M= 0 1 10 ·^ 0.5^ 0.866 (^0)
0 0 1 0 0 1 1* 0.866 0 * 0.5 5 * 0 1* 0.5 0 * 0.866 5 * 0 1* 0 0 * 0 5 * M= 0 * 0.866 1* 0.5 10 * 0 0 * 0.5 1* 0.866 10 * 0 0 * 0 1* 0 10 *
(^0) * 0.866 0 * 0.5 1* 0 0 * 0.5 0 * 0.866 1* 0 0 * 0 0 * 0 1* 0.866 0.5 5 M= 0.5 0.866 10
0 0 1
Then, we compute the transformations of the 3 vertices: Transformation of vertex (10,20):
x' 0.866 0.5 5 10 0.866 *10 ( 0.5) * 20 5 *1 3. y' = 0.5 0.866 10 20 = 0.5 *10 0.866 * 20 10 *1 = 32. 1 0 0 1 1 0 10 0 * 20 11 1
Transformation of vertex (10,10):
x' 0.866 0.5 5 10 0.866 *10 ( 0.5) *10 5 *1 8. y' =^ 0.5^ 0.866^10 10 =^ 0.5 *10^ 0.866 *10^ 10 *1^ =^ 23. 1 0 0 1 1 0 *10 0 10 11 1
5
Transformation of vertex (20,10):
x' 0.866 0.5 5 20 0.866 * 20 ( 0.5) *10 5 *1 17. y' (^) = 0.5 0.866 10 10 = 0.5 * 20 0.866 *10 10 *1 (^) = 28. 1 0 0 1 1 0 * 20 0 10 11 1
The resultant coordinates of the triangle vertices are (3.66,32.32), (8.66,23.66), and (17.32,28.66) respectively.
II. Matrix multiplication may not be commutative :
A·B may not equal to B·A
This means that if we want to translate and rotate an object, we must be careful about the order in which the composite matrix is evaluated. Using the previous example, if you compute C' = (A·B)·C, you are rotating the triangle with B first, then translate it with A, but if you compute C' = (B·A)·C, you are translating it with A first, then rotate it with B. The result is different.
Exercise: Translate a triangle with vertices (10,20), (10,10), (20,10) by tx=5, ty=10 and then rotate it about the origin by 30 degrees. Compare the result with the one obtained previously: (3.66,32.32), (8.66,23.66), and (17.32,28.66) by plotting the original triangle together with these 2 results.
Translations
By common sense, if we translate a shape with 2 successive translation vectors: (tx1, ty1) and (tx2, ty2), it is equal to a single translation of (tx1+ tx2, ty1+ t (^) y2). This additive property can be demonstrated by composite transformation matrix:
1 0 t (^) x1 1 0 t (^) x 2 11 0 * 0 t (^) x1 * 0 1 0 0 1 t (^) x1 * 0 1 t (^) x 2 0 * t (^) y 2 t (^) x1 * 0 1 t (^) y1 · 0 1 t (^) y2 = (^) 0 1 1 0 t (^) y1 * 0 0 * 0 11 t (^) y1 * 0 0 * t (^) x 2 1 t (^) y 2 t (^) y1 *
0 0 1 0 0 1 0 1 0 * 0 1 0 (^) 0 * 0 0 1 1 0 0 * t (^) x 2 0 * tu 2 1* 1 0 t^ x1 t^ x 2
= 01 t^ y1 t^ y 2 0 0 1
This demonstrates that 2 successive translations are additive.
6