GEOMETRIC OBJECTS AND TRANSFORMATIONS I

Similar documents
UNIT 4 GEOMETRIC OBJECTS AND TRANSFORMATIONS-1

Building Models. Objectives. Introduce simple data structures for building polygonal models. OpenGL vertex arrays. Vertex lists Edge lists

Building Models. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Display Lists. Conceptually similar to a graphics file. In client-server environment, display list is placed on server

Building Models. Objectives Introduce simple data structures for building polygonal models. Vertex lists Edge lists

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York

2D transformations: An introduction to the maths behind computer graphics

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics I. Guoying Zhao 1 / 52

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science

Filled Area Primitives. CEng 477 Introduction to Computer Graphics METU, 2007

UNIT 2 2D TRANSFORMATIONS

Object Representation Affine Transforms. Polygonal Representation. Polygonal Representation. Polygonal Representation of Objects

COMPUTER GRAPHICS AND VISUALIZATION. Subject Code: 10CS65 / 10IS665 I.A. Marks : 25 Hours/Week : 04 Exam Hours: 03 Total Hours : 52 Exam Marks: 100

Computer Graphics Hands-on

3D Mathematics. Co-ordinate systems, 3D primitives and affine transformations

Basic Elements. Geometry is the study of the relationships among objects in an n-dimensional space

CT5510: Computer Graphics. Transformation BOCHANG MOON

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

Figure 1. Lecture 1: Three Dimensional graphics: Projections and Transformations

Lecture 2 2D transformations Introduction to OpenGL

How shapes are represented in 3D Graphics. Aims and objectives By the end of the lecture you will be able to describe

Lecture 4 of 41. Lab 1a: OpenGL Basics

Homework #2 and #3 Due Friday, October 12 th and Friday, October 19 th

Graphics and Interaction Transformation geometry and homogeneous coordinates

COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates

Computer Graphics and Visualization SYLLABUS COMPUTER GRAPHICS AND VISUALIZATION

CS 465 Program 4: Modeller

Lecture 4: Transformations and Matrices. CSE Computer Graphics (Fall 2010)

Lecture 4: Transforms. Computer Graphics CMU /15-662, Fall 2016

Geometry. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

CS452/552; EE465/505. Models & Viewing

Computer Graphics with OpenGL ES (J. Han) Chapter IV Spaces and Transforms

THE VIEWING TRANSFORMATION

Last week. Machiraju/Zhang/Möller/Fuhrmann

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

CS452/552; EE465/505. Geometry Transformations

COS340A Assignment 1 I Pillemer Student# March 25 th 2007 p1/15

GEOMETRIC TRANSFORMATIONS AND VIEWING

CHAPTER 1 Graphics Systems and Models 3

Computer Graphics 7: Viewing in 3-D

Mathematics 308 Geometry. Chapter 9. Drawing three dimensional objects

Viewing with Computers (OpenGL)

Matrices. Chapter Matrix A Mathematical Definition Matrix Dimensions and Notation

Transforms. COMP 575/770 Spring 2013

Computer Graphics. Chapter 7 2D Geometric Transformations

Computer Graphics Seminar

BASIC ELEMENTS. Geometry is the study of the relationships among objects in an n-dimensional space

Building Models. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Perspective Mappings. Contents

2D/3D Geometric Transformations and Scene Graphs

Transformations. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

OpenGL. Jimmy Johansson Norrköping Visualization and Interaction Studio Linköping University

CSC 470 Computer Graphics

SOURCES AND URLS BIBLIOGRAPHY AND REFERENCES

Monday, 12 November 12. Matrices

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

Geometry. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Vector Addition. Qty Item Part Number 1 Force Table ME-9447B 1 Mass and Hanger Set ME Carpenter s level 1 String

Overview. By end of the week:

Computer Graphics Hands-on

2D and 3D Transformations AUI Course Denbigh Starkey

Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2)

Vector Algebra Transformations. Lecture 4

