Professional Documents
Culture Documents
Maths Preliminaries
Cartesian coordinates
All objects are defined
using simple coordinate
pairs x x axis
5
of
Coordinate Reference Frames – 2D
30 (cont…)
(2, 7) (7, 7)
7
3
(2, 3) (7, 3)
x
2 7
6
of
30
Coordinate Reference Frames – 3D
For three dimensional scenes we simply add
z
x
z axis x axis
7
of
30
Left Handed Or Right Handed?
There are two different ways in which we
Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)
Right-Hand Left-Hand
Reference System Reference System
8
of
30
Points & Lines
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)
9
of
30
Points & Lines (cont…)
y
(2, 7) (6, 7)
(7, 1)
x
10
of
30
The Equation of A Line
The slope-intercept y
where:
yend − y0 y0
m=
xend − x0 x
x0 xend
b = y0 − m ⋅ x0
The equation of the line gives us the
corresponding y point for every x point
11
of
30
A Simple Example
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
12
of
30
A Simple Example (cont…)
0 1 2 3 4 5 6 7 8 9 10 x
13
of
30
A Simple Example (cont…)
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
14
of
30
Vectors
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
15
of
30
Vectors (2D)
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)
2
= ( x2 − x1 , y2 − y1 )
P1 (2, 6)
V
= (6 − 1, 7 − 3)
V
P1 (1, 3) P1 (5, 3)
= (5, 4)
x axis
P1
= (7 − 2, 10 − 1, 5 − 3)
= (5,9,2)
z axis x axis
17
of
30
Vector Operations
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
18
of
30
Vector Operations: Vector Length
Vector lengths are easily calculated in two
dimensions:
| V |= V + V
x
2
y
2
| V |= V + V + V
x
2
y
2
z
2
19
of
30
Vector Operations: Vector Addition
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 + V2
V2 V2
V1
V1
x axis x axis
(Vx, Vy) sV
x axis x axis
21
of
30
Other Vector Operations
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)
22
of
30
Matrices
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
Example: 2 4 6 6 12 18
3 * 8 10 12 = 24 30 36
14 16 18 42 48 54
25
of
30
Matrix Operations: Addition
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
T 1 4
1 2 3 2 5
4 5 6 =
3 6
30
of
30
Other Matrix Operations
There are some other important matrix
operations that we will explain as we need
them
These include:
– Determinant of a matrix
– Matrix inverse
31
of
30
Summary
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 techniques that we will
begin to look at, starting next time
32
of
30
Exercises 1
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
33
of
30
Exercises 2
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 __ __ __
34
of
30
Exercises 3
Perform the following matrix multiplications:
− 15 19
8 15 19 4 − 12 − 19 __________ __________ __ __
7 − 4 12 3 * 0 = =
− 13 __________ __________ __ __
10 7