SlideShare a Scribd company logo
1 of 24
Download to read offline
http://www.tutorialspoint.com/computer_graphics/computer_graphics_quick_guide.htm
Copyright © tutorialspoint.com
COMPUTER GRAPHICS - QUICK GUIDECOMPUTER GRAPHICS - QUICK GUIDE
COMPUTER GRAPHICS - BASICSCOMPUTER GRAPHICS - BASICS
Computer graphics is an art of drawing pictures on computer screens with the help of
programming. It involves computations, creation, and manipulation of data. In other words, we can
say that computer graphics is a rendering tool for the generation and manipulation of images.
Cathode Ray Tube
The primary output device in a graphical system is the video monitor. The main element of a video
monitor is the Cathode Ray Tube CRT, shown in the following illustration.
The operation of CRT is very simple −
The electron gun emits a beam of electrons cathoderays.
The electron beam passes through focusing and deflection systems that direct it towards
specified positions on the phosphor-coated screen.
When the beam hits the screen, the phosphor emits a small spot of light at each position
contacted by the electron beam.
It redraws the picture by directing the electron beam back over the same screen points
quickly.
There are two ways RandomscanandRasterscan by which we can display an object on the screen.
Raster Scan
In a raster scan system, the electron beam is swept across the screen, one row at a time from top
to bottom. As the electron beam moves across each row, the beam intensity is turned on and off to
create a pattern of illuminated spots.
Picture definition is stored in memory area called the Refresh Buffer or Frame Buffer. This
memory area holds the set of intensity values for all the screen points. Stored intensity values are
then retrieved from the refresh buffer and “painted” on the screen one row scanline at a time as
shown in the following illustration.
Each screen point is referred to as a pixel pictureelement or pel. At the end of each scan line, the
electron beam returns to the left side of the screen to begin displaying the next scan line.
Random Scan VectorScan
In this technique, the electron beam is directed only to the part of the screen where the picture is
to be drawn rather than scanning from left to right and top to bottom as in raster scan. It is also
called vector display, stroke-writing display, or calligraphic display.
Picture definition is stored as a set of line-drawing commands in an area of memory referred to as
the refresh display file. To display a specified picture, the system cycles through the set of
commands in the display file, drawing each component line in turn. After all the line-drawing
commands are processed, the system cycles back to the first line command in the list.
Random-scan displays are designed to draw all the component lines of a picture 30 to 60 times
each second.
Application of Computer Graphics
Computer Graphics has numerous applications, some of which are listed below −
Computer graphics user interfaces GUIs − A graphic, mouse-oriented paradigm which
allows the user to interact with a computer.
Business presentation graphics − "A picture is worth a thousand words".
Cartography − Drawing maps.
Weather Maps − Real-time mapping, symbolic representations.
Satellite Imaging − Geodesic images.
Photo Enhancement − Sharpening blurred photos.
Medical imaging − MRIs, CAT scans, etc. - Non-invasive internal examination.
Engineering drawings − mechanical, electrical, civil, etc. - Replacing the blueprints of the
past.
Typography − The use of character images in publishing - replacing the hard type of the
past.
Architecture − Construction plans, exterior sketches - replacing the blueprints and hand
drawings of the past.
Art − Computers provide a new medium for artists.
Training − Flight simulators, computer aided instruction, etc.
Entertainment − Movies and games.
Simulation and modeling − Replacing physical modeling and enactments
LINE GENERATION ALGORITHMLINE GENERATION ALGORITHM
A line connects two points. It is a basic element in graphics. To draw a line, you need two points
between which you can draw a line. In the following three algorithms, we refer the one point of line
as X0, Y0 and the second point of line as X1, Y1.
DDA Algorithm
Digital Differential Analyzer DDA algorithm is the simple line generation algorithm which is
explained step by step here.
Step 1 − Get the input of two end points (X0, Y0) and (X1, Y1).
Step 2 − Calculate the difference between two end points.
dx = X1 - X0
dy = Y1 - Y0
Step 3 − Based on the calculated difference in step-2, you need to identify the number of steps to
put pixel. If dx > dy, then you need more steps in x coordinate; otherwise in y coordinate.
if (dx > dy)
Steps = absolute(dx);
else
Steps = absolute(dy);
Step 4 − Calculate the increment in x coordinate and y coordinate.
Xincrement = dx / (float) steps;
Yincrement = dy / (float) steps;
Step 5 − Put the pixel by successfully incrementing x and y coordinates accordingly and complete
the drawing of the line.
for(int v=0; v < Steps; v++)
{
x = x + Xincrement;
y = y + Yincrement;
putpixel(x,y);
}
Bresenham’s Line Generation
The Bresenham algorithm is another incremental scan conversion algorithm. The big advantage
of this algorithm is that, it uses only integer calculations. Moving across the x axis in unit intervals
and at each step choose between two different y coordinates.
For example, as shown in the following illustration, from position 2, 3 you need to choose between
3, 3 and 3, 4. You would like the point that is closer to the original line.
At sample position Xk + 1, the vertical separations from the mathematical line are labelled as dupper
and dlower.
From the above illustration, the y coordinate on the mathematical line at xk + 1 is −
Y = m$Xk$ + 1 + b
So, dupper and dlower are given as follows −
dlower = y − yk
= m(Xk + 1) + b − Yk
and
dupper = (yk + 1) − y
= Yk + 1 − m(Xk + 1) − b
You can use these to make a simple decision about which pixel is closer to the mathematical line.
This simple decision is based on the difference between the two pixel positions.
dlower − dupper = 2m(xk + 1) − 2yk + 2b − 1
Let us substitute m with dy/dx where dx and dy are the differences between the end-points.
dx(dlower − dupper) = dx(2
dy
dx(xk + 1) − 2yk + 2b − 1)
= 2dy. xk − 2dx. yk + 2dy + 2dx(2b − 1)
= 2dy. xk − 2dx. yk + C
So, a decision parameter Pk for the kth step along a line is given by −
pk = dx(dlower − dupper)
= 2dy. xk − 2dx. yk + C
The sign of the decision parameter Pk is the same as that of dlower − dupper.
If pk is negative, then choose the lower pixel, otherwise choose the upper pixel.
Remember, the coordinate changes occur along the x axis in unit steps, so you can do everything
with integer calculations. At step k+1, the decision parameter is given as −
pk+1 = 2dy. xk+1 − 2dx. yk+1 + C
Subtracting pk from this we get −
pk+1 − pk = 2dy(xk+1 − xk) − 2dx(yk+1 − yk)
But, xk+1 is the same as xk+1. So −
pk+1 = pk + 2dy − 2dx(yk+1 − yk)
Where, Y_{k+1} – Y_{k} is either 0 or 1 depending on the sign of P_{k}.
The first decision parameter p_{0} is evaluated at (x_{0}, y_{0}) is given as −
p_{0} = 2dy - dx
Now, keeping in mind all the above points and calculations, here is the Bresenham algorithm for
slope m < 1 −
Step 1 − Input the two end-points of line, storing the left end-point in (x_{0}, y_{0}).
Step 2 − Plot the point (x_{0}, y_{0}).
Step 3 − Calculate the constants dx, dy, 2dy, and 2dy – 2dx and get the first value for the decision
parameter as −
p_{0} = 2dy - dx
Step 4 − At each X_{k} along the line, starting at k = 0, perform the following test −
If p_{k} < 0, the next point to plot is (x_{k}+1, y_{k}) and
p_{k+1} = p_{k} + 2dy Otherwise,
p_{k+1} = p_{k} + 2dy - 2dx
Step 5 − Repeat step 4 dx – 1 times.
For m > 1, find out whether you need to increment x while incrementing y each time.
After solving, the equation for decision parameter P_{k} will be very similar, just the x and y in the
equation gets interchanged.
Mid-Point Algorithm
Mid-point algorithm is due to Bresenham which was modified by Pitteway and Van Aken. Assume
that you have already put the point P at x, y coordinate and the slope of the line is 0 ≤ k ≤ 1 as
shown in the following illustration.
Now you need to decide whether to put the next point at E or N. This can be chosen by identifying
the intersection point Q closest to the point N or E. If the intersection point Q is closest to the point
N then N is considered as the next point; otherwise E.
To determine that, first calculate the mid-point Mx+1, y + ½. If the intersection point Q of the line
with the vertical line connecting E and N is below M, then take E as the next point; otherwise take N
as the next point.
In order to check this, we need to consider the implicit equation −
Fx,y = mx + b - y
For positive m at any given X,
If y is on the line, then Fx, y = 0
If y is above the line, then Fx, y < 0
If y is below the line, then Fx, y > 0
This can be decided by the decision parameter d.
If d <= 0, then NX+1, Y is to be chosen as next pixel.
If d > 0, then SX+1, Y-1 is to be chosen as the next pixel.
Algorithm
Step 1 − Get the coordinates of the center of the circle and radius, and store them in x, y, and R
respectively. Set P=0 and Q=R.
Step 2 − Set decision parameter D = 3 – 2R.
Step 3 − Repeat through step-8 while X < Y.
Step 4 − Call Draw Circle X, Y, P, Q.
Step 5 − Increment the value of P.
Step 6 − If D < 0 then D = D + 4x + 6.
Step 7 − Else Set Y = Y + 1, D = D + 4X-Y + 10.
Step 8 − Call Draw Circle X, Y, P, Q.
Draw Circle Method(X, Y, P, Q).
Call Putpixel (X + P, Y + Q).
Call Putpixel (X - P, Y + Q).
Call Putpixel (X + P, Y - Q).
Call Putpixel (X - P, Y - Q).
Call Putpixel (X + Q, Y + X).
Call Putpixel (X - Q, Y + X).
Call Putpixel (X + Q, Y - X).
Call Putpixel (X - Q, Y - X).
Mid Point Algorithm
Step 1 − Input radius r and circle center (x_{c,} y_{c}) and obtain the first point on the
circumference of the circle centered on the origin as
(x0, y0) = (0, r)
Step 2 − Calculate the initial value of decision parameter as
P_{0} = 5/4 – r See the following description for simplification of this equation.
f(x, y) = x2 + y2 - r2 = 0
f(xi - 1/2 + e, yi + 1)
= (xi - 1/2 + e)2 + (yi + 1)2 - r2
= (xi- 1/2)2 + (yi + 1)2 - r2 + 2(xi - 1/2)e + e2
= f(xi - 1/2, yi + 1) + 2(xi - 1/2)e + e2 = 0
Let di = f(xi - 1/2, yi + 1) = -2(xi - 1/2)e - e2
Thus,
If e < 0 then di > 0 so choose point S = (xi - 1, yi + 1).
di+1 = f(xi - 1 - 1/2, yi + 1 + 1) = ((xi - 1/2) - 1)2 + ((yi + 1) + 1)2 - r2
= di - 2(xi - 1) + 2(yi + 1) + 1
= di + 2(yi + 1 - xi + 1) + 1
If e >= 0 then di <= 0 so choose point T = (xi, yi + 1)
di+1 = f(xi - 1/2, yi + 1 + 1)
= di + 2yi+1 + 1
The initial value of di is
d0 = f(r - 1/2, 0 + 1) = (r - 1/2)2 + 12 - r2
= 5/4 - r {1-r can be used if r is an integer}
When point S = (xi - 1, yi + 1) is chosen then
di+1 = di + -2xi+1 + 2yi+1 + 1
When point T = (xi, yi + 1) is chosen then
di+1 = di + 2yi+1 + 1
Step 3 − At each X_{K} position starting at K=0, perform the following test −
If PK < 0 then next point on circle (0,0) is (XK+1,YK) and
PK+1 = PK + 2XK+1 + 1
Else
PK+1 = PK + 2XK+1 + 1 – 2YK+1
Where, 2XK+1 = 2XK+2 and 2YK+1 = 2YK-2.
Step 4 − Determine the symmetry points in other seven octants.
Step 5 − Move each calculate pixel position X, Y onto the circular path centered on (X_{C,}
Y_{C}) and plot the coordinate values.
X = X + XC, Y = Y + YC
Step 6 − Repeat step-3 through 5 until X >= Y.
POLYGON FILLING ALGORITHMPOLYGON FILLING ALGORITHM
Polygon is an ordered list of vertices as shown in the following figure. For filling polygons with
particular colors, you need to determine the pixels falling on the border of the polygon and those
which fall inside the polygon. In this chapter, we will see how we can fill polygons using different
techniques.
Scan Line Algorithm
This algorithm works by intersecting scanline with polygon edges and fills the polygon between
pairs of intersections. The following steps depict how this algorithm works.
Step 1 − Find out the Ymin and Ymax from the given polygon.
Step 2 − ScanLine intersects with each edge of the polygon from Ymin to Ymax. Name each
intersection point of the polygon. As per the figure shown above, they are named as p0, p1, p2, p3.
Step 3 − Sort the intersection point in the increasing order of X coordinate i.e. p0, p1, p1, p2, and
p2, p3.
Step 4 − Fill all those pair of coordinates that are inside polygons and ignore the alternate pairs.
Flood Fill Algorithm
Sometimes we come across an object where we want to fill the area and its boundary with
different colors. We can paint such objects with a specified interior color instead of searching for
particular boundary color as in boundary filling algorithm.
Instead of relying on the boundary of the object, it relies on the fill color. In other words, it replaces
the interior color of the object with the fill color. When no more pixels of the original interior color
exist, the algorithm is completed.
Once again, this algorithm relies on the Four-connect or Eight-connect method of filling in the
pixels. But instead of looking for the boundary color, it is looking for all adjacent pixels that are a
part of the interior.
Boundary Fill Algorithm
The boundary fill algorithm works as its name. This algorithm picks a point inside an object and
starts to fill until it hits the boundary of the object. The color of the boundary and the color that we
fill should be different for this algorithm to work.
In this algorithm, we assume that color of the boundary is same for the entire object. The boundary
fill algorithm can be implemented by 4-connected pixels or 8-connected pixels.
4-Connected Polygon
In this technique 4-connected pixels are used as shown in the figure. We are putting the pixels
above, below, to the right, and to the left side of the current pixels and this process will continue
until we find a boundary with different color.
Algorithm
Step 1 − Initialize the value of seed point seedx, seedy, fcolor and dcol.
Step 2 − Define the boundary values of the polygon.
Step 3 − Check if the current seed point is of default color, then repeat the steps 4 and 5 till the
boundary pixels reached.
If getpixel(x, y) = dcol then repeat step 4 and 5
Step 4 − Change the default color with the fill color at the seed point.
setPixel(seedx, seedy, fcol)
Step 5 − Recursively follow the procedure with four neighborhood points.
FloodFill (seedx – 1, seedy, fcol, dcol)
FloodFill (seedx + 1, seedy, fcol, dcol)
FloodFill (seedx, seedy - 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol)
Step 6 − Exit
There is a problem with this technique. Consider the case as shown below where we tried to fill the
entire region. Here, the image is filled only partially. In such cases, 4-connected pixels technique
cannot be used.
8-Connected Polygon
In this technique 8-connected pixels are used as shown in the figure. We are putting pixels above,
below, right and left side of the current pixels as we were doing in 4-connected technique.
In addition to this, we are also putting pixels in diagonals so that entire area of the current pixel is
covered. This process will continue until we find a boundary with different color.
Algorithm
Step 1 − Initialize the value of seed point seedx, seedy, fcolor and dcol.
Step 2 − Define the boundary values of the polygon.
Step 3 − Check if the current seed point is of default color then repeat the steps 4 and 5 till the
boundary pixels reached
If getpixel(x,y) = dcol then repeat step 4 and 5
Step 4 − Change the default color with the fill color at the seed point.
setPixel(seedx, seedy, fcol)
Step 5 − Recursively follow the procedure with four neighbourhood points
FloodFill (seedx – 1, seedy, fcol, dcol)
FloodFill (seedx + 1, seedy, fcol, dcol)
FloodFill (seedx, seedy - 1, fcol, dcol)
FloodFill (seedx, seedy + 1, fcol, dcol)
FloodFill (seedx – 1, seedy + 1, fcol, dcol)
FloodFill (seedx + 1, seedy + 1, fcol, dcol)
FloodFill (seedx + 1, seedy - 1, fcol, dcol)
FloodFill (seedx – 1, seedy - 1, fcol, dcol)
Step 6 − Exit
The 4-connected pixel technique failed to fill the area as marked in the following figure which
won’t happen with the 8-connected technique.
Inside-outside Test
This method is also known as counting number method. While filling an object, we often need to
identify whether particular point is inside the object or outside it. There are two methods by which
we can identify whether particular point is inside an object or outside.
Odd-Even Rule
Nonzero winding number rule
Odd-Even Rule
In this technique, we count the edge crossing along the line from any point x, y to infinity. If the
number of interactions is odd then the point x, y is an interior point. If the number of interactions is
even then point x, y is an exterior point. Here is the example to give you the clear idea −
From the above figure, we can see that from the point x, y, the number of interactions point on the
left side is 5 and on the right side is 3. So the total number of interaction point is 8, which is odd.
Hence, the point is considered within the object.
Nonzero Winding Number Rule
This method is also used with the simple polygons to test the given point is interior or not. It can be
simply understood with the help of a pin and a rubber band. Fix up the pin on one of the edge of
the polygon and tie-up the rubber band in it and then stretch the rubber band along the edges of
the polygon.
When all the edges of the polygon are covered by the rubber band, check out the pin which has
been fixed up at the point to be test. If we find at least one wind at the point consider it within the
polygon, else we can say that the point is not inside the polygon.
In another alternative method, give directions to all the edges of the polygon. Draw a scan line
from the point to be test towards the left most of X direction.
Give the value 1 to all the edges which are going to upward direction and all other -1 as
direction values.
Check the edge direction values from which the scan line is passing and sum up them.
If the total sum of this direction value is non-zero, then this point to be tested is an interior
point, otherwise it is an exterior point.
In the above figure, we sum up the direction values from which the scan line is passing then
the total is 1 – 1 + 1 = 1; which is non-zero. So the point is said to be an interior point.
VIEWING & CLIPPINGVIEWING & 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, Y is within the
given window or not; and decides whether we will use the minimum and maximum coordinates of
the window.
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.
CS3162 Introduction to Computer Graphics
Helena Wong, 2000
1
4. Two Dimensional Transformations
In many applications, changes in orientations, size, and shape are accomplished with geometric transformations
that alter the coordinate descriptions of objects.
Basic geometric transformations are:
Translation
Rotation
Scaling
Other transformations:
Reflection
Shear
4.1 Basic Transformations
Translation
We translate a 2D point by adding translation distances, tx and ty, to the original coordinate position
(x,y):
x' = x + tx, y' = y + ty
Alternatively, translation can also be specified by the following transformation matrix:










