Presentation is loading. Please wait.

Presentation is loading. Please wait.

COM366 Interactive Computer Graphics Topic 1 : Introduction.

Similar presentations


Presentation on theme: "COM366 Interactive Computer Graphics Topic 1 : Introduction."— Presentation transcript:

1 COM366 Interactive Computer Graphics Topic 1 : Introduction

2 COM366 Y X (2,2) N1N1 N2N2 N3N3 N4N4 (2,-2) (-2,-2) (-2,2) A simple data structure

3 COM366 plot(X,Y) Drawing a line in Matlab (-1,-2) (3,4) X = [ -1 3]Y = [ -2 4]

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

5 COM366 The line drawn

6 COM366 plot(X,Y,'Color','red','LineWidth',2) Changing the appearance of the line XY -2 2 22 2 Column vectors for drawing the square

7 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) N1N1 N2N2 N3N3 N4N4 (-2,2) -2, -2 2, 2 2, -2 -2, -2 Column 1 Row 3

8 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

9 COM366 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; Drawing the square

10 COM366 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) Alternative ways of drawing the square Using ‘patch’Using ‘fill’

11 COM366 patch(x-coordinates,y-coordinates,[z-coordinates],colordata) Drawing in three dimensions

12 COM366 The viewing pipeline Data Model Application Program Application Program Software Primitives Software Primitives Hardware Primitives & Device control Hardware Primitives & Device control Display

13 COM366 PrimitiveFunction 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 CameraNot 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. CamlookatPosition the camera to view an object or group of objects

14 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 180 o So for example 45 o is 45 * pi/180 radians

15 COM366 function Circle(R); %Draws a circle centred on the origin of radius R t = 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…..

16 COM366


Download ppt "COM366 Interactive Computer Graphics Topic 1 : Introduction."

Similar presentations


Ads by Google