0% found this document useful (0 votes)
124 views35 pages

CSC314 Lecture 3 - Computer Graphics Maths Preliminaries

The document discusses key concepts in computer graphics including coordinate systems, vectors, matrices, and their applications. It explains how points, lines, and objects are defined using coordinates and vectors. Several important vector and matrix operations are also outlined that are useful for computer graphics techniques.

Uploaded by

KELVIN WAMBUI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views35 pages

CSC314 Lecture 3 - Computer Graphics Maths Preliminaries

The document discusses key concepts in computer graphics including coordinate systems, vectors, matrices, and their applications. It explains how points, lines, and objects are defined using coordinates and vectors. Several important vector and matrix operations are also outlined that are useful for computer graphics techniques.

Uploaded by

KELVIN WAMBUI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

CSC 314

Dr Almaz Yohannis

10/18/22 1
} Computer graphics is all about maths!
} None of the maths is hard, but we need to
understand it well in order to be able to
understand certain techniques
} Some of the Important concepts involve:
◦ Coordinate reference frames
◦ Points & lines
◦ Vectors
◦ Matrices

2
10/18/22
10/18/22 3
} When setting up a scene in computer
graphics we define the scene using simple
geometry
} For 2D scenes we use y axis
simple two dimensional
Cartesian coordinates y
P

} All objects are defined


using simple coordinate
pairs

x x axis

10/18/22 4
y

(2, 7) (7, 7)
7

3
(2, 3) (7, 3)

x
2 7

10/18/22 5
} For three dimensional scenes we simply add an extra coordinate

y axis

z
x

z axis x axis
10/18/22 6
} There are two different ways in which we can do 3D
coordinates – left handed or right handed

Left-Hand
Reference System

Right-Hand
Reference System For CSC 314 we use the RHS
10/18/22 7
} Points:
◦ A point in two dimensional space is given as an
ordered pair (x, y)
◦ In three dimensions a point is given as an ordered
triple (x, y, z)
} Lines:
◦ A line is defined using a start point
and an end-point
– In 2d: (xstart, ystart) to (xend, yend)

– In 3d: (xstart, ystart , zstart) to (xend, yend , zend)

10/18/22 8
y

(2, 7) (6, 7)

The line from


(2, 7) to (7, 3)
(2, 3) (7, 3)

(7, 1)

10/18/22 9
} The slope-intercept y

equation of a line is:


yend
y = m× x +b
} where:
yend - y0 y0
m=
xend - x0 x
x0 xend
} The equation of the line gives us the
corresponding y point for every x point
b = y0 - m × x0
10/18/22 10
} Let’s draw a portion of the line given by the
equation:
3 4
y = x+
5 5
} Just work out the y coordinate for each x
coordinate

10/18/22 11
y

0 1 2 3 4 5 6 7 8 9 10 x
10/18/22 12
For each x value just work out the y value:
3 4
y (2) = × 2 + = 2
5 5
3 4 3 y
y (3) = × 3 + = 2 5
5 5 5
3 4 1
y (4) = × 4 + = 3
5 5 5
3 4 4 2
y (5) = × 5 + = 3
5 5 5
3 4 2 x
y (6) = × 6 + = 4 2 3 4 5 6 7
5 5 5
3 4
y (7 ) = × 7 + = 5
5 5 10/18/22 13
} Vectors:
◦ A vector is defined as the difference between two
points
◦ The important thing is that a vector has a direction
and a length
} What are vectors for?
◦ A vector shows how to move from one point to
another
◦ Vectors are very important in graphics - especially
for transformations

10/18/22 14
} To determine the vector between two points
simply subtract them
P2 (7, 10)
y axis
V = P2 - P1
V P (6, 7) P2 (10, 7)
= ( x2 - x1 , y2 - y1 )
2

P1 (2, 6)
V V
= (6 - 1, 7 - 3)
P1 (1, 3) P1 (5, 3)
= (5, 4)
x axis

WATCH OUT: Lots of pairs of points share the same


vector between them 10/18/22 15
} In three dimensions a vector is calculated in
much the same way
y axis V = P2 - P1
= ( x2 - x1 , y2 - y1 , z 2 - z1 )
= (Vx , V y , Vz )
P2
So for (2, 1, 3) to (7, 10, 5)
we get

P1
= (7 - 2, 10 - 1, 5 - 3)
= (5,9,2)
z axis x axis
10/18/22 16
} There are a number of important operations
we need to know how to perform with
vectors:
◦ Calculation of vector length
◦ Vector addition
◦ Scalar multiplication of vectors
◦ Scalar product
◦ Vector product

10/18/22 17
} Vector lengths are easily calculated in two
dimensions:

| V |= V + V
x
2
y
2

} and in three dimensions:

| V |= V + V + V
x
2
y
2
z
2

10/18/22 18
} The sum of two vectors is calculated by
simply adding corresponding components
V1 + V 2 = (V1x + V2 x , V1 y + V2 y )
y axis y axis

V1 + V 2
V2 V2

V1
} Performed similarly in three dimensions
V1
x axis x axis

10/18/22 19
} Multiplication of a vector by a scalar proceeds
by multiplying each of the components of the
vector by the scalar

sV = ( sVx , sV y )
y axis y axis (sVx, sVy)

(Vx, Vy) sV

x axis x axis
10/18/22 20
} There are other important vector operations
that we will cover as we come to them
} These include:
◦ Scalar product (dot product)
◦ Vector product (cross product)

10/18/22 21
} A matrix is simply a grid of numbers
é 1 11 13 ù é 4 .3 ù
ê10 4 - 3ú ê 6 .7 ú é 4 8 15 ù
ê ú [1 2 3 4] ê ú ê16 23 42ú
êë 2 0 6 úû êë1.2 úû ë û

} However, by using matrix operations we can


