Presentation is loading. Please wait.

Presentation is loading. Please wait.

Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.

Similar presentations


Presentation on theme: "Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for."— Presentation transcript:

1 Representation

2 Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for representing affine spaces Discuss change of frames and bases Introduce homogeneous coordinates

3 Linear Independence A set of vectors v 1, v 2, …, v n is linearly independent if  1 v 1 +  2 v 2 +..  n v n =0 iff  1 =  2 =…=0 If a set of vectors is linearly independent, we cannot represent one in terms of the others If a set of vectors is linearly dependent, as least one can be written in terms of the others

4 Dimension In a vector space, the maximum number of linearly independent vectors is fixed and is called the dimension of the space In an n-dimensional space, any set of n linearly independent vectors form a basis for the space Given a basis v 1, v 2,…., v n, any vector v can be written as v=  1 v 1 +  2 v 2 +….+  n v n where the {  i } are unique

5 Representation Until now we have been able to work with geometric entities without using any frame of reference, such as a coordinate system Need a frame of reference to relate points and objects to our physical world.  For example, where is a point? Can’t answer without a reference system  World coordinates  Camera coordinates

6 Coordinate Systems Consider a basis v 1, v 2,…., v n A vector is written v=  1 v 1 +  2 v 2 +….+  n v n The list of scalars {  1,  2, ….  n } is the representation of v with respect to the given basis We can write the representation as a row or column array of scalars a=[  1  2 ….  n ] T =

7 Example v=2v 1 +3v 2 -4v 3 a=[2 3 –4] T Note that this representation is with respect to a particular basis For example, in OpenGL we start by representing vectors using the object basis but later the system needs a representation in terms of the camera or eye basis

8 Coordinate Systems Which is correct? Both are because vectors have no fixed location v v

9 Frames A coordinate system is insufficient to represent points If we work in an affine space we can add a single point, the origin, to the basis vectors to form a frame P0P0 v1v1 v2v2 v3v3

10 Representation in a Frame Frame determined by (P 0, v 1, v 2, v 3 ) Within this frame, every vector can be written as v=  1 v 1 +  2 v 2 +….+  n v n Every point can be written as P = P 0 +  1 v 1 +  2 v 2 +….+  n v n

11 Confusing Points and Vectors Consider the point and the vector P = P 0 +  1 v 1 +  2 v 2 +….+  n v n v=  1 v 1 +  2 v 2 +….+  n v n They appear to have the similar representations p=[  1  2  3 ] T v=[  1  2  3 ] T which confuses the point with the vector A vector has no position v p v Vector can be placed anywhere point: fixed

12 A Single Representation If we define 0P = 0 and 1P =P then we can write v=  1 v 1 +  2 v 2 +  3 v 3 = [  1  2  3 0 ] [v 1 v 2 v 3 P 0 ] T P = P 0 +  1 v 1 +  2 v 2 +  3 v 3 = [  1  2  3 1 ] [v 1 v 2 v 3 P 0 ] T Thus we obtain the four-dimensional homogeneous coordinate representation v = [  1  2  3 0 ] T p = [  1  2  3 1 ] T

13 Homogeneous Coordinates The homogeneous coordinates form for a three dimensional point [x y z] is given as p =[x’ y’ z’ w] T =[wx wy wz w] T We return to a three dimensional point (for w  0 ) by x  x’ /w y  y’/w z  z’/w If w=0, the representation is that of a vector Note that homogeneous coordinates replaces points in three dimensions by lines through the origin in four dimensions For w=1, the representation of a point is [x y z 1] T

14 Homogeneous Coordinates and Computer Graphics Homogeneous coordinates are key to all computer graphics systems  All standard transformations (rotation, translation, scaling) can be implemented with matrix multiplications using 4 x 4 matrices  Hardware pipeline works with 4 dimensional representations  For orthographic viewing, we can maintain w=0 for vectors and w=1 for points  For perspective we need a perspective division