100
t10
t01
y
x
Then we can rewrite the formula as:










1
'y
'x
=










100
t10
t01
y
x










1
y
x
For example, to translate a triangle with vertices at original coordinates (10,20), (10,10), (20,10) by
tx=5, ty=10, we compute as followings:
Translation of vertex (10,20):










1
'y
'x
=










100
1010
501










1
20
10
=










++
++
++
1*120*010*0
1*1020*110*0
1*520*010*1
=










1
30
15
Translation of vertex (10,10):










1
'y
'x
=










100
1010
501










1
10
10
=










++
++
++
1*110*010*0
1*1010*110*0
1*510*010*1
=










1
20
15
CS3162 Introduction to Computer Graphics
Helena Wong, 2000
2
Translation of vertex (20,10):










1
'y
'x
=










100
1010
501










1
10
20
=










++
++
++
1*110*020*0
1*1010*120*0
1*510*020*1
=










1
20
25
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.
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:










θθ
θ−θ
100
0cossin
0sincos
Then we can rewrite the formula as:










1
'y
'x
=










θθ
θ−θ
100
0cossin
0sincos










1
y
x
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:










θθ
θ−θ
100
0cossin
0sincos
=









 −
100
030cos30sin
030sin30cos
=









 −
100
0866.05.0
05.0866.0
Rotation of vertex (10,20):