Lecture 5 2D Transformation

CS 432 Interactive Computer Graphics

Geometry. Prof. George Wolberg Dept. of Computer Science City College of New York

Lecture 9: Transformations. CITS3003 Graphics & Animation

Principles of Computer Game Design and Implementation. Lecture 6

Institutionen för systemteknik

UNIT B3 Number Sequences: Activities

Junior Circle Meeting 9 Commutativity and Inverses. May 30, We are going to examine different ways to transform the square below:

CSE528 Computer Graphics: Theory, Algorithms, and Applications

521493S Computer Graphics Exercise 2 Solution (Chapters 4-5)

Ray Tracer I: Ray Casting Due date: 12:00pm December 3, 2001

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Fachhochschule Regensburg, Germany, February 15, 2017

Today s class. Geometric objects and transformations. Informationsteknologi. Wednesday, November 7, 2007 Computer Graphics - Class 5 1

2D Object Definition (1/3)

Data Representation in Visualisation

Vertex Buffer Objects

Vertex Buffer Objects. Vertex Buffer Objects: The Big Idea

L1 - Introduction. Contents. Introduction of CAD/CAM system Components of CAD/CAM systems Basic concepts of graphics programming

Chapter 2: Transformations. Chapter 2 Transformations Page 1

CS 4620 Midterm, March 21, 2017

Geometry Primitives. Computer Science Department University of Malta. Sandro Spina Computer Graphics and Simulation Group. CGSG Geometry Primitives

Notes on Computer Graphics and OpenGL. Thomas Strathmann

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

Transformation Pipeline

Introduction to Computer Graphics with OpenGL/GLUT

CS 4620 Midterm 1. Tuesday 22 October minutes

Objectives. Geometry. Basic Elements. Coordinate-Free Geometry. Transformations to Change Coordinate Systems. Scalars

Midterm Exam Fundamentals of Computer Graphics (COMP 557) Thurs. Feb. 19, 2015 Professor Michael Langer

Modeling with Transformations

MET71 COMPUTER AIDED DESIGN

A NON-TRIGONOMETRIC, PSEUDO AREA PRESERVING, POLYLINE SMOOTHING ALGORITHM

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

OpenGL Transformations

CS770/870 Spring 2017 Transformations

Basics of Computational Geometry

Computer Graphics. Chapter 5 Geometric Transformations. Somsak Walairacht, Computer Engineering, KMITL

Transcription:

Computer UNIT Graphics - 4 and Visualization 6 Hrs GEOMETRIC OBJECTS AND TRANSFORMATIONS I Scalars Points, and vectors Three-dimensional primitives Coordinate systems and frames Modelling a colored cube Affine transformations Rotation, translation and scaling Page 49

UNIT - 4 6 Hrs GEOMETRIC OBJECTS AND TRANSFORMATIONS I 4.1 Scalars, points and vectors The basic geometric objects and relationship among them can be described using the three fundamental types called scalars, points and vectors. Geometric Objects. Points: One of the fundamental geometric objects is a point. In 3D geometric system, point is a location in space. Point possesses only the location property, mathematically point neither a size nor a shape. Points are useful in specifying objects but not sufficient. Scalars: Scalars are objects that obey a set of rules that are abstraction of the operations of ordinary arithmetic. Thus, addition and multiplication are defined and obey the usual rules such as commutativity and associativity and also every scalar has multiplicative and additive inverses. Vector: Another basic object which has both direction and magnitude, however, vector does not have a fixed location in space. Directed line segment shown in figure below connects two points has both direction i.e, orientation and magnitude i.e., its length so it is called as a vector Q P because of vectors does not have fixed position, the directed line segments shown in figure below are identical because they have the same direction and magnitude. Page 50

