Title: COM366
1COM 366 Interactive Computer Graphics Topic 1
Introduction
COM366
2A simple data structure
COM366
3Drawing a line in Matlab
(3,4)
X -1 3
Y -2 4
(-1,-2)
plot(X,Y)
COM366
4Drawing a line with MATLAB
function LineDemo To draw a single line First
of all define the two node vectors X -1 3 Y
-2 4 Draw the line plot(X,Y) Set the
limits to the axes and ensure they are of equal
dimension axis(-5,5,-5,5) axis square
COM366
5The line drawn
COM366
6Changing the appearance of the line
plot(X,Y,'Color','red','LineWidth',2)
Column vectors for drawing the square
X Y
-2 -2
-2 2
2 2
2 -2
-2 -2
COM366
7Combining the X and Y arrays
Column 1
(-2,-2) ? (-2,2) (-2,2) ? (2,2) (2,2) ?
(2,-2) (2,-2) ? (-2,-2)
-2, -2 -2, -2 2, 2 2, -2 -2, -2
(2,-2)
(-2,-2)
Row 3
Node -2 -2 -2 2 2 2 2 -2-2 -2
COM366
8A useful Matlab convention
Node -2 -2 -2 2 2 2 2 -2-2 -2
Node(,1)
Means take ALL rows from column 1 of array node
Node(3,)
Means take ALL columns from row 3 of array node
Node(1..3,1)
Means take rows 1 to 3 from column 1 of array
node
COM366
9Drawing the square
function Drawsquare To draw a square using
nodes First of all define the nodes Node -2
-2 -2 2 2 2 2 -2-2 -2 Draw the
square plot(Node(,1),Node(,2)) axis(-5,5,-5,5)
axis square
COM366
10Alternative ways of drawing the square
Using patch
Using fill
function Drawsquare2 To draw a square using
patch First of all define the nodes Node -2
-2 -2 2 2 2 2 -2 Draw the
square patch(Node(,1),Node(,2),'red') axis(-5,5
,-5,5) axis square
fill(Node(,1),Node(,2),C)
COM366
11Drawing in three dimensions
patch(x-coordinates,y-coordinates,z-coordinates,
colordata)
COM366
12The viewing pipeline
COM366
13COM366
14Degrees and radians
Most computer languages (including Matlab) like
to use angles in Radians in their trigonometric
functions like sine and cosine
- We normally like to think in degrees. Fortunately
the conversion is - easy if you remember that
- Radians is equivalent to 180o
- So for example 45o is 45 pi/180 radians
COM366
15Adding a circle primitive
function Circle(R) Draws a circle centred on
the origin of radius R t 0pi/362pi x
Rsin(t) y Rcos(t) fill(x,y,'w') axis square
pi is the Matlab convention for ? 3.1416..
COM366
16COM366