1
'y
'x
=









 −
100
0866.05.0
05.0866.0










1
20
10
=










++
++
+−+
1*120*010*0
1*020*866.010*5.0
1*020*)5.0(10*866.0
=









−
1
32.22
34.1
CS3162 Introduction to Computer Graphics
Helena Wong, 2000
3
Rotation of vertex (10,10):










1
'y
'x
=









 −
100
0866.05.0
05.0866.0










1
10
10
=










++
++
+−+
1*110*010*0
1*010*866.010*5.0
1*010*)5.0(10*866.0
=










1
66.13
66.3
Rotation of vertex (20,10):










1
'y
'x
=









 −
100
0866.05.0
05.0866.0










1
10
20
=










++
++
+−+
1*110*020*0
1*010*866.020*5.0
1*010*)5.0(20*866.0
=










1
66.18
32.12
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.
Scaling With Respect to the Origin
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:










100
0s0
00s
y
x
Then we can rewrite the formula as:










1
'y
'x
=










100
0s0
00s
y
x










1
y
x
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):










1
'y
'x
=










100
05.10
002










1
20
10
=










++
++
++
1*120*010*0
1*020*5.110*0
1*020*010*2
=










1
30
20
CS3162 Introduction to Computer Graphics
Helena Wong, 2000
4
Scaling of vertex (10,10):










1
'y
'x
=










100
05.10
002










1
10
10
=










++
++
++
1*110*010*0
1*010*5.110*0
1*010*010*2
=










1
15
20
Scaling of vertex (20,10):










1
'y
'x
=










100
05.10
002










1
10
20
=










++
++
++
1*110*020*0
1*010*5.120*0
1*010*020*2
=










1
15
40
The resultant coordinates of the triangle vertices are (20,30), (20,15), and (40,15) respectively.
Exercise: Scale a triange with vertices at original coordinates (10,25), (5,10), (20,10) by sx=1.5,
sy=2, with respect to the origin. Roughly plot the original and resultant triangles.
4.2 Concatenation Properties of Composite Matrix
I. Matrix multiplication is associative:
A·B·C = (A·B) ·C = A·(B·C)
Therefore, we can evaluate matrix products using these associative grouping.
For example, we have a triangle, we want to rotate it with the matrix B, then we translate it with
matrix A.
Then, for a vertex of that triangle represented as C, we compute its transformation as:
C'=A·(B·C)
But we can also change the computation method as:
C' = (A·B)·C
The advantage of computing it using C' = (A·B)·C instead of C'=A·(B·C) is that, for computing
the 3 vertices of the triangle, C1, C2, C3, the computation time is shortened:
Using C'=A·(B·C):
1. compute B · C1 and put the result into I1
2. compute A · I1 and put the result into C1
'
3. compute B · C2 and put the result into I2
4. compute A · I2 and put the result into C2
'
5. compute B · C3 and put the result into I3
6. compute A · I3 and put the result into C3
'
Using C' = (A·B)·C:
1. compute A · B and put the result into M
2. compute M · C1 and put the result into C1
'
3. compute M · C2 and put the result into C2
'
4. compute M · C3 and put the result into C3
'
CS3162 Introduction to Computer Graphics
Helena Wong, 2000
5
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:
B =









 −
100
030cos30sin
030sin30cos
=









 −
100
0866.05.0
05.0866.0
And we compute the translation matrix:
A=










100
1010
501
Then, we compute M=A·B
M=










100
1010
501
·









 −
100
0866.05.0
05.0866.0
M=










++++−++
++++−++
++++−++
1*10*00*00*1866.0*05.0*00*15.0*0866.0*0
1*100*10*00*10866.0*15.0*00*105.0*1866.0*0
1*50*00*10*5866.0*05.0*10*55.0*0866.0*1
M=









 −
100
10866.05.0
55.0866.0
Then, we compute the transformations of the 3 vertices:
Transformation of vertex (10,20):










1
'y
'x
=









 −
100
10866.05.0
55.0866.0










1
20
10
=










++
++
+−+
1*120*010*0
1*1020*866.010*5.0
1*520*)5.0(10*866.0
=










1
32.32
66.3
Transformation of vertex (10,10):










1
'y
'x
=









 −
100
10866.05.0
55.0866.0










1
10
10
=










++
++
+−+
1*110*010*0
1*1010*866.010*5.0
1*510*)5.0(10*866.0
=










1
66.23
66.8
CS3162 Introduction to Computer Graphics
Helena Wong, 2000
6
Transformation of vertex (20,10):










1
'y
'x
=









 −
100
10866.05.0
55.0866.0










1
10
20
=










++
++
+−+
1*110*020*0
1*1010*866.020*5.0
1*510*)5.0(20*866.0
=










1
66.28
32.17
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.
4.3 Composite Transformation Matrix
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+ ty2).
This additive property can be demonstrated by composite transformation matrix:










100
t10
t01
1y
1x
·










100
t10
t01
2y
2x
=










++++++
++++++
++++++
1*1t*0t*00*11*00*00*10*01*0
1*tt*1t*00*t1*10*00*t0*11*0
1*tt*0t*10*t1*00*10*t0*01*1
2u2x
1y2y2x1y1y
1x2y2x1x1x
=










+
+
100
tt10
tt01
2y1y
2x1x
This demonstrates that 2 successive translations are additive.
CS3162 Introduction to Computer Graphics
Helena Wong, 2000
7
Rotations
By common sense, if we rotate a shape with 2 successive rotation angles: ? and a, about the origin, it
is equal to rotating the shape once by an angle ? + a about the origin.
Similarly, this additive property can be demonstrated by composite transformation matrix:










θθ
θ−θ
100
0cossin
0sincos
·










αα
α−α
100
0cossin
0sincos
=










+++α+α−+α+α
+θ+θ+αθ+α−θ+αθ+αθ
+θ−+θ+αθ−+α−θ+αθ−+αθ
1*10*00*00*1cos*0)sin(*00*1sin*0cos*0
1*00*cos0*sin0*0cos*cos)sin(*sin0*0sin*coscossin
1*00*)sin(0*cos0*0cos*)sin()sin(*cos0*0sin*)sin(coscos
=










αθ+αθ−αθ+αθ
αθ+αθ−αθ−αθ
100
0coscossinsinsincoscossin
0)cossinsin(cossinsincoscos
=










α+θα+θ
α+θ−α+θ
100
0)cos()sin(
0)sin()cos(
This demonstrates that 2 successive rotations are additive.
Scalings With Respect to the Origin
By common sense, if we scale a shape with 2 successive scaling factor: (sx1, sy1) and (sx2, sy2), with
respect to the origin, it is equal to a single scaling of (sx1* sx2, sy1* sy2) with respect to the origin.
This multiplicative property can be demonstrated by composite transformation matrix:










100
0s0
00s
1y
1x
·










100
0s0
00s
2y
2x
=










++++++
++++++
++++++
1*10*00*00*1s*00*00*10*0s*0
1*00*s0*00*0s*s0*00*00*ss*0
1*00*00*s0*0s*00*s0*00*0s*s
2y2x
1y2y1y1y2x
1x2y1x2x1x
=










100
0s*s0
00s*s
2y1y
2x1x
This demonstrates that 2 successive scalings with respect to the origin are multiplicative.
CS3162 Introduction to Computer Graphics
Helena Wong, 2000
8
General Pivot-Point Rotation
Rotation about an arbitrary pivot point is not as simple as rotation about the origin. The procedure of
rotation about an arbitrary pivot point is:
1. Translate the object so that the pivot-point position is moved to the origin.
2. Rotate the object about the origin.
3. Translate the object so that the pivot point is returned to its original position.
The corresponding composite transformation matrix is:










100
y10
x01
r
r










θθ
θ−θ
100
0cossin
0sincos










−
−
100
y10
x01
r
r
=










θθ
θ−θ
100
ycossin
xsincos
r
r










−
−
100
y10
x01
r
r
=










+θ−θ−θθ
+θ+θ−θ−θ
100
ycosysinxcossin
xsinycosxsincos
rrr
rrr
General Fixed-Point Scaling
Scaling with respect to an arbitrary fixed point is not as simple as scaling with respect to the origin.
The procedure of scaling with respect to an arbitrary fixed point is:
1. Translate the object so that the fixed point coincides with the origin.
2. Scale the object with respect to the origin.
3. Use the inverse translation of step 1 to return the object to its original position.
CS3162 Introduction to Computer Graphics
Helena Wong, 2000
9
The corresponding composite transformation matrix is:










100
y10
x01
f
f










100
0s0
00s
y
x










−
−
100
y10
x01
f
f
=










−
−
100
)s1(ys0
)s1(x0s
yfy
xfx
General Scaling Direction
Scaling along an arbitrary direction is not as simple as scaling along the x-y axis. The procedure of
scaling along and normal to an arbitrary direction (s1 and s2), with respect to the origin, is:
1. Rotate the object so that the directions for s1 and s2 coincide with the x and y axes respectively.
2. Scale the object with respect to the origin using (s1, s2).
3. Use an opposite rotation to return points to their original orientation.
The corresponding composite transformation matrix is:










θ−θ−
θ−−θ−
100
0)cos()sin(
0)sin()cos(










100
0s0
00s
2
1










θθ
θ−θ
100
0cossin
0sincos
4.4 Other Transformations
Reflection
Reflection about the x axis:










1
'y
'x
=










−
100
010
001










1
y
x
ie. x'=x; y'=-y
Reflection about the y axis:










1
'y
'x
=









−
100
010
001










1
y
x
ie. x'=-x; y'=y
CS3162 Introduction to Computer Graphics
Helena Wong, 2000
10
Flipping both x and y coordinates of a point relative to the origin:










1
'y
'x
=










−
−
100
010
001










1
y
x
ie. x'=-x; y'=-y
Reflection about the diagonal line y=x:










1
'y
'x
=










100
001
010










1
y
x
ie. x'=y; y'=x
Reflection about the diagonal line y=-x:










1
'y
'x
=










−
−
100
001
010










1
y
x
ie. x'=-y; y'=-x
Shear
X-direction shear, with a shearing parameter shx, relative
to the x-axis:










1
'y
'x
=










100
010
0sh1 x










1
y
x
ie. x'=x+y*shx; y'=-x
Exercise: Think of a y-direction shear, with a shearing parameter shy, relative to the y-axis.
4.5 Transformation Between 2 Cartesian Systems
For modelling and design applications, individual objects may be defined in their own local Cartesian
References. The local coordinates must then be transformed to position the objects within the overall
scene coordinate system.
Suppose we want to transform object descriptions from the xy system to the x'y' system:
The composite transformation is:










θ−θ−
θ−−θ−
100
y)cos()sin(
x)sin()cos(
r
r










−
−
100
y10
x01
0
0

More Related Content

What's hot

A mid point ellipse drawing algorithm on a hexagonal grid
A mid  point ellipse drawing algorithm on a hexagonal gridA mid  point ellipse drawing algorithm on a hexagonal grid
A mid point ellipse drawing algorithm on a hexagonal gridS M K
 
Output primitives computer graphics c version
Output primitives   computer graphics c versionOutput primitives   computer graphics c version
Output primitives computer graphics c versionMarwa Al-Rikaby
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterizationMaaz Rizwan
 
Circle generation algorithm
Circle generation algorithmCircle generation algorithm
Circle generation algorithmAnkit Garg
 
Lab lecture 1 line_algo
Lab lecture 1 line_algoLab lecture 1 line_algo
Lab lecture 1 line_algosimpleok
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesAnkit Garg
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.Mohd Arif
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmKasun Ranga Wijeweera
 
Computer graphics presentation
Computer graphics presentationComputer graphics presentation
Computer graphics presentationLOKENDRA PRAJAPATI
 
Dda line algorithm presentatiion
Dda line algorithm presentatiionDda line algorithm presentatiion
Dda line algorithm presentatiionMuhammadHamza401
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithmsMohammad Sadiq
 

What's hot (20)

A mid point ellipse drawing algorithm on a hexagonal grid
A mid  point ellipse drawing algorithm on a hexagonal gridA mid  point ellipse drawing algorithm on a hexagonal grid
A mid point ellipse drawing algorithm on a hexagonal grid
 
Output primitives computer graphics c version
Output primitives   computer graphics c versionOutput primitives   computer graphics c version
Output primitives computer graphics c version
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
bresenham circles and polygons in computer graphics(Computer graphics tutorials)
bresenham circles and polygons in computer graphics(Computer graphics tutorials)bresenham circles and polygons in computer graphics(Computer graphics tutorials)
bresenham circles and polygons in computer graphics(Computer graphics tutorials)
 
Cs580
Cs580Cs580
Cs580
 
Computer graphics 2
Computer graphics 2Computer graphics 2
Computer graphics 2
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterization
 
Circle generation algorithm
Circle generation algorithmCircle generation algorithm
Circle generation algorithm
 
Lab lecture 1 line_algo
Lab lecture 1 line_algoLab lecture 1 line_algo
Lab lecture 1 line_algo
 
DDA algorithm
DDA algorithmDDA algorithm
DDA algorithm
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniques
 
Dda algorithm
Dda algorithmDda algorithm
Dda algorithm
 
Line drawing algo.
Line drawing algo.Line drawing algo.
Line drawing algo.
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
 
Clipping 22
Clipping 22Clipping 22
Clipping 22
 
Dda algo notes
Dda algo notesDda algo notes
Dda algo notes
 
Computer graphics presentation
Computer graphics presentationComputer graphics presentation
Computer graphics presentation
 
Dda line algorithm presentatiion
Dda line algorithm presentatiionDda line algorithm presentatiion
Dda line algorithm presentatiion
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 
Lect14 lines+circles
Lect14 lines+circlesLect14 lines+circles
Lect14 lines+circles
 

Similar to Computer Graphics Quick Guide

Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2SanthiNivas
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsAmol Gaikwad
 
Output Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and MultimediaOutput Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and Multimediasaranyan75
 
Computer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivesComputer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivessaranyan75
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygonsaa11bb11
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons dericationKumar
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxKokebe2
 
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdfCD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdfRajJain516913
 
Lecture _Line Scan Conversion.ppt
Lecture _Line Scan Conversion.pptLecture _Line Scan Conversion.ppt
Lecture _Line Scan Conversion.pptGaganvirKaur
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxNaveenaKarthik3
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsThirunavukarasu Mani
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsKetan Jani
 
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.pptLecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.pptKhondokarMdMehediHas
 
Rasterization.pptx
Rasterization.pptxRasterization.pptx
Rasterization.pptxAhmadAbba6
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxIndhuMcamphil
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxAlamelu
 

Similar to Computer Graphics Quick Guide (20)

Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithms
 
Output Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and MultimediaOutput Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and Multimedia
 
Computer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivesComputer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitives
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptx
 
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdfCD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
 
lecture 1.pptx
lecture 1.pptxlecture 1.pptx
lecture 1.pptx
 
03.Scan Conversion.ppt
03.Scan Conversion.ppt03.Scan Conversion.ppt
03.Scan Conversion.ppt
 
Lecture _Line Scan Conversion.ppt
Lecture _Line Scan Conversion.pptLecture _Line Scan Conversion.ppt
Lecture _Line Scan Conversion.ppt
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptx
 
module 1.pdf
module 1.pdfmodule 1.pdf
module 1.pdf
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
 
Graphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygonsGraphics6 bresenham circlesandpolygons
Graphics6 bresenham circlesandpolygons
 
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.pptLecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
Lecture-4-Scan_Conversion_Bresenhams_Algorithm.ppt
 
Rasterization.pptx
Rasterization.pptxRasterization.pptx
Rasterization.pptx
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
 

Recently uploaded

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Recently uploaded (20)

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 

Computer Graphics Quick Guide

  • 1. http://www.tutorialspoint.com/computer_graphics/computer_graphics_quick_guide.htm Copyright © tutorialspoint.com COMPUTER GRAPHICS - QUICK GUIDECOMPUTER GRAPHICS - QUICK GUIDE COMPUTER GRAPHICS - BASICSCOMPUTER GRAPHICS - BASICS Computer graphics is an art of drawing pictures on computer screens with the help of programming. It involves computations, creation, and manipulation of data. In other words, we can say that computer graphics is a rendering tool for the generation and manipulation of images. Cathode Ray Tube The primary output device in a graphical system is the video monitor. The main element of a video monitor is the Cathode Ray Tube CRT, shown in the following illustration. The operation of CRT is very simple − The electron gun emits a beam of electrons cathoderays. The electron beam passes through focusing and deflection systems that direct it towards specified positions on the phosphor-coated screen. When the beam hits the screen, the phosphor emits a small spot of light at each position contacted by the electron beam. It redraws the picture by directing the electron beam back over the same screen points quickly. There are two ways RandomscanandRasterscan by which we can display an object on the screen. Raster Scan In a raster scan system, the electron beam is swept across the screen, one row at a time from top to bottom. As the electron beam moves across each row, the beam intensity is turned on and off to create a pattern of illuminated spots. Picture definition is stored in memory area called the Refresh Buffer or Frame Buffer. This memory area holds the set of intensity values for all the screen points. Stored intensity values are then retrieved from the refresh buffer and “painted” on the screen one row scanline at a time as shown in the following illustration. Each screen point is referred to as a pixel pictureelement or pel. At the end of each scan line, the
  • 2. electron beam returns to the left side of the screen to begin displaying the next scan line. Random Scan VectorScan In this technique, the electron beam is directed only to the part of the screen where the picture is to be drawn rather than scanning from left to right and top to bottom as in raster scan. It is also called vector display, stroke-writing display, or calligraphic display. Picture definition is stored as a set of line-drawing commands in an area of memory referred to as the refresh display file. To display a specified picture, the system cycles through the set of commands in the display file, drawing each component line in turn. After all the line-drawing commands are processed, the system cycles back to the first line command in the list. Random-scan displays are designed to draw all the component lines of a picture 30 to 60 times each second. Application of Computer Graphics Computer Graphics has numerous applications, some of which are listed below −
  • 3. Computer graphics user interfaces GUIs − A graphic, mouse-oriented paradigm which allows the user to interact with a computer. Business presentation graphics − "A picture is worth a thousand words". Cartography − Drawing maps. Weather Maps − Real-time mapping, symbolic representations. Satellite Imaging − Geodesic images. Photo Enhancement − Sharpening blurred photos. Medical imaging − MRIs, CAT scans, etc. - Non-invasive internal examination. Engineering drawings − mechanical, electrical, civil, etc. - Replacing the blueprints of the past. Typography − The use of character images in publishing - replacing the hard type of the past. Architecture − Construction plans, exterior sketches - replacing the blueprints and hand drawings of the past. Art − Computers provide a new medium for artists. Training − Flight simulators, computer aided instruction, etc. Entertainment − Movies and games. Simulation and modeling − Replacing physical modeling and enactments LINE GENERATION ALGORITHMLINE GENERATION ALGORITHM A line connects two points. It is a basic element in graphics. To draw a line, you need two points between which you can draw a line. In the following three algorithms, we refer the one point of line as X0, Y0 and the second point of line as X1, Y1. DDA Algorithm Digital Differential Analyzer DDA algorithm is the simple line generation algorithm which is explained step by step here. Step 1 − Get the input of two end points (X0, Y0) and (X1, Y1). Step 2 − Calculate the difference between two end points. dx = X1 - X0 dy = Y1 - Y0 Step 3 − Based on the calculated difference in step-2, you need to identify the number of steps to put pixel. If dx > dy, then you need more steps in x coordinate; otherwise in y coordinate. if (dx > dy) Steps = absolute(dx); else Steps = absolute(dy); Step 4 − Calculate the increment in x coordinate and y coordinate. Xincrement = dx / (float) steps; Yincrement = dy / (float) steps; Step 5 − Put the pixel by successfully incrementing x and y coordinates accordingly and complete
  • 4. the drawing of the line. for(int v=0; v < Steps; v++) { x = x + Xincrement; y = y + Yincrement; putpixel(x,y); } Bresenham’s Line Generation The Bresenham algorithm is another incremental scan conversion algorithm. The big advantage of this algorithm is that, it uses only integer calculations. Moving across the x axis in unit intervals and at each step choose between two different y coordinates. For example, as shown in the following illustration, from position 2, 3 you need to choose between 3, 3 and 3, 4. You would like the point that is closer to the original line. At sample position Xk + 1, the vertical separations from the mathematical line are labelled as dupper and dlower.
  • 5. From the above illustration, the y coordinate on the mathematical line at xk + 1 is − Y = m$Xk$ + 1 + b So, dupper and dlower are given as follows − dlower = y − yk = m(Xk + 1) + b − Yk and dupper = (yk + 1) − y = Yk + 1 − m(Xk + 1) − b You can use these to make a simple decision about which pixel is closer to the mathematical line. This simple decision is based on the difference between the two pixel positions. dlower − dupper = 2m(xk + 1) − 2yk + 2b − 1 Let us substitute m with dy/dx where dx and dy are the differences between the end-points. dx(dlower − dupper) = dx(2 dy dx(xk + 1) − 2yk + 2b − 1) = 2dy. xk − 2dx. yk + 2dy + 2dx(2b − 1) = 2dy. xk − 2dx. yk + C So, a decision parameter Pk for the kth step along a line is given by − pk = dx(dlower − dupper) = 2dy. xk − 2dx. yk + C The sign of the decision parameter Pk is the same as that of dlower − dupper. If pk is negative, then choose the lower pixel, otherwise choose the upper pixel. Remember, the coordinate changes occur along the x axis in unit steps, so you can do everything with integer calculations. At step k+1, the decision parameter is given as − pk+1 = 2dy. xk+1 − 2dx. yk+1 + C Subtracting pk from this we get − pk+1 − pk = 2dy(xk+1 − xk) − 2dx(yk+1 − yk) But, xk+1 is the same as xk+1. So − pk+1 = pk + 2dy − 2dx(yk+1 − yk) Where, Y_{k+1} – Y_{k} is either 0 or 1 depending on the sign of P_{k}. The first decision parameter p_{0} is evaluated at (x_{0}, y_{0}) is given as − p_{0} = 2dy - dx Now, keeping in mind all the above points and calculations, here is the Bresenham algorithm for slope m < 1 − Step 1 − Input the two end-points of line, storing the left end-point in (x_{0}, y_{0}).
  • 6. Step 2 − Plot the point (x_{0}, y_{0}). Step 3 − Calculate the constants dx, dy, 2dy, and 2dy – 2dx and get the first value for the decision parameter as − p_{0} = 2dy - dx Step 4 − At each X_{k} along the line, starting at k = 0, perform the following test − If p_{k} < 0, the next point to plot is (x_{k}+1, y_{k}) and p_{k+1} = p_{k} + 2dy Otherwise, p_{k+1} = p_{k} + 2dy - 2dx Step 5 − Repeat step 4 dx – 1 times. For m > 1, find out whether you need to increment x while incrementing y each time. After solving, the equation for decision parameter P_{k} will be very similar, just the x and y in the equation gets interchanged. Mid-Point Algorithm Mid-point algorithm is due to Bresenham which was modified by Pitteway and Van Aken. Assume that you have already put the point P at x, y coordinate and the slope of the line is 0 ≤ k ≤ 1 as shown in the following illustration. Now you need to decide whether to put the next point at E or N. This can be chosen by identifying the intersection point Q closest to the point N or E. If the intersection point Q is closest to the point N then N is considered as the next point; otherwise E. To determine that, first calculate the mid-point Mx+1, y + ½. If the intersection point Q of the line with the vertical line connecting E and N is below M, then take E as the next point; otherwise take N as the next point. In order to check this, we need to consider the implicit equation − Fx,y = mx + b - y For positive m at any given X, If y is on the line, then Fx, y = 0 If y is above the line, then Fx, y < 0 If y is below the line, then Fx, y > 0
  • 7. This can be decided by the decision parameter d. If d <= 0, then NX+1, Y is to be chosen as next pixel. If d > 0, then SX+1, Y-1 is to be chosen as the next pixel. Algorithm Step 1 − Get the coordinates of the center of the circle and radius, and store them in x, y, and R respectively. Set P=0 and Q=R. Step 2 − Set decision parameter D = 3 – 2R. Step 3 − Repeat through step-8 while X < Y. Step 4 − Call Draw Circle X, Y, P, Q. Step 5 − Increment the value of P. Step 6 − If D < 0 then D = D + 4x + 6. Step 7 − Else Set Y = Y + 1, D = D + 4X-Y + 10. Step 8 − Call Draw Circle X, Y, P, Q. Draw Circle Method(X, Y, P, Q). Call Putpixel (X + P, Y + Q). Call Putpixel (X - P, Y + Q). Call Putpixel (X + P, Y - Q). Call Putpixel (X - P, Y - Q). Call Putpixel (X + Q, Y + X). Call Putpixel (X - Q, Y + X). Call Putpixel (X + Q, Y - X). Call Putpixel (X - Q, Y - X). Mid Point Algorithm Step 1 − Input radius r and circle center (x_{c,} y_{c}) and obtain the first point on the circumference of the circle centered on the origin as (x0, y0) = (0, r) Step 2 − Calculate the initial value of decision parameter as P_{0} = 5/4 – r See the following description for simplification of this equation. f(x, y) = x2 + y2 - r2 = 0
  • 8. f(xi - 1/2 + e, yi + 1) = (xi - 1/2 + e)2 + (yi + 1)2 - r2 = (xi- 1/2)2 + (yi + 1)2 - r2 + 2(xi - 1/2)e + e2 = f(xi - 1/2, yi + 1) + 2(xi - 1/2)e + e2 = 0 Let di = f(xi - 1/2, yi + 1) = -2(xi - 1/2)e - e2 Thus, If e < 0 then di > 0 so choose point S = (xi - 1, yi + 1). di+1 = f(xi - 1 - 1/2, yi + 1 + 1) = ((xi - 1/2) - 1)2 + ((yi + 1) + 1)2 - r2 = di - 2(xi - 1) + 2(yi + 1) + 1 = di + 2(yi + 1 - xi + 1) + 1 If e >= 0 then di <= 0 so choose point T = (xi, yi + 1) di+1 = f(xi - 1/2, yi + 1 + 1) = di + 2yi+1 + 1 The initial value of di is d0 = f(r - 1/2, 0 + 1) = (r - 1/2)2 + 12 - r2 = 5/4 - r {1-r can be used if r is an integer} When point S = (xi - 1, yi + 1) is chosen then di+1 = di + -2xi+1 + 2yi+1 + 1 When point T = (xi, yi + 1) is chosen then di+1 = di + 2yi+1 + 1 Step 3 − At each X_{K} position starting at K=0, perform the following test − If PK < 0 then next point on circle (0,0) is (XK+1,YK) and PK+1 = PK + 2XK+1 + 1 Else PK+1 = PK + 2XK+1 + 1 – 2YK+1
  • 9. Where, 2XK+1 = 2XK+2 and 2YK+1 = 2YK-2. Step 4 − Determine the symmetry points in other seven octants. Step 5 − Move each calculate pixel position X, Y onto the circular path centered on (X_{C,} Y_{C}) and plot the coordinate values. X = X + XC, Y = Y + YC Step 6 − Repeat step-3 through 5 until X >= Y. POLYGON FILLING ALGORITHMPOLYGON FILLING ALGORITHM Polygon is an ordered list of vertices as shown in the following figure. For filling polygons with particular colors, you need to determine the pixels falling on the border of the polygon and those which fall inside the polygon. In this chapter, we will see how we can fill polygons using different techniques. Scan Line Algorithm This algorithm works by intersecting scanline with polygon edges and fills the polygon between pairs of intersections. The following steps depict how this algorithm works. Step 1 − Find out the Ymin and Ymax from the given polygon. Step 2 − ScanLine intersects with each edge of the polygon from Ymin to Ymax. Name each intersection point of the polygon. As per the figure shown above, they are named as p0, p1, p2, p3. Step 3 − Sort the intersection point in the increasing order of X coordinate i.e. p0, p1, p1, p2, and p2, p3. Step 4 − Fill all those pair of coordinates that are inside polygons and ignore the alternate pairs. Flood Fill Algorithm
  • 10. Sometimes we come across an object where we want to fill the area and its boundary with different colors. We can paint such objects with a specified interior color instead of searching for particular boundary color as in boundary filling algorithm. Instead of relying on the boundary of the object, it relies on the fill color. In other words, it replaces the interior color of the object with the fill color. When no more pixels of the original interior color exist, the algorithm is completed. Once again, this algorithm relies on the Four-connect or Eight-connect method of filling in the pixels. But instead of looking for the boundary color, it is looking for all adjacent pixels that are a part of the interior. Boundary Fill Algorithm The boundary fill algorithm works as its name. This algorithm picks a point inside an object and starts to fill until it hits the boundary of the object. The color of the boundary and the color that we fill should be different for this algorithm to work. In this algorithm, we assume that color of the boundary is same for the entire object. The boundary fill algorithm can be implemented by 4-connected pixels or 8-connected pixels. 4-Connected Polygon In this technique 4-connected pixels are used as shown in the figure. We are putting the pixels above, below, to the right, and to the left side of the current pixels and this process will continue until we find a boundary with different color.
  • 11. Algorithm Step 1 − Initialize the value of seed point seedx, seedy, fcolor and dcol. Step 2 − Define the boundary values of the polygon. Step 3 − Check if the current seed point is of default color, then repeat the steps 4 and 5 till the boundary pixels reached. If getpixel(x, y) = dcol then repeat step 4 and 5 Step 4 − Change the default color with the fill color at the seed point. setPixel(seedx, seedy, fcol) Step 5 − Recursively follow the procedure with four neighborhood points. FloodFill (seedx – 1, seedy, fcol, dcol) FloodFill (seedx + 1, seedy, fcol, dcol) FloodFill (seedx, seedy - 1, fcol, dcol) FloodFill (seedx – 1, seedy + 1, fcol, dcol) Step 6 − Exit There is a problem with this technique. Consider the case as shown below where we tried to fill the entire region. Here, the image is filled only partially. In such cases, 4-connected pixels technique cannot be used. 8-Connected Polygon In this technique 8-connected pixels are used as shown in the figure. We are putting pixels above, below, right and left side of the current pixels as we were doing in 4-connected technique. In addition to this, we are also putting pixels in diagonals so that entire area of the current pixel is covered. This process will continue until we find a boundary with different color.
  • 12. Algorithm Step 1 − Initialize the value of seed point seedx, seedy, fcolor and dcol. Step 2 − Define the boundary values of the polygon. Step 3 − Check if the current seed point is of default color then repeat the steps 4 and 5 till the boundary pixels reached If getpixel(x,y) = dcol then repeat step 4 and 5 Step 4 − Change the default color with the fill color at the seed point. setPixel(seedx, seedy, fcol) Step 5 − Recursively follow the procedure with four neighbourhood points FloodFill (seedx – 1, seedy, fcol, dcol) FloodFill (seedx + 1, seedy, fcol, dcol) FloodFill (seedx, seedy - 1, fcol, dcol) FloodFill (seedx, seedy + 1, fcol, dcol) FloodFill (seedx – 1, seedy + 1, fcol, dcol) FloodFill (seedx + 1, seedy + 1, fcol, dcol) FloodFill (seedx + 1, seedy - 1, fcol, dcol) FloodFill (seedx – 1, seedy - 1, fcol, dcol) Step 6 − Exit The 4-connected pixel technique failed to fill the area as marked in the following figure which won’t happen with the 8-connected technique.
  • 13. Inside-outside Test This method is also known as counting number method. While filling an object, we often need to identify whether particular point is inside the object or outside it. There are two methods by which we can identify whether particular point is inside an object or outside. Odd-Even Rule Nonzero winding number rule Odd-Even Rule In this technique, we count the edge crossing along the line from any point x, y to infinity. If the number of interactions is odd then the point x, y is an interior point. If the number of interactions is even then point x, y is an exterior point. Here is the example to give you the clear idea − From the above figure, we can see that from the point x, y, the number of interactions point on the left side is 5 and on the right side is 3. So the total number of interaction point is 8, which is odd. Hence, the point is considered within the object. Nonzero Winding Number Rule This method is also used with the simple polygons to test the given point is interior or not. It can be simply understood with the help of a pin and a rubber band. Fix up the pin on one of the edge of the polygon and tie-up the rubber band in it and then stretch the rubber band along the edges of the polygon. When all the edges of the polygon are covered by the rubber band, check out the pin which has been fixed up at the point to be test. If we find at least one wind at the point consider it within the polygon, else we can say that the point is not inside the polygon.
  • 14. In another alternative method, give directions to all the edges of the polygon. Draw a scan line from the point to be test towards the left most of X direction. Give the value 1 to all the edges which are going to upward direction and all other -1 as direction values. Check the edge direction values from which the scan line is passing and sum up them. If the total sum of this direction value is non-zero, then this point to be tested is an interior point, otherwise it is an exterior point. In the above figure, we sum up the direction values from which the scan line is passing then the total is 1 – 1 + 1 = 1; which is non-zero. So the point is said to be an interior point. VIEWING & CLIPPINGVIEWING & 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, Y is within the given window or not; and decides whether we will use the minimum and maximum coordinates of the window. 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.
  • 15. CS3162 Introduction to Computer Graphics Helena Wong, 2000 1 4. Two Dimensional Transformations In many applications, changes in orientations, size, and shape are accomplished with geometric transformations that alter the coordinate descriptions of objects. Basic geometric transformations are: Translation Rotation Scaling Other transformations: Reflection Shear 4.1 Basic Transformations Translation We translate a 2D point by adding translation distances, tx and ty, to the original coordinate position (x,y): x' = x + tx, y' = y + ty Alternatively, translation can also be specified by the following transformation matrix:           100 t10 t01 y x Then we can rewrite the formula as:           1 'y 'x =           100 t10 t01 y x           1 y x For example, to translate a triangle with vertices at original coordinates (10,20), (10,10), (20,10) by tx=5, ty=10, we compute as followings: Translation of vertex (10,20):           1 'y 'x =           100 1010 501           1 20 10 =           ++ ++ ++ 1*120*010*0 1*1020*110*0 1*520*010*1 =           1 30 15 Translation of vertex (10,10):           1 'y 'x =           100 1010 501           1 10 10 =           ++ ++ ++ 1*110*010*0 1*1010*110*0 1*510*010*1 =           1 20 15
  • 16. CS3162 Introduction to Computer Graphics Helena Wong, 2000 2 Translation of vertex (20,10):           1 'y 'x =           100 1010 501           1 10 20 =           ++ ++ ++ 1*110*020*0 1*1010*120*0 1*510*020*1 =           1 20 25 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. 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:           θθ θ−θ 100 0cossin 0sincos Then we can rewrite the formula as:           1 'y 'x =           θθ θ−θ 100 0cossin 0sincos           1 y x 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:           θθ θ−θ 100 0cossin 0sincos =           − 100 030cos30sin 030sin30cos =           − 100 0866.05.0 05.0866.0 Rotation of vertex (10,20):           1 'y 'x =           − 100 0866.05.0 05.0866.0           1 20 10 =           ++ ++ +−+ 1*120*010*0 1*020*866.010*5.0 1*020*)5.0(10*866.0 =          − 1 32.22 34.1
  • 17. CS3162 Introduction to Computer Graphics Helena Wong, 2000 3 Rotation of vertex (10,10):           1 'y 'x =           − 100 0866.05.0 05.0866.0           1 10 10 =           ++ ++ +−+ 1*110*010*0 1*010*866.010*5.0 1*010*)5.0(10*866.0 =           1 66.13 66.3 Rotation of vertex (20,10):           1 'y 'x =           − 100 0866.05.0 05.0866.0           1 10 20 =           ++ ++ +−+ 1*110*020*0 1*010*866.020*5.0 1*010*)5.0(20*866.0 =           1 66.18 32.12 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. Scaling With Respect to the Origin 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:           100 0s0 00s y x Then we can rewrite the formula as:           1 'y 'x =           100 0s0 00s y x           1 y x 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):           1 'y 'x =           100 05.10 002           1 20 10 =           ++ ++ ++ 1*120*010*0 1*020*5.110*0 1*020*010*2 =           1 30 20
  • 18. CS3162 Introduction to Computer Graphics Helena Wong, 2000 4 Scaling of vertex (10,10):           1 'y 'x =           100 05.10 002           1 10 10 =           ++ ++ ++ 1*110*010*0 1*010*5.110*0 1*010*010*2 =           1 15 20 Scaling of vertex (20,10):           1 'y 'x =           100 05.10 002           1 10 20 =           ++ ++ ++ 1*110*020*0 1*010*5.120*0 1*010*020*2 =           1 15 40 The resultant coordinates of the triangle vertices are (20,30), (20,15), and (40,15) respectively. Exercise: Scale a triange with vertices at original coordinates (10,25), (5,10), (20,10) by sx=1.5, sy=2, with respect to the origin. Roughly plot the original and resultant triangles. 4.2 Concatenation Properties of Composite Matrix I. Matrix multiplication is associative: A·B·C = (A·B) ·C = A·(B·C) Therefore, we can evaluate matrix products using these associative grouping. For example, we have a triangle, we want to rotate it with the matrix B, then we translate it with matrix A. Then, for a vertex of that triangle represented as C, we compute its transformation as: C'=A·(B·C) But we can also change the computation method as: C' = (A·B)·C The advantage of computing it using C' = (A·B)·C instead of C'=A·(B·C) is that, for computing the 3 vertices of the triangle, C1, C2, C3, the computation time is shortened: Using C'=A·(B·C): 1. compute B · C1 and put the result into I1 2. compute A · I1 and put the result into C1 ' 3. compute B · C2 and put the result into I2 4. compute A · I2 and put the result into C2 ' 5. compute B · C3 and put the result into I3 6. compute A · I3 and put the result into C3 ' Using C' = (A·B)·C: 1. compute A · B and put the result into M 2. compute M · C1 and put the result into C1 ' 3. compute M · C2 and put the result into C2 ' 4. compute M · C3 and put the result into C3 '
  • 19. CS3162 Introduction to Computer Graphics Helena Wong, 2000 5 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: B =           − 100 030cos30sin 030sin30cos =           − 100 0866.05.0 05.0866.0 And we compute the translation matrix: A=           100 1010 501 Then, we compute M=A·B M=           100 1010 501 ·           − 100 0866.05.0 05.0866.0 M=           ++++−++ ++++−++ ++++−++ 1*10*00*00*1866.0*05.0*00*15.0*0866.0*0 1*100*10*00*10866.0*15.0*00*105.0*1866.0*0 1*50*00*10*5866.0*05.0*10*55.0*0866.0*1 M=           − 100 10866.05.0 55.0866.0 Then, we compute the transformations of the 3 vertices: Transformation of vertex (10,20):           1 'y 'x =           − 100 10866.05.0 55.0866.0           1 20 10 =           ++ ++ +−+ 1*120*010*0 1*1020*866.010*5.0 1*520*)5.0(10*866.0 =           1 32.32 66.3 Transformation of vertex (10,10):           1 'y 'x =           − 100 10866.05.0 55.0866.0           1 10 10 =           ++ ++ +−+ 1*110*010*0 1*1010*866.010*5.0 1*510*)5.0(10*866.0 =           1 66.23 66.8
  • 20. CS3162 Introduction to Computer Graphics Helena Wong, 2000 6 Transformation of vertex (20,10):           1 'y 'x =           − 100 10866.05.0 55.0866.0           1 10 20 =           ++ ++ +−+ 1*110*020*0 1*1010*866.020*5.0 1*510*)5.0(20*866.0 =           1 66.28 32.17 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. 4.3 Composite Transformation Matrix 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+ ty2). This additive property can be demonstrated by composite transformation matrix:           100 t10 t01 1y 1x ·           100 t10 t01 2y 2x =           ++++++ ++++++ ++++++ 1*1t*0t*00*11*00*00*10*01*0 1*tt*1t*00*t1*10*00*t0*11*0 1*tt*0t*10*t1*00*10*t0*01*1 2u2x 1y2y2x1y1y 1x2y2x1x1x =           + + 100 tt10 tt01 2y1y 2x1x This demonstrates that 2 successive translations are additive.
  • 21. CS3162 Introduction to Computer Graphics Helena Wong, 2000 7 Rotations By common sense, if we rotate a shape with 2 successive rotation angles: ? and a, about the origin, it is equal to rotating the shape once by an angle ? + a about the origin. Similarly, this additive property can be demonstrated by composite transformation matrix:           θθ θ−θ 100 0cossin 0sincos ·           αα α−α 100 0cossin 0sincos =           +++α+α−+α+α +θ+θ+αθ+α−θ+αθ+αθ +θ−+θ+αθ−+α−θ+αθ−+αθ 1*10*00*00*1cos*0)sin(*00*1sin*0cos*0 1*00*cos0*sin0*0cos*cos)sin(*sin0*0sin*coscossin 1*00*)sin(0*cos0*0cos*)sin()sin(*cos0*0sin*)sin(coscos =           αθ+αθ−αθ+αθ αθ+αθ−αθ−αθ 100 0coscossinsinsincoscossin 0)cossinsin(cossinsincoscos =           α+θα+θ α+θ−α+θ 100 0)cos()sin( 0)sin()cos( This demonstrates that 2 successive rotations are additive. Scalings With Respect to the Origin By common sense, if we scale a shape with 2 successive scaling factor: (sx1, sy1) and (sx2, sy2), with respect to the origin, it is equal to a single scaling of (sx1* sx2, sy1* sy2) with respect to the origin. This multiplicative property can be demonstrated by composite transformation matrix:           100 0s0 00s 1y 1x ·           100 0s0 00s 2y 2x =           ++++++ ++++++ ++++++ 1*10*00*00*1s*00*00*10*0s*0 1*00*s0*00*0s*s0*00*00*ss*0 1*00*00*s0*0s*00*s0*00*0s*s 2y2x 1y2y1y1y2x 1x2y1x2x1x =           100 0s*s0 00s*s 2y1y 2x1x This demonstrates that 2 successive scalings with respect to the origin are multiplicative.
  • 22. CS3162 Introduction to Computer Graphics Helena Wong, 2000 8 General Pivot-Point Rotation Rotation about an arbitrary pivot point is not as simple as rotation about the origin. The procedure of rotation about an arbitrary pivot point is: 1. Translate the object so that the pivot-point position is moved to the origin. 2. Rotate the object about the origin. 3. Translate the object so that the pivot point is returned to its original position. The corresponding composite transformation matrix is:           100 y10 x01 r r           θθ θ−θ 100 0cossin 0sincos           − − 100 y10 x01 r r =           θθ θ−θ 100 ycossin xsincos r r           − − 100 y10 x01 r r =           +θ−θ−θθ +θ+θ−θ−θ 100 ycosysinxcossin xsinycosxsincos rrr rrr General Fixed-Point Scaling Scaling with respect to an arbitrary fixed point is not as simple as scaling with respect to the origin. The procedure of scaling with respect to an arbitrary fixed point is: 1. Translate the object so that the fixed point coincides with the origin. 2. Scale the object with respect to the origin. 3. Use the inverse translation of step 1 to return the object to its original position.
  • 23. CS3162 Introduction to Computer Graphics Helena Wong, 2000 9 The corresponding composite transformation matrix is:           100 y10 x01 f f           100 0s0 00s y x           − − 100 y10 x01 f f =           − − 100 )s1(ys0 )s1(x0s yfy xfx General Scaling Direction Scaling along an arbitrary direction is not as simple as scaling along the x-y axis. The procedure of scaling along and normal to an arbitrary direction (s1 and s2), with respect to the origin, is: 1. Rotate the object so that the directions for s1 and s2 coincide with the x and y axes respectively. 2. Scale the object with respect to the origin using (s1, s2). 3. Use an opposite rotation to return points to their original orientation. The corresponding composite transformation matrix is:           θ−θ− θ−−θ− 100 0)cos()sin( 0)sin()cos(           100 0s0 00s 2 1           θθ θ−θ 100 0cossin 0sincos 4.4 Other Transformations Reflection Reflection about the x axis:           1 'y 'x =           − 100 010 001           1 y x ie. x'=x; y'=-y Reflection about the y axis:           1 'y 'x =          − 100 010 001           1 y x ie. x'=-x; y'=y
  • 24. CS3162 Introduction to Computer Graphics Helena Wong, 2000 10 Flipping both x and y coordinates of a point relative to the origin:           1 'y 'x =           − − 100 010 001           1 y x ie. x'=-x; y'=-y Reflection about the diagonal line y=x:           1 'y 'x =           100 001 010           1 y x ie. x'=y; y'=x Reflection about the diagonal line y=-x:           1 'y 'x =           − − 100 001 010           1 y x ie. x'=-y; y'=-x Shear X-direction shear, with a shearing parameter shx, relative to the x-axis:           1 'y 'x =           100 010 0sh1 x           1 y x ie. x'=x+y*shx; y'=-x Exercise: Think of a y-direction shear, with a shearing parameter shy, relative to the y-axis. 4.5 Transformation Between 2 Cartesian Systems For modelling and design applications, individual objects may be defined in their own local Cartesian References. The local coordinates must then be transformed to position the objects within the overall scene coordinate system. Suppose we want to transform object descriptions from the xy system to the x'y' system: The composite transformation is:           θ−θ− θ−−θ− 100 y)cos()sin( x)sin()cos( r r           − − 100 y10 x01 0 0