Vector lengths can be altered by the scalar components, so the line segment A shown in figure below is twice t he length of line segment B B A=2B We can also combine directed line segments as shown in figure below by using the head and tail rule D=A+B B A We obtained new vector D from two vectors A and B by connecting head of A to tail of B. Magnitude and direction of vector D is determined from the tail of A to the head of B, we can call D has sum of A and B, so we can write it as D=A+B. Consider the two directed line segments A and E shown in figure below with the same length but opposite direction. We can define the vector E in terms of A as E =-A, so the vector E is called inverse vector of A. The sum of vectors A and E is called Zero vector, which is denoted as 0, that has a zero magnitude and orientation is undefined. A Page 51

4.2 Coordinate systems and frames The purpose of the graphics pipeline is to create images and display them on your screen. The graphics pipeline takes geometric data representing an object or scene (typically in three dimensions) and creates a two-dimensional image from it. Your application supplies the geometric data as a collection of vertices that form polygons, lines, and points. The resulting image typically represents what an observer or camera would see from a particular vantage point. As the geometric data flows through the pipeline, the GPU's vertex processor transforms the constituent vertices into one or more different coordinate systems, each of which serves a particular purpose. Cg vertex programs provide a way for you to program these transformations yourself. Figure 4-1 illustrates the conventional arrangement of transforms used to process vertex positions. The diagram annotates the transitions between each transform with the coordinate space used for vertex positions as the positions pass from one transform to the next. 4.3 Modeling a colored cube Modeling the faces The case is as simple 3D object. There are number of ways to model it. CSG systems regard it as a single primitive. Another way is, case as an object defined by eight vertices. We start Page 52

modeling the cube by assuming that vertices of the case are available through an array of vertices i.e, GLfloat Vertices [8][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}} We can also use object oriented form by 3D point type as follows Typedef GLfloat point3 [3]; The vertices of the cube can be defined as follows Point3 Vertices [8] = {{-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}} We can use the list of points to specify the faces of the cube. For example one face is glbegin (GL_POLYGON); glvertex3fv (vertices [0]); glvertex3fv (vertices [3]); glend (); glvertex3fv (vertices [2]); glvertex3fv (vertices [1]); Similarly we can define other five faces of the cube. Inward and outward pointing faces When we are defining the 3D polygon, we have to be careful about the order in which we specify the vertices, because each polygon has two sides. Graphics system can display either or both of them. From the camera s perspective, we need to distinguish between the two faces of a polygon. The order in which the vertices are specified provides this information. In the Page 53

above example we used the order 0,3,2,1 for the first face. The order 1,0,2,3 would be sa me because the final vertex in polygon definition is always linked back to the first, but the order 0,1,2,3 is different. We call face outward facing, if the vertices are traversed in a counter clockwise order, when the face is viewed from the outside. In our example, the order 0,3,2,1 specifies outward face of the cube. Whereas the order 0,1,2,3 specifies the back face of the same polygon. 1 2 0 3 By specifying front and back carefully, we will can eliminate faces that are not visible. OpenGL can treat inward and outward facing polygons differently. Data structures for object representation It is better to use the data structure that separate the geometry from the topology. [The geometry stands for locations of the vertices and topology stands for organization of the vertices and edges]. We use a structure, the vertex list (shown in Fig. below) that is both simple and useful. Page 54

The data specifying the location of the vertices contain the geometry and can be stored as a simple list or array, such as in vertices the vertex list. The top level entity is a cube and is composed of six faces. Each face consists of four ordered vertices. Each vertex can be specified indirectly through its index. This can be represented like figure shown above.. The color cube We can use the vertex list to define a color cube. We can define a function quad to draw quadrilaterals polygons specified by pointers into the vertex list. The color cube specifies the six faces, taking care to make them all outward facing as follows. GLfloatVertices [8] [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 color [8] [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}}; void quad (int a, int b, int c, int d) { } glbegin (GL_QUADS); glend(); glcolor3fv (colors[a]); glvertex3fv(vertices[a]); glcolor3fv(colors[b]); glvertex3fv(vertices[b]); glcolor3fv(colors[c]); glvertex3fv (vertices[c]); glcolor3fv (colors[d]); glvertex3fv(vertices[d]); Page 55