15 Change of Coordinate Systems Consider two representations of a same vector with respect to two different bases. The representations are v=  1 v 1 +  2 v 2 +  3 v 3 = [  1  2  3 ] [v 1 v 2 v 3 ] T =  1 u 1 +  2 u 2 +  3 u 3 = [  1  2  3 ] [u 1 u 2 u 3 ] T a=[  1  2  3 ] T b=[  1  2  3 ] T where

16 Representing second basis in terms of first Each of the basis vectors, u1,u2, u3, are vectors that can be represented in terms of the first basis u 1 =  11 v 1 +  12 v 2 +  13 v 3 u 2 =  21 v 1 +  22 v 2 +  23 v 3 u 3 =  31 v 1 +  32 v 2 +  33 v 3 v

17 Matrix Form The coefficients define a 3 x 3 matrix and the bases can be related by a=M T b M =

18 Change of Frames We can apply a similar process in homogeneous coordinates to the representations of both points and vectors Any point or vector can be represented in either frame We can represent Q 0, u 1, u 2, u 3 in terms of P 0, v 1, v 2, v 3 Consider two frames: (P 0, v 1, v 2, v 3 ) (Q 0, u 1, u 2, u 3 ) P0P0 v1v1 v2v2 v3v3 Q0Q0 u1u1 u2u2 u3u3

19 Representing One Frame in Terms of the Other u 1 =  11 v 1 +  12 v 2 +  13 v 3 u 2 =  21 v 1 +  22 v 2 +  23 v 3 u 3 =  31 v 1 +  32 v 2 +  33 v 3 Q 0 =  41 v 1 +  42 v 2 +  43 v 3 +  44 P 0 Extending what we did with change of bases defining a 4 x 4 matrix M =

20 Working with Representations Within the two frames any point or vector has a representation of the same form a=[  1  2  3  4 ] T in the first frame b=[  1  2  3  4 ] T in the second frame where  4   4  for points and  4   4  for vectors and The matrix M is 4 x 4 and specifies an affine transformation in homogeneous coordinates a=M T b

21 Affine Transformations Every linear transformation is equivalent to a change in frames Every affine transformation preserves lines However, an affine transformation has only 12 degrees of freedom because 4 of the elements in the matrix are fixed and are a subset of all possible 4 x 4 linear transformations

22 The World and Camera Frames When we work with representations, we work with n-tuples or arrays of scalars Changes in frame are then defined by 4 x 4 matrices In OpenGL, the base frame that we start with is the world frame Eventually we represent entities in the camera frame by changing the world representation using the model-view matrix Initially these frames are the same ( M=I )

23 Moving the Camera If objects are on both sides of z=0, we must move camera frame M =

24 Building Models

25 Objectives Introduce simple data structures for building polygonal models  Vertex lists  Edge lists OpenGL vertex arrays

26 Representing a Mesh Consider a mesh There are 8 nodes and 12 edges  5 interior polygons  6 interior (shared) edges Each vertex has a location v i = (x i y i z i ) v1v1 v2v2 v7v7 v6v6 v8v8 v5v5 v4v4 v3v3 e1e1 e8e8 e3e3 e2e2 e 11 e6e6 e7e7 e 10 e5e5 e4e4 e9e9 e 12

27 Simple Representation Define each polygon by the geometric locations of its vertices Leads to OpenGL code such as Inefficient and unstructured  Consider moving a vertex to a new location  Must search for all occurrences glBegin(GL_POLYGON); glVertex3f(x1, y1, z1); glVertex3f(x6, y6, z6); glVertex3f(x8, y8, z8); glVertex3f(x7, y7, z7); glEnd();

28 Inward and Outward Facing Polygons The order {v 1, v 6, v 7 } and {v 6, v 7, v 1 } are equivalent in that the same polygon will be rendered by OpenGL but the order {v 1, v 7, v 6 } is different The first two describe outwardly facing polygons Use the right-hand rule = counter-clockwise encirclement of outward-pointing normal OpenGL can treat inward and outward facing polygons differently

29 Geometry vs Topology Generally it is a good idea to look for data structures that separate the geometry from the topology  Geometry: locations of the vertices  Topology: organization of the vertices and edges  Example: a polygon is an ordered list of vertices with an edge connecting successive pairs of vertices and the last to the first  Topology holds even if geometry changes

