Note 4
Note 4
Sourav Pramanik
Assistant Professor, New Alipore College
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
an extra coordinate
y axis
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
Line Drawing Algorithm
Programmer specifies (x, y) values of
end pixels.
Need algorithm to figure out which
intermediate pixels are on line path. 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
12
of
30
The Equation of A Line
13
of
30
A Simple Example
Example 1 The endpoints of line are(0,0) & (6,18).
Compute each value of y as x steps from 0 to 6 and plot
the result.
Solution : Equation of line is y= mx +b
m = y2-y1/x2-x1= 18-0/6-0 = 3
Next the y intercept b is found by plugging y1& x1 into the
equation y = 3x + b,
0 = 3(0) + b. Therefore, b=0, so the equation for the line
is y= 3x.
14
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
15
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
16
of
30
12
10
0 2 4 6 8 10 12 14 16 17 18 x
18
of
DDA (Digital Differential Analyzer)
30
Algorithm
x y
2 2
3 2
4 2
5 2
6 2
7 2
8 2
9 2
19
of
DDA (Digital Differential Analyzer)
30
Algorithm
x y
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
20
of
DDA (Digital Differential Analyzer)
30
Algorithm
x y
5 4 4
6 4.4 4
7 4.8 5
8 5.2 5
9 5.6 6
10 6 6
11 6.4 6
12 6.8 7
21
of
DDA (Digital Differential Analyzer)
30
Algorithm
X y
5 5 7
6 5.6 8
6 6.2 9
7 6.8 10
7 7.4 11
8 8 12
9 8.6 13
9 9.2 14
10 9.8 15
22
of
DDA (Digital Differential Analyzer)
30
Algorithm
x y
23
of
DDA (Digital Differential Analyzer)
30
Algorithm
24
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
25
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)
( x2 x1 , y2 y1 )
2
P1 (2, 6)
(6 1, 7 3)
V 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
27
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
28
of
30
Vector Operations: Vector Length
Vector lengths are easily calculated in two
dimensions:
| V | V V
x
2
y
2
| V | Vx2 V y2 Vz2
29
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
31
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)
32
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
35
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 ct
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
40
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
41
of
30
Pixel
• Pixels are the basic building block of
graphics display.
• We can call it Picture Element.
• The pixel is a smallest size object or color
spot that can be displayed and addressed
on a screen.
• Any image that is displayed on the
monitor is made up of thousands of
pixels.
42
of
30
Dot
• The internal surface of the monitor screen
is coated with Red, Green, Blue phosphor
material. That glows when struck by the
stream of electrons.
• The coated material is arranged into an
array of millions of tiny cells.
• Red, Green, Blue.- these colored cells are
usually called dots.
43
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
44
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
45
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 __ __ __
46
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
16 10 12 11 4 _________________ __
10 15 15 5 11 _________________ __
*
1 14 9 0 6 _________________ __
3 3 16 5
3 _________________ __
47
of
30
Exercises 4
Perform the following multiplication of a
matrix by a scalar
15 19 __ __
2 5 __ __
6*
0 1 __ __
1 7 __ __