perform a lot of the maths operations
required in graphics extremely quickly

10/18/22 22
} The important matrix operations for this
course are:
◦ Scalar multiplication
◦ Matrix addition
◦ Matrix multiplication
◦ Matrix transpose
◦ Determinant of a matrix
◦ Matrix inverse

10/18/22 23
} To multiply the elements of a matrix by a
scalar simply multiply each one by the scalar

éa b c ù és *a s *b s *c ù
s * êêd e f úú = êê s * d s * e s * f úú
êë g h i úû êë s * g s * h s * i úû
} Example:

é 2 4 6 ù é 6 12 18 ù
3 * êê 8 10 12úú = êê24 30 36úú
êë14 16 18úû êë42 48 54úû
10/18/22 24
} To add two matrices simply add together all
corresponding elements
éa b c ù ér s t ù éa + r b + s c+t ù
êd e f úú + êêu v wúú = êêd + u e + v f + wúú
ê
êë g h i úû êë x y z úû êë g + x h + y i + z úû
} Example:
é 2 4 6 ù é 3 5 7 ù é 5 9 13 ù
ê 8 10 12ú + ê 9 11 13ú = ê17 21 25ú
ê ú ê ú ê ú
êë14 16 18úû êë15 17 19úû êë29 33 37 úû

Both matrices have to be the same size 10/18/22 25


} We can multiply two matrices A and B
together as long as the number of columns in
A is equal to the number of rows in B
} So, if we have an m by n matrix A and a p by
q matrix B we get the multiplication:
} C=AB
} where C is a m by q matrix whose elements
are calculated as follows:
n
cij = å aik bki
k =1 10/18/22 26
} Examples:
é 0 - 1ù é0 *1 + (-1) * 3 0 * 2 + (-1) * 4ù é- 3 - 4ù
ê5 ú é1 2ù ê ú = ê 26 38 ú
ê 7 =
ú ê3 4ú ê 5 *1 + 7 * 3 5 * 2 + 7 * 4 ú ê ú
êë- 2 8 úû ë û êë - 2 *1 + 8 * 3 - 2 * 2 + 8 * 4 úû êë 22 28 úû
é 4ù
[1 2 3] êê5úú = [1* 4 + 2 * 5 + 3 * 6] = [32]
êë6úû
é 4ù é4 *1 4 * 2 4 * 3ù é4 8 12ù
ê5ú [1 2 3] = ê5 *1 5 * 2 5 * 3ú = ê5 10 15ú
ê ú ê ú ê ú
êë6úû êë6 *1 6 * 2 6 * 3úû êë6 12 18úû
10/18/22 27
} Watch Out! Matrix multiplication is not
commutative, so:
AB ¹ BA

10/18/22 28
} The transpose of a matrix M, written as MT
is obtained by simply interchanging the rows
and columns of the matrix
} For example:

Té1 4 ù
é1 2 3 ù ê2 5ú
ê 4 5 6ú = ê ú
ë û êë3 6úû

10/18/22 29
} There are some other important matrix
operations that we will explain as we need
them
} These include:
◦ Determinant of a matrix
◦ Matrix inverse

10/18/22 30
} In this lecture we have taken a brief tour
through the following:
• Basic idea
• The mathematics of points, lines and vectors
• The mathematics of matrices
} These tools will equip us to deal with the
computer graphics

10/18/22 31
} Plot the line y = ½x + 2 from x = 1 to x = 9
y

0 1 2 3 4 5 6 7 8 9 10 x
10/18/22 32
} Perform the following matrix additions:

[- 11 - 19 - 15 5] + [- 1 - 14 - 5 1] = [__ __ __ __ ]

é 3 20 - 11 0 ù é16 10 - 12 - 11ù é __ __ __ __ ù
ê- 14 5 - 3 6 ú ê10 - 15 15 5 ú ê __ __ __ __ úú
ê ú+ê ú=ê
ê 15 2 9 - 18ú ê- 1 14 -9 0 ú ê __ __ __ __ ú
ê ú ê ú ê ú
ë - 19 4 - 15 10 û ë 3 - 3 - 16 - 5 û ë __ __ __ __ û

é13 - 3 - 4ù é - 1 - 15 - 7 ù é __ __ __ ù
ê19 9 ú +ê ú =ê
ë 8 û ë- 14 5 17 û ë __ __ __ úû
10/18/22 33
} Perform the following matrix multiplications:
é - 15 19 ù
ê ú
é8 15 19 4ù ê- 12 - 19ú é __________ __________ ù é __ __ ù
ê7 - 4 12 3ú * ê 0 =ê ú =ê
ë û - 13ú ë __________ __________ û ë __ __ úû
ê ú
ë 10 7 û

é16 10 - 12 - 11ù é 4 ù é _________________ ù é __ ù


ê10 - 15 15 5 ú ê11ú ê _________________ ú ê __ ú
ê ú*ê ú = ê ú=ê ú
ê- 1 14 -9 0 ú ê 6 ú ê _________________ ú ê __ ú
ê ú ê ú ê ú ê ú
ë 3 - 3 - 16 - 5 3
û ë û ë _________________ û ë __ û

10/18/22 34
} Perform the following multiplication of a matrix by
a scalar

é15 19 ù é __ __ ù
ê 2 5 ú ê __ __ ú
6* ê ú=ê ú
ê 0 - 1ú ê __ __ ú
ê ú ê ú
ë 1 7 û ë __ __ û
} Calculate the transpose of the following matrix
T
é 3 11ù
ê 6 4 ú = é __ __ __ ù
ê ú ê __ __ __ úû
êë23 7 úû ë

10/18/22 35

You might also like