Upload
griselda-wright
View
221
Download
0
Embed Size (px)
DESCRIPTION
COM366 plot(X,Y) Drawing a line in Matlab (-1,-2) (3,4) X = [ -1 3]Y = [ -2 4]
Citation preview
COM366
COM 366
Interactive Computer Graphics
Topic 1 : Introduction
COM366
Y
X
(2,2)
N1
N2
N3
N4
(2,-2)(-2,-2)
(-2,2)
A simple data structure
COM366
plot(X,Y)
Drawing a line in Matlab
(-1,-2)
(3,4)
X = [ -1 3] Y = [ -2 4]
COM366
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;
Drawing a line with MATLAB
COM366
The line drawn
COM366
plot(X,Y,'Color','red','LineWidth',2)
Changing the appearance of the line
X Y
-2 -2
-2 2
2 2
2 -2
-2 -2
Column vectors for drawing the square
COM366
Combining the X and Y arrays
Node = [-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)
Y
X
(2,-2)(-2,-2)
(2,2)
N1
N2N3
N4
(-2,2)-2, -2
-2, -2
2, 2
2, -2
-2, -2
Column 1
Row 3
COM366
A 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
function Drawsquare;%To draw a square using nodes%First of all define the nodesNode = [-2 -2; -2 2; 2 2; 2 -2;-2 -2];%Draw the squareplot(Node(:,1),Node(:,2))axis([-5,5,-5,5]);axis square;
Drawing the square
COM366
function Drawsquare2;%To draw a square using patch%First of all define the nodesNode = [-2 -2; -2 2; 2 2; 2 -2];%Draw the squarepatch(Node(:,1),Node(:,2),'red')axis([-5,5,-5,5]);axis square;
fill(Node(:,1),Node(:,2),C)
Alternative ways of drawing the square
Using ‘patch’ Using ‘fill’
COM366
patch(x-coordinates,y-coordinates,[z-coordinates],colordata)
Drawing in three dimensions
COM366
The viewing pipeline
Data ModelApplication
ProgramSoftware
PrimitivesHardware
Primitives &Device control
Display
COM366
Primitive Function
Plot(X,Y,props) Draw a graph of the object defined by the X,Y vectors using a particular set of properties – line colour, thickness etc.
Subplot(m,n,p) Allows you to display m rows and n cols of sub plots in a single window. p is the current plot to be drawn.
Fill(X,Y,C) Fill a polygon defined by X and Y with colour C
Patch(X,Y,Z,C) Creates a patch in 3D defined by the colour C. C can in fact be quite sophisticated allowing shading across the patch
Camera Not really a primitive as such but gives access to a huge range of properties to configure the viewing of a 3D object
Light(props) Creates all the properties of a light source to view a scene.
Camlookat Position the camera to view an object or group of objects
COM366
Degrees 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
function Circle(R);%Draws a circle centred on the origin of radius Rt = 0:pi/36:2*pi;x = R*sin(t);y = R*cos(t);fill(x,y,'w')axis square
Adding a circle primitive
pi is the Matlab convention
for = 3.1416…..
COM366