Computer Graphics Andreas Savva Lecture Notes 1. 2 Computer Graphics Definition Computer Graphics is...
-
Upload
joshua-bennett-ryan -
Category
Documents
-
view
237 -
download
2
Transcript of Computer Graphics Andreas Savva Lecture Notes 1. 2 Computer Graphics Definition Computer Graphics is...
2
Computer GraphicsComputer Graphics
Definition
Computer Graphics is concerned with all aspects of producing pictures or images using a computer.
3
Rabbit ChangeRabbit Change
1960s1960sDisplay of data on hardcopy plotters and cathode ray tube (CRT) screens.
TodayTodayCreation, storage, and manipulation of models and images of objects. These models include physical, mathematical, engineering, architectural, conceptual (abstract) structures, natural phenomena, etc.
4
Interactive Computer GraphicsInteractive Computer GraphicsToday Computer Graphics are largely interactive:
the user control the contents, structure, and appearance of objects and their displayed images by using input devises.
5
CG Vs Image ProcessingCG Vs Image ProcessingUntil recently they have been quite separate disciplines. However, the overlap between the two is growing.
Computer Graphics task:to synthesize pictures and images on the basis of some description, or model, in a computer.
Image (Picture) Processing task:to reconstruct models of 2D or 3D objects from their pictures.to improve or alter images that where created elsewhere (digitized from photographs or captured by a video recorder).
6
Examples of Image ProcessingExamples of Image Processing
aerial photographsX-ray imagescomputerized axial tomography (CAT) scansfingerprint analysisimproving image quality by eliminating noise (extraneous or missing pixel data) or by enhancing contrastscan images, typewritten or even hand-printed charactersreconstruction of 3D models from several 2D images
7
History of Computer GraphicsHistory of Computer Graphics1960
The first computer graphics software “Sketchpad” was created by Evan Sutherland on his doctoral thesis at MIT.A graph could be drawn on a digital computer. The computer had its own air-conditioning environment and it read in its program and data from hole punched paper tapes and output the results either to tape or a plotter. The capital cost of the equipment was about £1M + running cost.Most applications were scientific, pure research funded by governments, universities, the army and international corporations, with no thought of recovering the cost of development.There were rabid advances in display technology and in the algorithms used to manage pictorial information.
1970Large corporations like Fort, Boeing and General Motors could draw drafting productivity improvements of their products and costs were recovered in about 3 years.Random-scan graphics displays used were very expensive.Computer graphics was a small specialized field, because the hardware was still expensive and there were not any easy-to-use and cost-effective graphics-based application programs.
8
History (continue)History (continue)1980 - Today
After the production of low-cost personal computers with build-in raster graphics displays, easy-to-use and inexpensive graphics-based applications such as the Xerox Star and later the mass-produced, even less expensive Apple Macintosh and IBM PC and its clones followed, which made good quality high-speed graphics available to all.Computer technology is rapidly spreading in all areas because the hardware/software system “pays for itself” by
speeding up operations significantly increasing productivitygiving organizations a competitive edge
The direct-view storage tube greatly reduced the capital cost, and modern high-resolutions raster displays have made good quality high-speed graphics available to ALL.Today, it is hard to find an area of human activity for which there are no Computer Graphics applications, i.e.
games, photography, animation, newspaper, Magazine, television, scientific research, computer-aided design and manufacture, image enlargement. Charting, e-commerce.
9
Applications of Computer GraphicsApplications of Computer GraphicsScienceEngineeringMedicineBusinessIndustry & GovernmentArtCAD (cars, airplanes)Cinema and TVAdvertisingEducation & TrainingFlight simulatorsSpace explorationEntertainmentComputer Interfacese-CommerceHome
0
10
20
30
40
50
60
70
80
90
Winter Spring Summer Automn
10
Why are graphics so popular?Why are graphics so popular?
A picture is worth ten thousand words.
A moving picture (animation) is worth ten thousand static ones.
11
Mathematical BackgroundMathematical Background
Pythagoras theorem
Trigonometry
Natural logarithms
Coordinate geometry
Matrices
Differentiation
12
MatricesMatrices Applications in many areas Rectangular array – 2D array
Size
Colour
small medium large Xlarge
Black 60 100 150 120
White 25 48 60 10
Gray 100 93 140 170
Navy 75 94 140 170
Red 80 80 60 0
0608080
1701409475
806093100
10604825
12015010060
13
DefinitionsDefinitions
A matrix is a rectangular array of elements (usually numbers) arranged in rows and columns enclosed in brackets.
d
c
b
a
CBA
213
532
042
20
41
21
Order of the matrix is the number of rows and columns. A is a 3×2 matrix, B is a 3×3 matrix C is a 4×1 matrix .
Matrices are denoted by capital letters while their elements are written as lower case letters as in example C above.
We refer to a particular element by using notation that refers to the row and column containing the element, i.e. a21=-1, b32 = 1, c21 = b.
Two matrices A and B are said to be equal, written A = B, if they have the same order and aij = bij for every i and j.
14
ExercisesExercises1. Write the elements d23 and d42 of matrix D.
2. Find x, y, and z so that
3. Write down the 3×4 matrix A, where
060808017014094758060931001060482512015010060
D
zyz
zy
yxy
zx
6218
6
26
232
otherwise 2
if if 0
jijiji ji
aij
15
Type of MatricesType of MatricesSquare matrix – a matrix with an equal number of rows and columns.
Diagonal matrix – a square matrix with zeros everywhere except down the leading diagonal.
Unit matrix (identity matrix) – a diagonal matrix with ones down the leading diagonal. The identity matrix is denoted with the letter I.
matrixunit 33 a is 100010001
3
I
matrix diagonal 33 a is 900050001
A
matrix square 33 a is 987654321
A
16
Type of Matrices (continue)Type of Matrices (continue)
Zero matrix – a matrix with zeros everywhere, denoted by O.
Symmetric matrix – a square matrix whose (ij)th element is the same as the (ji)th element for all i and j.
Row matrix (row vector) – a matrix with only one row, i.e. its order is 1×m.
Column matrix (column vector) – a matrix with only one column, i.e. an n×1 matrix.
matrix symmetric a is 374725451
A
17
Matrix Addition and SubtractionMatrix Addition and Subtraction
If A and B are two n×m matrices then– their sum C = A + B is the n×m matrix with
cij = aij + bij
– their difference C = A - B is the n×m matrix with
cij = aij - bij
1024
172
7)3()3()1()2(2
432)5(31
732
423
312
351
440
734
7)3()3()1()2(2
432)5(31
732
423
312
351
Examples:Examples:
18
Scalar Multiplication of MatricesScalar Multiplication of Matrices
If A is an n×m matrix and k is a real number, then the scalar multiple C = kA is the n×m matrix where cij = kaij .
1464
846
72)3(2)2(2
422232
732
4232
19
The Transpose of a MatrixThe Transpose of a Matrix
If A is a matrix then the transpose of A is the matrix At where at
ij = aji.
312412023121
A
340111222231
tA
20
Matrix MultiplicationMatrix Multiplication
If A is an n×m matrix and B is an m×p matrix then the product of A and B, C = AB, is an n×p matrix
Cij = (row i of A) × (column j of B)
= ai1b1j + ai2b2j + ai3b3j + … ainbjp
232333
45
214
83
02)2(041)3(23011
01)2()3(4)2()3(13)3(1)2(
04)2(243)3(43213
03
23
41
201
132
423
21
PropertiesPropertiesIf a, b are scalars and A, B, C are matrices of the same dimension (order) then
A + B = B + A
A + (B + C) = (A + B) + C
a(bA) = (ab)A
(a + b)A = aA + bA
a(A + B) = aA + aB
a(A - B) = aA - aB
A + OA = A, and aO = O
(A + B)t = At + Bt
(A - B)t = At - Bt
22
PropertiesPropertiesIf a, b are scalars and A, B, C are matrices of the same dimension (order) then assuming that the matrix dimensions are such that the products in each of the following are defined, then we have:
AB ≠ BAA(BC) = (AB)C(A + B)C = AC + BCA(B + C) = AB + ACOA = O, AO = O(aA)(bB) = abABIA = AI = A(AB)T = BTAT
23
Inverse of a 2Inverse of a 2×2 Matrix×2 MatrixNot all Matrices have an inverse.
The Determinant – determines if a matrix has an inverse or not. If the determinant of a matrix A is zero then the matrix has no inverse.
bcadAAdcba
A
det
11)1(342det 4132
AAA
Example:Example:
24
Inverse of a 2Inverse of a 2×2 Matrix×2 Matrix
If A is a matrix then it is possible to find another matrix, called A-1, such that AA-1 = I or A-1A = I .
acbd
AA
dcba
A1
1
112
111
113
114
1
2134
11
1
4132
AA
Example:Example:
25
Solution of Systems ofSolution of Systems ofSimultaneous EquationsSimultaneous Equations
41132
yxyx
411
1132
yx
AA xx = = bb
Ax = b A-1Ax = A-1b x = A-1b
27
ExercisesExercises
1. A + B
2. B – A
3. AB
4. BA
5. AI
6. IA
01321322
2134
4321
CBA
Consider the above matrices and complete the following operations:
7. BC
8. CB
9. C(A + B)
10. BCt
11. (AB)t
12. At Bt
28
ExercisesExercises Solve the following pairs of simultaneous
equations using matrices.
37742935
yxyx
1353226
yxyx
8231
yxyx
25.0575.264
yxyx
7236
yxyx
752
yxyxa)
b)
c)
d)
e)
f)
29
Inverse of a 3Inverse of a 3×3 matrix×3 matrix
1
:t determinan theFrom
)()(det
333231
232221
1312111
333231
232221
131211
aaaaaa
aaa
AA
bdaeebda
abgahhbga
aegdhhegd
a
cdaffcda
acgaiicga
afgdiifgd
a
cebffceb
achbiichb
afheiifhe
a
A
afhbdicegcdhbfgaeiAA
ifchebgda
Aihgfedcba
A
t
t
30
Inverse of a 3Inverse of a 3×3 matrix (example)×3 matrix (example)
444433437
4
1
43111
44101
44301
44011
33001
33401
44031
33041
73443
:t determinan theFrom
4139)3160()009(det
340431011
340431011
1
333231
232221
131211
A
aaa
aaa
aaa
A
AA
AA
t
t
31
ExercisesExercises
1. Find the inverse of the following matrix:
2. Solve the following simultaneous equations using matrices.
102
212
123
A
623
433
52
zyx
zyx
zyx
32
Row OperationsRow Operations
Solve any system of equations (that has a solution)Find the inverse of an n×n matrix
RulesRules1.1. Can interchange any two rows of a matrix.Can interchange any two rows of a matrix.2.2. Can replace any row by a non zero multiple Can replace any row by a non zero multiple
of the same row.of the same row.3.3. Can replace any row by the sum of that row Can replace any row by the sum of that row
and a multiple ofand a multiple of some other row.some other row.
33
Row OperationsRow OperationsSolve the system of equations
232
2
yx
yx
2
2
32
11
y
x
SolutionSolution::
By using the rules transform the matrix into the form
232
211
k
h
10
01ky
hx
k
h
y
x
10
01
34
SolutionSolution
232
211
210
211
RR22 = = rr22 – 2 – 2rr11
210
401
RR11 = = rr11 + + rr22
210
211
RR22 = - = -rr22
2
4
y
x
35
Algorithm Algorithm nn××nn
1321
31333231
21232221
111131211
nnmnnn
m
baaaa
baaa
baaa
baaaa
110000
00
1111
11
000000
00
0000
00
00
00bbcc
dd
aa
36
1123
423
6
zyx
zyx
zyx
1121341236111
Solve the system of equations:
7120144106111
RR22 = = rr22 – 3 – 3rr11
RR33 = = rr33 – 3 – 3rr11
7120144106111
RR22 = (-1) = (-1)rr22
2170014410
8301
RR11 = = rr11 – – rr22
RR33 = = rr33 + 2 + 2rr22
310014410
8301
RR33 = = rr33 / 7 / 7
310020101001
RR11 = = rr11 + 3 + 3rr33
RR22 = = rr22 - 4 - 4rr33
xx = 1, = 1, yy = 2, = 2, zz = 3 = 3
37
There is always a solution?There is always a solution?
4
8
3
4100
8010
3001
3
2
1
x
x
x
1000
1210
0301 Third row:Third row:0x1 + 0x2 + 0x3 = -1 or 0 = -1 meaningless, so the system has no solution
43100
21010
52001
43
42
41
43
42
41
34
2
25
or
43
2
52
xx
xx
xx
xx
xx
xx
Thus the system hasinfinitely many solutions
38
ExercisesExercises
332524232
zyxzyxzyx
1. Solve the system of equations:
a)a)
11232322222832
wzyxwzyxwzyx
wzyxb)b)
2. Find a matrix A such that:
0112
1210
A
2. For what number x will the following be true?
07420201012
14
45
xx
39
Finding the InverseFinding the Inverse using the row operation using the row operation
1012
A
1001
1012
i.e. 1
dcba
IAA
10100112
| 2IA
RR11 = = rr1 1 / 2/ 2
101001 2
121
RR11 = = rr11 - (1/2) - (1/2) rr22
101001 2
121
1 11 2 2
0 1A
40
ExampleExample
Find the inverse of the matrix
221012211
A
100221010012001211
RR22 = = rr22 - 2 - 2rr11
RR33 = = rr33 - - rr11
101010012410001211
RR22 = - = -rr22
1 1 2 1 0 0
0 1 4 2 1 0
0 1 0 1 0 1
RR11 = = rr11 - - rr22
RR33 = = rr33 – –rr22
1 0 2 1 1 0
0 1 4 2 1 0
0 0 4 3 1 1
41
Example (continue)Example (continue)
RR33 = (-1/4) = (-1/4)rr33
3 1 14 4 4
1 0 2 1 1 0
0 1 4 2 1 0
0 0 1
RR11 = = rr1 1 + 2+ 2rr33
RR22 = = rr22 - 4 - 4rr33
41
41
43
21
21
21
100101010
001
41
41
43
21
21
21
1 101 A
VerifyVerify::AA-1 = I3
42
ExercisesExercises
Find the inverse of the following matrices using the row operations method:
102312122
B
0321110113122112
C
1432
A
43
DimensionDimension of a Space of a Space
is the amount of freedom of movement that objects within the space have.
0D0D
2D2D y
x
3D3D y
xz
1D1D
x
44
3D Coordinate Systems3D Coordinate Systems
y
x
z
y
x
z
Right-handed system(z comes out)
Left-handed system(z goes in)
45
DistanceDistance
221
22121 )()(),( yyxxPPd
1D1DP1 P2
2D2D y
x
3D3D y
xz
2121 ),( xxPPd
221
221
22121 )()()(),( zzyyxxPPd
P1
P2
P1
P2
48
Equation of a circle at (0,0)Equation of a circle at (0,0)
222 ryx
Cartesian formCartesian form Polar formPolar form
rSiny
rCosx
(0, 0)
r
(x,y)
49
Equation of a circle at (Equation of a circle at (xxc c ,y,ycc))
222 )()( ryyxx cc
r(xc,yc)
r
(x,y)
Cartesian formCartesian form Polar formPolar form
c
c
yrSiny
xrCosx
50
ExercisesExercises
1. Find the equation of the straight line which passes from the two points (2,8) and (8,26).
2. Draw the graph y = x3 – x.3. Draw the graph y = x / (x2 – 1).4. Find the Cartesian coordinates x, y for the circle
with center (0,0) and radius 4, when = 0º, 45º, 90º, 150º, 215º, and 340º.
5. Find the Cartesian coordinates x, y for the circle with center (4,3) and radius 10, when = 30º, 190º, and 325º.
6. Find the radius of the circle with center (4,6) and passes from point (-2,10).
51
Positions (Positions (pointspoints) & Directions () & Directions (vectorsvectors))
A vector is the difference between two points, i.e.vector = point2 – point1
v = P2 – P1 = (4, 3, 1) – (2, 1, 2) = (2, 2,-1)
point2 = point1 + vector
P2 = P1 + v = (2, 1, 2) + (2, 2,-1) = (4,3,1)
y
z
v=(x,y,z)=(2,2,-1)
xP1=(2,1,2)
P2=(4,3,1)
52
Addition of VectorsAddition of Vectors
v1 = (x1, y1, z1)
v2 = (x2, y2, z2)
v1 + v2 = (x1 + x2 , y1 + y2 , z1 + z2)
(0, 0, 0)
(x2, y2, z2)
(x1, y1, z1)
(x1+x2, y1+y2, z1+z2)
53
Scalar multiplication of VectorsScalar multiplication of Vectors
),,( zyxv
v2v
(-1)v(1/2)v
Vector additionVector addition
v
w
v+w v
-w
v-w
Vector differenceVector differencev + w = v + (-w)
P
O
OPVector
54
Length of a vectorLength of a vector
222|| zyxv
Norm of a vectorNorm of a vector
|| oflength
vector )(norm
v
v
v
vv
Only interested on the direction and not in its length.So norm(v) has the same direction but length 1.
55
Inner (dot) product of two vectorsInner (dot) product of two vectorsThe dot-product, denoted by v1 · v2 , is the angular relationship between two vectors:
Normalizing each of the vectors v1 and v2 and then take the dot-product of the normalized vectors we find which is the angle between the two vectors.
The dot product of a unit length vector with itself is 1.
Vectors that are perpendicular to one another (called orthogonal) have a zero dot product.
21212121 zzyyxxvv
11 2 1 2
1 2 1 2
cos cos| | | | | | | |
v v v v
v v v v
56
ExerciseExerciseFind the angle between vectors (3,7) and (-4,5).
y
x
(-4,5) (3,7)
1 11 2
1 2
1 1
12 35cos cos
| | | | 58 41
23cos cos 0.472 61.86
48.765
v v
v v
57
The cross-product, denoted by v1 × v2 , is the vector:
v1×v2 is orthogonal to both v1 and v2, i.e. v1 and v2 form a plane and their cross product is normal to that plane.
How to remember the formula:
Vector cross-productVector cross-product
) , ,( 12212112122121 yxyxzxzxzyzyvv
v1
v2
v1×v2
1221
1221
1221
21
21
21
)( yxyxzxzx
zyzy
zzyyxx
v1
v2
-v1×v2 = v2×v1
Properties:Properties:
sin|||||| 2121
1221
vvvv
vvvv
58
Spherical coordinatesSpherical coordinates
P
r
y
x
z
r is the radial distance of P from the origin (latitude) is the angle that P makes with the xz-plane. -/2 ≤ < /2 (azimuth) is the angle between the xy-plane and the plane through P and the y-axis. 0 ≤ < 2
Px= r cos cos
Py= r sin
Pz= r cos sin
59
Spherical coordinatesSpherical coordinates
222zyx PPPr
r
Py1sin
0 and 0 if
0 and 0 if
0 if tan
0 if tan
2
2
1
1
y x
y x
x
x
x
z
x
z
PP
PP
Cartesian coordinatesCartesian coordinates
(Px, Py, Pz)
Spherical coordinatesSpherical coordinates(r, , )
60
ExercisesExercises
1. Suppose that P is at a distance 2 from the origin, it is 60° up from the xz-plane and it is along the negative x-axis. Find P in Cartesian coordinates.
2. Convert the point (x, y, z) = (2, 4, -3) to spherical coordinates.
3. Convert the point (r, , ) = (5, 35°, -67°) to Cartesian coordinates.