Void colorcube () { 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); Vertex arrays Although we used vertex lists to model the cube, it requires many opengl function calls. For example, the above function make 60 opengl calls: six faces, each of which needs a glbegin, a glend, four calls to glcolor, and four calls to glvertex. Each of which involves overhead & data transfer. This problem can be solved by using vertex arrays. Vertex arrays provide a method for encapsulating the information in data structure such that we can draw polyhedral objects with only few function calls. There are three steps in using vertex arrays (i) Enable the functionality of vertex arrays (ii) Tell opengl, location & format of the array. (iii) Render the object. The first two steps are called initialization part and the third step is called display callback. OpenGL allows many different types of arrays; here we are using two such arrays called color and vertex arrays. The arrays can be enabled as follows. glenableclientstate (GL_COLOR_ARRAY) glenableclientstate (GL_VERTEX_ARRAY). The arrays are same as before. Next, we identify where the arrays are as follows. Page 56

glvertexpointer (3,GL_FLOAT, 0, Vertices); glcolorpointer (3,GL_FLOAT, 0, COLOR); The first three arguments state that the elements are 3D colors and vertices stored as floats & that the elements are contagious in the arrays. Fourth argument is pointer to the array holding the data. Next, provide information in data structure about the relationship between the vertices the faces of the cube by specifying an array that holds the 24 ordered vertex indices for the six faces. GLubytecubeIndices [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}; Each successive four indices describe a face of the cube, Draw the array through gldrawelements which replaces all glvertex & glcolor calls in the display. gldrawelements(glenum type, GLsizei n, GLenum format, void * pointer) We can draw the cube using two methods 1) for (i=0;,i<6;i++) gldrawelements(gl_polygon,4,gl_unsigned_byte, & cubeindices[4*i]); 2) gldrawelements(gl_quads, 24, GL_UNSIGNED_BYTE, cubeindices); 4.4 Affine transformations An affine transformation is an important class of linear 2-D geometric transformations which maps variables (e.g. pixel intensity values located at position in an input image) into new variables (e.g. in an output image) by applying a linear combination of translation, rotation, scaling and/or shearing (i.e. non-uniform scaling in some directions) operations. The general affine transformation is commonly written in homogeneous coordinates as shown below: By defining only the B matrix, this transformation can carry out pure translation: Page 57

Pure rotation uses the A matrix and is defined as (for positive angles being clockwise rotations): Here, we are working in image coordinates, so the y axis goes downward. Rotation formula can be defined for when the y axis goes upward. Similarly, pure scaling is: (Note that several different affine transformations are often combined to produce a resultant transformation. The order in which the transformations occur is significant since a translation followed by a rotation is not necessarily equivalent to the converse.) Since the general affine transformation is defined by 6 constants, it is possible to define this transformation by specifying the new output image locations of any three input image coordinate pairs. (In practice, many more points are measured and a least squares method is used to find the best fitting transform.) 4.5 Rotation, translation and scaling Translation void gltranslate{fd} (TYPE x, TYPE y, TYPE z); Multiplies the current matrix by a matrix that moves (translates) an object by the given x, y, and z values Page 58

Rotation void glrotate{fd}(type angle, TYPE x, TYPE y, TYPE z); Multiplies the current matrix by a matrix that rotates an object in a counterclockwise direction about the ray from the origin through the point (x, y, z). The angle parameter specifies the angle of rotation in degrees. Scaling void glscale{fd} (TYPEx, TYPE y, TYPEz); Multiplies the current matrix by a matrix that stretches, shrinks, or reflects an object along the axes. Equations : Translation: Pf = T + P Page 59

x f = x o + dx y f = y o + dy Rotation: Pf = R P x f = x o * cos - y o *sin y f = x o * sin + y o *cos Scale: Pf = S P x f = sx * x o y f = sy * y o Page 60

PART - B Page 61