30 Vertex Lists Put the geometry in an array Use pointers from the vertices into this array Introduce a polygon list x 1 y 1 z 1 x 2 y 2 z 2 x 3 y 3 z 3 x 4 y 4 z 4 x 5 y 5 z 5. x 6 y 6 z 6 x 7 y 7 z 7 x 8 y 8 z 8 P1 P2 P3 P4 P5 v1v7v6v1v7v6 v8v5v6v8v5v6 topology geometry

31 Shared Edges Vertex lists will draw filled polygons correctly but if we draw the polygon by its edges, shared edges are drawn twice Can store mesh by edge list

32 Edge List v1v1 v2v2 v7v7 v6v6 v8v8 v5v5 v3v3 e1e1 e8e8 e3e3 e2e2 e 11 e6e6 e7e7 e 10 e5e5 e4e4 e9e9 e 12 e1 e2 e3 e4 e5 e6 e7 e8 e9 x 1 y 1 z 1 x 2 y 2 z 2 x 3 y 3 z 3 x 4 y 4 z 4 x 5 y 5 z 5. x 6 y 6 z 6 x 7 y 7 z 7 x 8 y 8 z 8 v1 v6 Note polygons are not represented

33 Modeling a Cube GLfloat vertices[][3] = {{-1.0,-1.0,-1.0},{1.0,- 1.0,-1.0}, {1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, {1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0}}; GLfloat colors[][3] = {{0.0,0.0,0.0},{1.0,0.0,0.0}, {1.0,1.0,0.0}, {0.0,1.0,0.0}, {0.0,0.0,1.0}, {1.0,0.0,1.0}, {1.0,1.0,1.0}, {0.0,1.0,1.0}}; Model a color cube for rotating cube program Define global arrays for vertices and colors

34 Drawing a polygon from a list of indices Draw a quadrilateral from a list of indices into the array vertices and use color corresponding to first index void polygon(int a, int b, int c, int d) { glBegin(GL_POLYGON); glColor3fv(colors[a]); glVertex3fv(vertices[a]); glVertex3fv(vertices[b]); glVertex3fv(vertices[c]); glVertex3fv(vertices[d]); glEnd(); }

35 Draw cube from faces void colorcube( ) { polygon(0,3,2,1); polygon(2,3,7,6); polygon(0,4,7,3); polygon(1,2,6,5); polygon(4,5,6,7); polygon(0,1,5,4); } 0 56 2 4 7 1 3 Note that vertices are ordered so that we obtain correct outward facing normals

36 Efficiency The weakness of our approach is that we are building the model in the application and must do many function calls to draw the cube Drawing a cube by its faces in the most straight forward way requires  6 glBegin, 6 glEnd  6 glColor  24 glVertex  More if we use texture and lighting

37 Vertex Arrays OpenGL provides a facility called vertex arrays that allows us to store array data in the implementation Six types of arrays supported  Vertices  Colors  Color indices  Normals  Texture coordinates  Edge flags We will need only colors and vertices

38 Initialization Using the same color and vertex data, first we enable glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); Identify location of arrays glVertexPointer(3, GL_FLOAT, 0, vertices); glColorPointer(3, GL_FLOAT, 0, colors); 3d arraysstored as floats data contiguous data array

39 Mapping indices to faces Form an array of face indices Each successive four indices describe a face of the cube Draw through glDrawElements which replaces all glVertex and glColor calls in the display callback GLubyte cubeIndices[24] = {0,3,2,1,2,3,7,6 0,4,7,3,1,2,6,5,4,5,6,7,0,1,5,4};

40 Drawing the cube Method 1: Method 2: for(i=0; i<6; i++) glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_BYTE, &cubeIndices[4*i]); format of index data start of index data what to draw number of indices glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, cubeIndices); Draws cube with 1 function call!!

41 Summary Dimension, Basis Vectors spaces vs. affine spaces Coordinate systems vs. frames Representation of points vs. vectors Homogeneous coordinates Change of frames with matrix, e.g., moving the camera


Download ppt "Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for."

Similar presentations


Ads by Google