Download presentation
Presentation is loading. Please wait.
Published byChristine Heath Modified over 7 years ago
1
Unit-4 Geometric Objects and Transformations- I
Course code: 10CS65 | Computer Graphics and Visualization Unit-4 Geometric Objects and Transformations- I Engineered for Tomorrow Prepared by : Asst. Prof. Sandhya Kumari Department: Computer Science and Engineering Date : dd.mm.yyyy
2
Geometric Transformations
Concentration on 3D graphics Affine & Euclidean vector spaces Homogeneous coordinates Formalities of vector spaces & matrix algebra – see App.B&C Goals: method for dealing with geometric objects – independent of a coordinate system coordinate free approach & homogeneous coordinates
3
Scalars, Points & Vectors
Most geometric objects can be defined by a limited set of primitives, like scalars, points, vectors Different perspectives: mathematical programming geometric BUT ALL are important for understanding vector = directed (oriented) line segment vectors have no fixed position!
4
Geometric View vectors have no fixed position
had-to-tail rule – useful to express functionality C = A + B points & vectors – distinct geometric types! a given vector can be defined as from a fixed reference point (origin) to the given point p (dangerous vector repr.)
5
Vector & Affine Spaces Vector (linear) space
vector & scalars – addition &multiplication operations used to form a scalar field (scalars – real, complex numbers, rational functions – typical Ax=0, n-tuples etc.) Affine space – extension of vector space – the point is an object vector-point addition, point-point subtraction, geometric operations with points etc. Euclidean space – enables to measure distance, size
6
Representation Mathematicians – scalars, points, vectors etc. – they are distinguished by symbols and fonts (bold, capital, italic etc.) Computer scientists – Abstract Data Types – ADT – set of operations on data; operations independent from the actual physical realization/implementation Data abstraction – fundamental to Computer Science but causes difficulties in a code understanding What is the meaning of a sequence in C++ : q = p + a * v;
7
Representation What is the meaning of a sequence in C++ : q = p + a * v; can be determined if the definition is known: vector u, v; point p, q; scalar a, b; and their actual meaning must be vector type as a vector ! OpenGL is not object oriented so far
8
Geometric ADT & Lines Symbols: , , - scalars P, Q, R – points u, v, w – vectors Typical geometrical operations: | v| = | | | v | v = P – Q => P = v + Q ( P – Q )+ ( Q – R ) = P – R P() = P0 + d (a line in an affine space – param.form)
9
Affine Sums new point P can be defined as P = Q + v Point R v = R – Q and P = Q + (R –Q)= R + (1- )Q P = 1 R+ 2 Q where 1 + 2 = 1
10
Convexity A convex object is one for which any point lying on the line segment connecting any two points in the object is also in the object P = 1 R+ 2 Q & 1+ 2 = 1 More general form P = 1P1+2P nPn where 1+ n= 1 & i 0 , i = 1, 2, ....,n
11
Planes Let P, Q, R are points defining a plane in an affine space S() = P + (1- )Q , 0 1 T() = S + (1 - ) R , 0 1 using a substitution T(,) = [ P + (1- )Q ] + ( 1 - ) R , 0 1 & 0 1 T(,) = P + (1 - )( Q – P ) + (1 - ) (R – P) Plane given by a point P0 and vectors u, v T(,) = P0 + u + v & 0 , 1
12
Planes A triangle is defined as (a plane has no limits for , ) T(,) = P0 + u + v & 0 , 1 If a point P lies in the plane then P - P0 = u + v Let w = u x v (cross product) The vector w is orthogonal to the plane and the equation wT (P – P0) = 0 (criterion for a test: point in the plane) vector w is called a normal vector and symbol n is often used
13
Three Dimensional Primitives
Full range of graphics primitives cannot be supported by graphics systems – some are approximated most graphics systems optimized for procession points and polygons, polygons in E3 are not planar – tessellation is required or made by the system itself Constructive Solid Geometry (CSG) – objects build using set operations like union, intersection, difference etc.
14
Coordinate Systems and Frames
A vector w is defined as w = 1v1 + 2v2 + 3v3 1, 2, 3 are components of w with respect to the basis vectors v1 ,v2 ,v3 vectors v forms coordinate system in vector space points representation needs to “fix” the origin – reference point and basis vectors are required - frame
15
Coordinate Systems and Frames
Within a given frame every vector can be written uniquely as w = 1v1 + 2v2 + 3v3 just as in a vector space. v1 = [ 1, 0 , 0]T v2 = [ 0, 1 , 0]T v3 = [ 0, 0 , 1]T Every point can be written uniquely as w = P0 + 1v1 + 2v2 + 3v3
16
Changes of Coordinate Systems
Suppose that {v1 , v2 , v3 } & {u1 , u2 , u3 } are two basis vectors. Therefore 9 scalar components exist { ij} such as u = M v a vector w with respect to v = [v1 , v2 , v3 ]T a = [1 , 2 , 3 ]T w = aT v a vector w with respect to v = [u1 , u2 , u3 ]T b = [ß1 , ß2 , ß3 ]T w = bT u w = bT u = bT M v = aT v bT M = aT a = MT b
17
Changes of Coordinate Systems
The origin unchanged - rotation, scaling representation u = M v Simple translation or a change of a frame cannot be represented in this way Study change of representation – chapter on your own
18
Homogeneous coordinates
A point P located at (x,y,z) is represented using a 3D frame by P0, v1, v2, v3 as p = [ x , y , z ]T therefore P = P0 + x v1+ y v2 + z v3 and point P can be determined as P = 1v1 + 2v2 + 3v3 + P0 P = [1 , 2 , 3 , 1] [v1 , v2 , v3 , P0 ]T Every point can be written uniquely as w = P0 + 1v1 + 2v2 + 3v3
19
Homogeneous Coordinates
Suppose that {v1 , v2 , v3 , P0 }&{u1 , u2 , u3 , Q0 } are two basis vectors. Therefore 16 scalar components exist { ij} such as u = M v a vector w with respect to v = [v1 , v2 , v3 , P0 ]T = [1 , 2 , 3 , 1]T w = aT v a vector w with respect to v = [u1 , u2 , u3 , Q0]T = [ß1 , ß2 , ß3 , 1]T w = bT u w = bT u = bT M v = aT v bT M = aT a = MT b Study Change in Frames and Frames&ADT Chapters on your own
20
Frames in OpenGL Two frames – camera & world frames
Consider the camera frame fixed model-view matrix converts the homogeneous coordinate representations of points and vectors to their representations in the camera frame the model-view matrix is part of the state of the system – there is always a camera frame and a present-world frame (how to define new frames – next chapters) three basis vectors correspond to up, y, z -directions,
21
Frames in OpenGL Default settings: Camera & World frames the same
Objects must moved away from camera or Camera must be moved away from objects If camera frame fixed & model-view positioning world frame to camera frame then model-view matrix A is defined as ( d- distance):
22
Frames in OpenGL Moves points (x,y,z) in the world frame to (x,y,z,-d) in the camera frame This concept is better than the repositioning objects position by changing their vertices Setting the Model-View matrix by sending an array of 16 elements to glLoadMatrix User working in the world coordinates positions the objects as before
23
Modeling a Colored Cube
Problem: Draw a rotating cube. Tasks to be done: modeling converting to the camera frame clipping projection hidden surfaces removal rasterization display of the object
24
Modeling of a Cube Cube as 6 polygons – facets typedef GLfloat point3[3]; point3 vertices[8] = { {x,y,z},...{x,y,z}}; /* definition of the cube vertices */ glBegin(GL_POLYGON); glVertex3fv(vertices[0]); glVertex3fv(vertices[3]); glVertex3fv(vertices[2]); glVertex3fv(vertices[1]); glEnd ( ); /* facet drawn */ outward facing - normal has right hand rule orientation
25
Data Structures for Object Represenation
Advantages of the data structure: separation of topology and geometry geometry stored in the vertex list hg
26
Data Structures for Object Represenation
typedef GLfloat point3[3]; point3 vertices [8] = {{x,y,z}, ... ,{x,y,z}}; /* vertices x,y,z coordinates def. */ GLfloat Colors[8][3] = {{r,g,b}, .... , {r,g,b}}; /* color defs. */ void quad(int a, int b, int c, int d) { glBegin(GL_QUADS); glColor3fv(colors[a]);glVertex3fv(vertices[a]); glColor3fv(colors[b]);glVertex3fv(vertices[b]); glColor3fv(colors[c]);glVertex3fv(vertices[c]); glColor3fv(colors[d]);glVertex3fv(vertices[d]); glEnd ( ); }
27
Data Structures for Object Representation
color is specified - graphics system must decide how to fill bilinear interpolation C01() = (1- )C0+ C1 C23() = (1- )C2+ C3 for the given value C01() = C4 , C23() = C5 C45() = (1- )C0+ C5 scan-line interpolation OpenGL provides this for others values that are assigned on the vertex-to-vertex basis void colorcube( );/*draws a cube*/ { quad(0,3,2,1); quad(2,3,7,6); quad(0,4,7,3); quad(1,2,6,5); quad(4,5,6,7); quad(0,1,5,4); }
28
Vertex Arrays glBegin, glEnd, glColor, glVertex – high overhead Vertex arrays – a glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); Arrays are the same as before GLfloat vertices [ ] = { }; GLfloat colors [ ] = { }; /* specification where the arrays are */ glVertexPointer(3,GL_FLOAT,0,vertices); glColorPointer(3,GL_FLOAT,0,colors); /* 3D vector, type, continuous (packed), pointer to the array */
29
Vertex Arrays The facets must be specified 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}; /* facets are formed by 4 vertices */ Options how to draw: glDrawElements(type,n,format,pointer); SOLUTION for ( i=0; i<6; i++) /* n number of elements */ glDrawElements(GL_POLYGON,4, GL_UNSIGNED_BYTE, &cubeIndicis[4*i]); or with a single call glDrawElements(GL_QUADS,24, GL_UNSIGNED_BYTE, &cubeIndices);
30
Rotation, translation and Scaling
Translation P’ = P + d Rotation x = cos y = sin x’ = cos (+) y’ = sin (+)
31
Rotation about a fixed point
For rotation – implicit point origin 2D – simple 3D –complicated Transformation rigid-body non-rigid-body reflections
32
Conclusion Chapter 4 You have learnt in this chapter:
how transformations are defined how can you use them how to construct quite complicated transformations Mention, please, that you are now capable to write quite complicated program with graphics output and input Next time we will learn how to represent different viewing principles, projections etc.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.