رسوم نظري كامله
رسوم نظري كامله
CHAPTER 1
Introduction to Computer Graphics
1.1 What is computer graphics?
1
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
2
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
3
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
A polyline need not form a closed figure, but if the first and last
points are connected by an edge the polyline is a polygon.
4
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
2. Text
Some graphics devices have two distinct display modes, a text
mode and a graphics mode. The text mode is used for simple
input/output of characters to control the operating system or
edit the code in a program.
Text displayed in this mode uses a built-in character generator.
The character generator is capable of drawing alphabetic,
numeric, and punctuation characters, and some selection of
special symbols such as ♥, ð, and ⊕ .
Compare with the graphic mode, the PC's text mode is easy to use.
Displaying information on the screen is a simple as placing ASCII char
in specific memory location. The text screen is divided into 80
column and 25 rows. The graphic mode requires a completely
different orientation instead of character; you have pixels, the
smallest picture element on your computer display. Today most
screens can display text and graphics.
Attributes of Text
There are many text attributes, the most important of which are
typeface, color, size, spacing, and Orientation.
A font is a specific set of character shapes (a typeface) in a particular
style and size.
3. Filled Regions
The filled region (sometimes called “fill area”) primitive is a
shape filled with some color or pattern. The boundary of a
filled region is often a polygon
5
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
4. Raster Image.
A raster image It is made up of many small “cells”, in different
shades of gray, The individual cells are often called “pixels”
(short for “picture elements”). Normally your eye can’t see the
individual cells; it blends them together and synthesizes an
overall picture.
6
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
2. Computed Images.
An algorithm is used to “render” a scene, which might be modeled
abstractly in computer memory. As a simple example, a scene might
consist of a single yellow smooth sphere illuminated by a light source
that emanates orange light.
3. Scanned images.
A photograph or television image can be digitized as described above.
In effect a grid is placed over the original image, and at each grid
point the digitizer reads into memory the “closest” color in its
repertoire. The bitmap is then stored in a file for later use.
7
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
In any case, the color values for all the pixels on the screen are stored
in a large block of memory known as a frame buffer. Changing the
image on the screen requires changing color values that are stored in
the frame buffer. The screen is redrawn many times per second, so
that almost immediately after the color values are changed in the
frame buffer, the colors of the pixels on the screen will be changed to
match, and the displayed image will change.
A computer screen used in this way is the basic model of raster
graphics. The term “raster” technically refers to the mechanism used
on older vacuum tube computer monitors: An electron beam would
move along the rows of pixels, making them glow. The beam was
8
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
moved across the screen by powerful magnets that would deflect the
path of the electrons. The stronger the beam, the brighter the glow of
the pixel, so the brightness of the pixels could be controlled by
modulating the intensity of the electron beam. The color values
stored in the frame buffer were used to determine the intensity of the
electron beam. (For a color screen, each pixel had a red dot, a green
dot, and a blue dot, which were separately illuminated by the
beam.)
A modern flat-screen computer monitor is not a raster in the same
sense. There is no moving electron beam. The mechanism that
controls the colors of the pixels is different for different types of
screen. But the screen is still made up of pixels, and the color values
for all the pixels are still stored in a frame buffer. The idea of an
image consisting of a grid of pixels, with numerical color values for
each pixel, defines raster graphics.
9
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
b. Frame Buffer:
Each screen pixel corresponds to a particular entry in a two
dimensional array residing in memory. This memory is called a frame
buffer or a bit map. The number of rows in the frame buffer array
equals the number of raster lines on the display screen. The number
10
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
c. Display Controller:
The hardware device that read the contents of the frame buffer into
video buffer, which then converts the digital representation of a
string of pixel values into analogue voltage signals that are sent
serially to the video display screen (CRT).
11
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
12
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
Resolution depend on :
1. Special resolution (number of pixels).
2. Brightness resolution (values of pixels).
2. Dot Pitch:
It is the amount of space between the center of adjacent pixels, the
closer the dots, the crisper the image. For crisp images, dot pitch
should be less than 0.31 millimeter.
3. Refresh Rate:
It is the number of times per second that the pixels are recharged so
that their glow remains bright. In general, displays are refreshed 45
to 100 times per second.
13
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
lecu.Amaal Khadum Computer science department
Chapter two
Two-Dimensional Graphics
Introduction
In order to draw a picture on a raster display, we must determine the
corresponding points in the frame buffer that make up the picture. To
perform this task we must write scan conversion point plotting
algorithms.
Both the frame buffer and the display screen are given a two-
dimensional coordinates system with the origin at the lower left
corner.
1
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
lecu.Amaal Khadum Computer science department
The drawing on the screen starts from top to down, and from left
to right. The pixel coordinates on the screen (VGA 640 480) is
shown in figure below:
(0,0)
(639 , 479)
2
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
lecu.Amaal Khadum Computer science department
Scan conversion
The process of representing continuous graphics objects as a
collection of discrete pixel called Scan conversion.
Figure 2.1 suggests how an image is created and displayed.
3
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
lecu.Amaal Khadum Computer science department
1. Horizontal Lines:
Algorithm (1):
Input: Xstart, Xend, Yspecified.
Output: Horizontal line.
If Xstart > Xend then replace Xend by Xstart and vice versa in for loop
at algorithm(1).
4
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
lecu.Amaal Khadum Computer science department
2. Vertical Lines:
Algorithm (2):
If Ystart > Yend then replace Yend by Ystart and vice versa in for loop
at algorithm (2).
5
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
lecu.Amaal Khadum Computer science department
3. Diagonal Lines:
To draw a diagonal line with a slope equal to (+1), we need only
repeatedly increment by one unit both x and y values from the start
to end pixels as shown in algorithm (3).
Algorithm (3):
6
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
lecu.Amaal Khadum Computer science department
What are the things a good line-drawing algorithms should do
well:
1. straight Lines must be appear as straight lines.
2. Lines must start and end accurately.
3. Lines should have constant brightness along their length.
4.Lines should be drawn rapidly.
Note
Jaggy lines
7
Mustansiriyah university
Computer Graphics Education college
2018-2019
Third stage
Computer science department
Arbitrary Lines
Drawing lines with arbitrary slope creates several problems, such as:
Although it may not be possible to choose pixels that lie on the actual
line, we want to turn on pixels lying closest to it. For example, in
previous figure, the pixel at location B is a better choice than the one
at location A.
1
Mustansiriyah university
Computer Graphics Education college
2018-2019
Third stage
Computer science department
1- Direct method:
In this method, we learn how to draw a line between two points by
drawing a group of pixels using the command plot (x , y , color), with
substituting in straight line equation:
Y=m×X+b
𝒚𝒆𝒏𝒅−𝒚𝒔𝒕𝒂𝒓𝒕
𝒎= , b=ystart – m * xstart
𝒙𝒆𝒏𝒅−𝒙𝒔𝒕𝒂𝒓𝒕
Algorithm (4):
Input: Xstart,Ystart, Xend, Yend.
Output: Arbitrary line.
{
dx=Xend-Xstart
dy=Yend-Ystart
m=dy/dx
b= Ystart – m * Xstart ;
for x= Xstart to Xend step sign(dx)
{
y=m *x + b;
plot (x , y , color);
}
}
2
Mustansiriyah university
Computer Graphics Education college
2018-2019
Third stage
Computer science department
Example: trace the line where the endpoints are (1, 5), (7, 2) by Direct
method , and draw the line in screen coordinate.
dx=7-1=6; dy=2-5= -3; m= -3/6= -1/2 =-0.5; b=5- (-0.5)*1=5.5
3
Mustansiriyah university
Computer Graphics Education college
2018-2019
Third stage
Computer science department
DDA Algorithm(5):
Consider one point of the line as (X1,Y1) and the second point of the
line as (X2,Y2).
1. calculate dx , dy
dx = ( X2 – X1);
dy = ( Y2 – Y1);
4
Mustansiriyah university
Computer Graphics Education college
2018-2019
Third stage
Computer science department
Algorithm (5):
Input: x1,x2,y1,y2.
i=0;
Output: Arbitrary line
{ If (abs(x2-x1) abs(y2-y1))
length= abs(x2-x1);
else
length= abs(y2-y1);
dx=(x2-x1)/length;
dy=(y2-y1)/length;
x=x1;
y=y1;
while (i length)
{
plot(round(x),round(y),color);
x=x+ d x ;
y=y+ d y ;
i=i+1;
5
Mustansiriyah university
Computer Graphics Education college
2018-2019
Third stage
Computer science department
Ex/: trace the line where the end points between (23,33), (29,40) by DDA
method.
Sol/: dx=29-23=6
dy=40-33=7 i X Y Plot Plot
(X) (y)
Length=7
Xinc=6/7 =0.857 0 23 33 23 33
Yinc=7/7=1.
1 23.857 34 24 34
2 24.714 35 25 35
3 25.571 36 26 36
4 26.429 37 26 37
5 27.286 38 27 38
6 28.143 39 28 39
7 29 40 29 40
NOTE:
The DDA algorithm is faster than the direct use of the line equation
since it calculates points on the line without any floating point
multiplication. However, a floating point addition is still needed in
determining each successive point. Furthermore, cumulative error
due to limited precision in the floating point representation may
cause calculated points to drift away from their true position when
the line relatively long.
6
Mustansiriyah university
Computer Graphics Education college
2018-2019
Third stage
Computer science department
3.Bresenham’s algorithm
- Developed by Bresenham J.E.
- Designed so that each iteration changes one of the coordinates
values by ± 1.
- The other coordinate may or may not change depending on the
value of an error term maintained by the algorithm.
- The error term records the distance measured perpendicular to the
axis of greatest movement between the exact path of the line and the
actual dots generated.
Algorithm (6):
Input: x1,x2,y1,y2.
Output: Arbitrary line
{ x=x1 ;y=y1; dx=x2-x1; dy=y2-y1;
e=dy/dx-0.5 ;
for i=0 to abs(dx)
{ plot (x,y,color);
While (e>=0)
{
if y1>y2
{ y=y-1;e=e-1;
else
y=y+1; e=e-1;
}
}
If x1>x2
{ x=x-1;
else
x=x+1;
}
e=e+dy/dx
}
}
7
Mustansiriyah university
Computer Graphics Education college
2018-2019
Third stage
Computer science department
5 55 67 -0.502 +m
6 56 67 -0.169 +m
7 57 67 0.164 -1+m
8 58 68 -0.503 +m
9 59 68 -0.17
8
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
Circle Drawing
The circle is a special kind of curves. The circle is a closed curve
with same starting and ending point. Circles are probably the most
used curves in elementary graphics.
xc,yc
y= yc ±√r 2−(x−xc)2
1
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
y= yc ±√r 2−(x−xc)2
x=x+1
2
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
Direct Algorithm
Input : xc ,yc , r.
Output : Circle
{ x=xc-r;
for i= 0 to 2*r
{ y=yc+
plot (x, integer (y) ,color)
y=yc-
plot (x, integer (y),color)
x=x+1;
}
}
3
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
Example :Find the point of a circle where xc=10, yc= 10 and r=5
using direct algorithm?
xc=10
yc=10
x=xc-r x=10-5=5 3
For i=0:2*r
y=yc+sqrt((r^2)-(x-xc)^2)
Plot(x,round(y),'y')
y=yc-sqrt((r^2)-(x-xc)^2)
Plot(x,round(y),'y')
x=x+1
End
4
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
y = yc + r sin .
5
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
Polar algorithm
Input : xc ,yc , r.
Output : Circle
{
th=0; dth=1/r;
while (th<=2*pi)
{
x = xc + r *cos (th)
y = yc + r sin(th)
plot (integer(x),integer(y),color)
th = th + dth;
}
}
Note: the algorithm use cos & sin operation and do not take
the advantage of symmetric in circle
6
Computer Graphics Mustansiriyah university
Third stage 2018-2019 Education college
Computer science department
Example :Find the point of a circle where xc=10, yc= 10 and r=5
using polar algorithm ?
th=0
dth=1/r=1/5
While th <=2*pi
x=xc+r*cos(th)
y=yc+r*sin(th)
Plot(round(x),round(y),'.k')
th=th+dth
End
7
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
Chapter Five
5.1 Symmetric (incremental) algorithm
1
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
x = xc + r cos
y = yc + r sin
x =r cos
y =r sin
Dx=-rsind
Dy=rcos d
Dx =-y d
Dy = x d
as we know
x = x + Dx x = x – y* dø
y = y + Dy y = y + x* dø
symmetry equation
2
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
Input : xc,yc,r.
Output : circle
{
th=0 , pi=3.141593 , dth=1/r , x=r , y=0;
while th<=pi/4
{
plot (integer (xc+x) , integer (yc+y) ,color )
plot (integer (xc+x) , integer (yc-y) ,color)
plot (integer (xc-x) , integer (yc+y) ,color )
plot (integer (xc-x) , integer (yc-y) ,color)
plot (integer (xc+y) , integer (yc+x) ,color )
plot (integer (xc+y) , integer (yc-x) ,color )
plot (integer (xc-y) , integer (yc+x) ,color )
plot (integer (xc-y) , integer (yc-x) ,color )
th = th + dth ;
x = x - y * dth ;
y = y + x * dth ;
}
}
3
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
S=d(A)+d(B);
4
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
P(x,y
A(x+1,y)
)
B(x+1,y-
1)
r
5
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
Input : xc,yc,r.
Output : circle
{
x=0; y=r;
While(x<=y)
{
plot (integer (xc+x) , integer (yc+y) ,color)
plot (integer (xc+x) , integer (yc-y) ,color)
plot (integer (xc-x) , integer (yc+y) ,color )
plot (integer (xc-x) , integer (yc-y) ,color)
plot (integer (xc+y) , integer (yc+x) ,color )
plot (integer (xc+y) , integer (yc-x) ,color )
plot (integer (xc-y) , integer (yc+x) ,color )
plot (integer (xc-y) , integer (yc-x) ,color )
da= (x+1)^2+(y)^2-(r)^2
db= (x+1)^2+ (y-1)^2 -(r)^2
s= da + db
if (s>0)
{ y=y-1 ; }
x=x+1;
}
}
6
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
Ex. /trace the Bresenham algorithm to generate six points of the circle
centered at (300,150) with a radius equal to 9 unit.
Sol. / da = (x+1) ^2 + y^2 – R^2 , db= (x+1) ^2 + (y-1) ^2 – R^2,
R^2=81
7
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
8
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
9
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
Input : xc,yc,r.
Output : circle
{
x = 0 ; y = r ; p = 2*(1 – r)
While x <= y
{
plot (integer (xc+x) , integer (yc+y) ,color)
plot (integer (xc+x) , integer (yc-y) ,color)
plot (integer (xc-x) , integer (yc+y) ,color )
plot (integer (xc-x) , integer (yc-y) ,color)
plot (integer (xc+y) , integer (yc+x) ,color )
plot (integer (xc+y) , integer (yc-x) ,color )
plot (integer (xc-y) , integer (yc+x) ,color )
plot (integer (xc-y) , integer (yc-x) ,color )
x = x + 1;
If p < 0 Then
p = p + 2 * x + 1;
Else
y=y-1;
p = p + 2 * (x - y) + 1;
End If
}
}
10
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
Ex. /trace the Midpoint algorithm to generate six points of the circle
centered at (120,130) with a radius equal to 7 unit.
Sol. /p=2(1-r)=2(1-7)=-12
If p<0 p=p+2*x+1
If p>=0 p=p+2(x-y)+1
x y P x+xc y+yc
0 7 -12 120 137
1 7 -9 121 137
2 7 -4 122 137
3 7 3 123 137
4 6 0 124 136
5 5 1 125 135
11
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
yr
ø
(xc,yc) xr
The values of (xr) and (yr) effect the shape of the ellipse.
- If yr > xr the ellipse is longer in the y direction
- If yr < xr the ellipse is longer in the x direction.
- If xr = yr the equation produces a circle.
- The ellipse can be drawn using four-points symmetry.
If (x,y) lies on the ellipse so do the points (-x,y), (x,-y) and
(-x,-y).
(-x,y) (x,y)
y
r
(-x,-y) (x,-y)
12
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
Input : xc,yc,xr,yr.
Output: Ellipse .
{
dth=1/ ((xr +yr)/2) ;
th=0 ;
pi= 3.1416;
While (th<=2*pi)
{
x= xr*cos(th) ;
y= yr*sin(th) ;
plot (integer (xc+x), integer(yc +y),color);
plot (integer (xc-x), integer (yc+y), color);
plot (integer (xc+x), integer (yc-y), color);
plot (integer (xc-x), integer (yc-y), color) ;
th=th+dth ;
}
}
EX /trace the algorithm that use the polar representation to generate six
points of the ellipse centered at (300, 150) with xr=10, yr=5.
Sol:\ dth=1/((xr+yr)/2) ; 2*pi=6.2832
=1/((10+5)/2)
= 0.133
13
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
14
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
Arc: is part of circle but is needed start angle & end angle and distance of
center of arc to surrounding is same as.
Sector: is part of ellipse but contains two line; line1 from center to start
angle & other line from center to end angle & distance between center of
sector to surrounding is different as.
r a
r
Arc Sector b
r
The starting value is set equal to 𝜃1 and the ending value is set
equal to 𝜃2. The rest of the steps are similar to those used
when scan-converting a circle except that symmetry is not
used.
Sectors
A sector is scan-converting an arc and then scan-converting
two-lines from the center of the Arc to the endpoints of the
Arc.
Ex./ Assume that a sector whose center is at point (h,k) is to
be scan-converted.
- First scan-convert an Arc from 𝜃1 to 𝜃2 .
- Next a line would be scan-converted from (h,k) to (r
cos(𝜃1)+h, r sin(𝜃1)+k).
- A second line would be scan-converted from (h,k) to (r
cos(𝜃2)+h, r sin(𝜃2)+k).
15
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
Scan-converting a rectangle
Rectangle sides are parallel to the coordinates axes may be
constructed if the locations of two vertices are known. The
remaining corner points are then derived. If we have the
following rectangle.
y y (x2,y2)
(x1,y1)
(x1,y1)
(x2,y2)
x x
16
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
Chapter Six
6.1 Two Dimension(2D)- Transformations
One of the most common and important tasks in computer graphics is to
transform the coordinates ( position, orientation, size and shape ) of either
objects within the graphical scene or the camera that is viewing the scene. It is
also frequently necessary to transform coordinates from one coordinate system
to another, (e.g. world coordinates to viewpoint coordinates to screen
coordinates). All of these transformations can be efficiently and sufficiently
handled using some simple matrix representations, which we will see can be
particularly useful for combining multiple transformations into a single
composite transform matrix.
Representation of Points/Objects
A point p in 2D is represented as a pair of numbers: p= (x, y) where x is the x-
coordinate of the point p and y is the y-coordinate of p . 2D objects are often
represented as a set of points (vertices), {𝑝1, 𝑝2,..., 𝑝𝑛} . We can also write points
in vector/matrix as : p=(xy)
1
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
Consider a point P(x, y). we can translated it means shift it to new position p`(x`,
y`) by adding tx and ty in y where Tx and Ty are translating factor.
100 20 60 40 20 + 𝑡𝑥 60 + 𝑡𝑥 40 + 𝑡𝑥
T=[ ] , P=[ ] , P’=[ ]
10 0 0 100 0 + 𝑡𝑦 0 + 𝑡𝑦 100 + 𝑡𝑦
20 120
[ ] 10 [ ] 160
0 60 10 [ ]
[ ] 10
0
100 120 140 160
0 10 20 30 40 50 60 70 80 90 100
2
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
Let us assume that the original coordinates are (x, y), the scaling factors are (Sx ,
Sy ), and the produced coordinates are (x’, y’). This can be mathematically
represented as shown below :
The scaling factor Sx, Sy scales the object in x and y direction respectively. The
above equations can also be represented in matrix form as below.
𝑋′ 𝑆𝑥 0 𝑥
𝑃′ = 𝑆 . 𝑃 𝑂𝑅 ( ′) = [ 0 ] .
𝑆𝑦 𝑦) (
𝑌
3
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
Whenever the scaling process is performed there is one point still no change (same
position), this point is called fixed point of the scaling transformation. If the fixed
point at the origin, then the point (x,y) can be scaled by a scale factor Sx , Sy in the
x-axis and y-axis direction respectively to the new point (𝑥 ′ , 𝑦 ′ ).
The scaling is performed with respect to any point (xf, yf) as fixed point according to
the three steps:
1. We must first translate the object so that the fixed point is coincide with the
origin as follows: every object point (x, y) is moved to the new position (𝑥 ′ , 𝑦 ′ )
such as:
𝑥 ′ = 𝑥 − 𝑥𝑓 , 𝑦 ′ = 𝑦 − 𝑦𝑓
2. We then scaled these translated points by scale factors 𝑆𝑥 and 𝑆𝑦 ,so that :
𝑥 ′′ = 𝑥 ′ . 𝑆 𝑥 , 𝑦 ′′ = 𝑦 ′ . 𝑆𝑦
3. Then perform the inverse of the original translation to move the fixed point back
to its original position.
′
𝑥 ′′′ = 𝑥 ′ + 𝑥 𝑓 , 𝑦 ′′′ = 𝑦 ′′ + 𝑦𝑓
These three steps can be combined in the following equation that scales a point (xf,
yf). 𝑖. 𝑒 𝑡ℎ𝑒 𝑓𝑖𝑛𝑎𝑙 𝑒𝑞𝑢𝑎𝑡𝑖𝑜𝑛𝑠 𝑜𝑓 𝑠𝑐𝑎𝑙𝑖𝑛𝑔 𝑜𝑏𝑗𝑒𝑐𝑡 𝑎𝑏𝑜𝑢𝑡 𝑎𝑟𝑏𝑖𝑡𝑜𝑟𝑦 𝑝𝑜𝑖𝑛𝑡 𝑎𝑟𝑒:
𝒙′′′ = (𝒙 − 𝒙 𝒇 ) . 𝑺 𝒙 + 𝒙 𝒇 , 𝒚′′′ = (𝒚 − 𝒚 𝒇 ) . 𝑺 𝒚 + 𝒚𝒇
4
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
6.2.C) Rotations
You can rotate an object about the origin or about a pivot point.
It is possible to rotate one or more objects or the entire image about any
point in world space in either negative oriented a (clockwise) where angle is
negative oriented or positive oriented (Anti-clockwise) where angle is positive.
6.2.C.1) Rotate about the origin :
- Any point (x,y) can be represented by its radial distance (r) from
the origin and its angle ∅ of the x-axis.
x= r*cos(∅)
y=r*sin(∅) …….. (1)
- If (x,y) is rotated an angle 𝜃 in the Anti-clockwise direction. The
transformed point (𝑥̅ , 𝑦̅) is represented as:
𝑥̅ = 𝑟 ∗ cos(∅ + 𝜃)
𝑦̅ = 𝑟 ∗ sin(∅ + 𝜃)……. (2)
Equation (3) are the transformation that rotate a point an angle (𝜃)
about the origin in the Anti-clockwise direction.
To rotate an object each point defining that object must be
transformed using equation (3). The object is then drawn using the list
of transformed points.
5
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
̅ = 𝒙 cos(𝜽)+y sin(𝜽)
𝒙
̅ = −𝒙 sin(𝜽) + y cos (𝜽) …………(4)
𝒚
Equation (4) are the transformation that rotate a point an angle (𝜃)
about the origin in the clockwise direction.
6
Al-Mustansiriyah university
Computer Graphics 2018-2019 Education college
Third stage Computer science department
2. Rotate these translated points (𝑥̅ , 𝑦̅) 𝜃 degree about the origin to
obtain the new point (𝑥, ̿ 𝑦̿)
𝑥̿ = 𝑥̅ ∗ cos(𝜃 ) − 𝑦̅ ∗ sin(𝜃 )
𝑦̿ = 𝑦̅ ∗ cos(𝜃 ) + 𝑥̅ ∗ sin(𝜃 )
Substituting for 𝑥̅ and 𝑦̅
𝑥̿ = (𝑥 − 𝑥𝑝 ) ∗ cos(𝜃 ) − (𝑦 − 𝑦𝑝 ) ∗ sin(𝜃 )
𝑦̿ = (𝑦 − 𝑦𝑝 ) ∗ cos(𝜃 ) + (𝑥 − 𝑥𝑝 ) ∗ sin(𝜃 )
3. Translate the center of rotation back to the pivot point (𝑥𝑝 , 𝑦𝑝 )
𝑥̅̿ = 𝑥̿ + 𝑥𝑝
𝑦̿̅ = 𝑦̿ + 𝑦𝑝
𝑖. 𝑒
𝑥̅̿ =(𝑥 − 𝑥𝑝 ) ∗ cos(𝜃 ) − (𝑦 − 𝑦𝑝 ) ∗ sin(𝜃 ) + 𝑥𝑝
𝑦̿̅ =(𝑦 − 𝑦𝑝 ) ∗ cos(𝜃 ) + (𝑥 − 𝑥𝑝 ) ∗ sin(𝜃 )+ 𝑦𝑝