CAP 4730 Computer Graphic Methods Prof. Roy Levow Chapter 4.

Slides:



Advertisements
Similar presentations
Transformations Ed Angel Professor Emeritus of Computer Science
Advertisements

Computer Graphics Lecture 4 Geometry & Transformations.
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
CMPE 466 COMPUTER GRAPHICS
Math 1Hofstra University – CSC171A1 Modeling Objects by Polygonal Approximations Define volumetric objects in terms of surfaces patches that surround the.
Math Foundations of CG Math 1 Hofstra University.
Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)
Chapter 4.1 Mathematical Concepts
2/7/2001Hofstra University – CSC290B1 Review: Math (Ch 4)
Chapter 4.1 Mathematical Concepts. 2 Applied Trigonometry Trigonometric functions Defined using right triangle  x y h.
Modeling Objects by Polygonal Approximations
CS5500 Computer Graphics March 22, Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Coordinate-Free Geometry When we learned simple.
2.1 si SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling.
Transformations Objectives Understand how transformations work in 2D and 3D Understand the concept of homogenous coordinate system Understand scene graphs.
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
Transformations. 2 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Coordinate-Free Geometry When we learned simple geometry, most of us.
Transformations CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Computer Graphics with OpenGL 3e
Vectors.
Geometric Objects and Transformations Geometric Entities Representation vs. Reference System Geometric ADT (Abstract Data Types)
Graphics CSE 581 – Interactive Computer Graphics Mathematics for Computer Graphics CSE 581 – Roger Crawfis (slides developed from Korea University slides)
CS 480/680 Computer Graphics Representation Dr. Frederick C Harris, Jr. Fall 2012.
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
Fundamentals of Computer Graphics Part 4
1 Chapter 4 Geometric Objects and Transformation.
Transformations Dr. Amy Zhang.
CS 480/680 Computer Graphics Transformations Dr. Frederick C Harris, Jr.
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
Geometric Transformations Jehee Lee Seoul National University.
Intro to 3D Models Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Mathematics for Graphics. 1 Objectives Introduce the elements of geometry  Scalars  Vectors  Points Develop mathematical operations among them in a.
Geometric Transformations
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Geometric Objects and Transformation
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 52 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 52 Computer Graphics Three-Dimensional Graphics I.
Background Mathematics Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006.
Geometric Objects and Transformations
University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell Affine Transformations.
CSE Real Time Rendering Week 5. Slides(Some) Courtesy – E. Angel and D. Shreiner.
Geometric Transformations
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Affine Transformation. Affine Transformations In this lecture, we will continue with the discussion of the remaining affine transformations and composite.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Geometric Transformations Sang Il Park Sejong University Many slides come from Jehee Lee’s.
1 Graphics CSCI 343, Fall 2015 Lecture 9 Geometric Objects.
Affine Geometry.
Computer Graphics Matrices
CSCE 552 Fall 2012 Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
Basic Theory (for curve 01). 1.1 Points and Vectors  Real life methods for constructing curves and surfaces often start with points and vectors, which.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 73 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 73 Computer Graphics Three-Dimensional Graphics II.
Geometric Transformations. Transformations Linear transformations Rigid transformations Affine transformations Projective transformations T Global reference.
Computer Graphics I, Fall 2010 Transformations.
1 Geometric Transformations Modelling Transforms By Dr.Ureerat Suksawatchon.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Transformations Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
4. Affine transformations. Reading Required:  Watt, Section 1.1. Further reading:  Foley, et al, Chapter  David F. Rogers and J. Alan Adams,
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Graphics Graphics Korea University kucg.korea.ac.kr Geometric Primitives 고려대학교 컴퓨터 그래픽스 연구실.
Graphics Graphics Korea University kucg.korea.ac.kr Mathematics for Computer Graphics 고려대학교 컴퓨터 그래픽스 연구실.
4. Geometric Objects and Transformations
3D Ojbects: Transformations and Modeling. Matrix Operations Matrices have dimensions: Vectors can be thought of as matrices: v=[2,3,4,1] is a 1x4 matrix.
Objectives Introduce standard transformations Introduce standard transformations Derive homogeneous coordinate transformation matrices Derive homogeneous.
Unit-4 Geometric Objects and Transformations- I
Unit-5 Geometric Objects and Transformations-II
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.
Transformations 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Geometric Objects and Transformations (II)
Presentation transcript:

CAP 4730 Computer Graphic Methods Prof. Roy Levow Chapter 4

Geometry  Basic components –Point –Vector –Line Segment –Directed Line Segment  Can be added head-to-tail  Similar to vector addition but location of start of first segment is start of sum

Point-Vector Operations  Inverse of a vector –reverses direction  Point + Vector –Gives new point at end of vector from original point  Interpret inverse Point – Point –to be vector from second point to first

Scalar Operations  Scalar times vector is standard operation  Can take linear combination of points and vectors with scalar multipliers as long as net number of points is 1 –OK: P – 2 Q + 3v –Bad: 2 P – 4 Q

Geometric Space  Coordinate-free system –Objects have no location  Scalar Field –add, subtract, multiply, divide –associative and commutative  Vector Space –Vectors and scalars as usual  Affine Space –Vector space plus points  point + vector; point - point

Computational Framework  Magnitude of a vector –|αv| = |α| |v|  Lines –parametric form –P(α) = P 0 + αv –affine addition –P = α 1 R + α 2 Q where α 1 + α 2 = 1

Convexity  A polygon with vertices P1, …, P n is convex precisely when all affine sums of the points P = α 1 R + … + α n P n are inside the figure when α i ‘s sum to 1

Dot and Cross Products  Dot (inner) Product –u∙v = sum u i v i –|u| 2 = u∙u –cos θ = u∙v / |u||v|  Cross Product –n = u x v –orthogonal to plane of u-v –|sin θ | = |u x v| / |u||v| –Right hand rule  Using right hand, u is index, v is middle, n is thumb

Plane  Affine sum of three non-colinear points  or point and two vectors  or solution to the equation –n ∙ (P – P 0 ) = 0

Three-Dimensonal Primitives  Curves  Surfaces  Volumetric Ojbects  Standard treatment –Objects are described by their surfaces and treated as hollow –Objects can be specifiedby vertices –Objects can be defined directly or approximated by flat convex polygons

Coordinate Systems and Frames  Any vector in 3-dimensions can be represented as a linear combination of any three lineraly independent vectors w = α 1 v 1 + α 2 v 2 + α 3 v 3 w = α 1 v 1 + α 2 v 2 + α 3 v 3  If we fix the vectors v 1, v 2, v 3 we call them a basis  we can represent a point by the coefficients a = (α 1, α 2, α 3 ) T a = (α 1, α 2, α 3 ) T

Coordinate Systems and Frames  Conversely w = (α 1, α 2, α 3 ) (v 1, v 2, v 3 ) T w = (α 1, α 2, α 3 ) (v 1, v 2, v 3 ) T  The basis vectors define a coordinate system  However, the basis vectors are not anchored and could be moved  Adding a point as the origin gives us a frame  Every point can then be written as P 0 plus a linear combination of the basis vectors

Representations  Any point can be represented as 1.a vector, from the origin 2.a 3-tuple of the coefficients for the basis

Changes in Coordinate System  Suppose we have two bases –{u 1, u 2, u 3 } and {v 1, v 2, v 3 }  Each vector u i is a linear combination of the v’s  If M is the 3x3 matrix of coefficients, then (u 1, u 2, u 3 ) T =M (v 1, v 2, v 3 ) T  The inverse of M transforms from u’s to v’s

Changing Coordinate System  If a is the coordinate vector for v’s and b is the coordinate vector for u’s then a = M T b a = M T b  Changing the basis can effect rotation and scaling  Changing the basis leaves the origin unchanged

Homogeneous Coordinates  We can include the origin in our calculation s by adding a 4 th dimension for the origin, P 0, and agreeing to multiply only by 1 except for the zero vector when we use 0  Basis is now {v 1, v 2, v 3, P 0 }  Last column of transform matrix is 0, 0, 0, 1 0, 0, 0, 1  Can convert to new basis {u 1, u 2, u 3, Q 0 }

Examples  Change of basis 4.3.3, p. 159  Change of frame 4.3.5, p. 163

Working with Representations  Problem: How to obtain the transformation matrix given two representations  Solution: The representation of one frame in terms of another, a = Cb, gives the inverse of the matrix, D = C -1 (see p. 165)

Frames in OpenGL  Camera us at origin of its frame, pointing in –z direction; y is the up direction and x completes a right- handed coordinate system (see next slide)  To view objects near origin, camera must be moved back, say a distance d (see next slide)

Camera Model-View Matrix  Model-View matrix is d 0001 moves point (x,y,z) in world frame to (x,y,z-d)

Camera at (1,0,1) Pointing at Origin  Camera is centered at (1,0,1,1) T  Orthogonal to back is n=(-1,0,-1,1) T  Up is same as world coord (0,1,0,0) T  Third orthogonal is (1,0,-1,0) T  Inverse of is is

Modeling a Colored Cube  Steps 1.Modeling 2.Converting to camera frame 3.Clipping 4.Projecting 5.Removing Hidden Surfaces 6.Rasterizing Code is cube.c

Modeling Cube  Model as 6 faces defined by vertices –Vertices at 1, -1 –Each face is a square (polygon)  Polygons have inside and outside face –Face is outward if vertices occur in counterclockwise order –Use right-hand rotation through vertices, thumb points out  Outward face must be to outside of cube

Data Structures  Polygons or Quads  Vertex list representation

Cube Code  Define colors for the vertices see code

Coloring Faces  Faces will be filled with colors by intepolation, bilinear scan-line interpolation from modelavoids need for flat

Vertex Arrays  Avoid recomputation  OpenGL Arrays 1.Color 2.Vertex 3.Color Index 4.Normal 5.Texture Coordinate 6.Edge Flag

Application to Cube  glEnableClientState(array_type); –array types: GL_COLOR_ARRAYGL_VERTEX_ARRAY  Create global arrays of values as before

Application to Cube (cont)  Register data arrays with OpenGL glVertexPointer (dim, glType, gap, array_var); glColorPointe (…)  For example glVertexPointer (3, GL_FLOAT, 0, glVertexPointer (3, GL_FLOAT, 0,vertices);

Application to Cube (cont)  Then draw the elements with glDrawElements(type, n, fmt, ptr);  For example for (1=0; i<6; i++) for (1=0; i<6; i++) glDrawElements(GL_POLYGON, 4 GL_UNSIGNED_BYTE,&cubeIndex[4*i]);  or could do quads in one batch of 24

Affine Transformations  A transformation maps a point (or vector) into another point (or vector) Q = T(P)  With homogeneous coordinates we can use the same function for both points and vectors, q=f(p) or v=f(u)

Linear Transformations  Limit consideration to functions satisfying f(ap+bq) = af(p) + bf(q) called linear transformations  Linear transformations can always be written as matrix multiplications by a 4x4 matrix  For homogeneous coordinates, the last row is but other 12 entries are arbitrary, but only 9 effect vectors.

Linear Transformations (cont)  Properites –Linear transformations can be viewed as either 1.change in representation (frame) 2.transformation on vertices within frame –Lines and planes are preserved –Transformed line segment is generated by transformed end points  This simplifies design of graphics pipeline

Translation, Rotation, Scaling  Translation P’ = P + d  Rotation in two coordinates about origin cos th -sin th sin th cos th

Rotation (cont)  Properties of rotations –one fixed point –can be composed from two-dimensional rotation in different coordinates –define positive rotation in plane if rotation is counterclockwise when viewed down normal to plane –is a rigid-body transformation  shape is not changed

Scaling  An affine non-rigid body transformation  Multiply coordinate by some factor  Negative multiplication produces reflection

Affine Transformations in Homogeneous Cooridnates  All represented by linear transformations  4x4 matrix with last row  Translation by a b c, and inverse a a b0 1 0 –b c c

Scaling  Multiply axes by a, b, c respectively a b c  Inverse comes from 1/a, 1/b, 1/c

Rotation  Can compose z, x, and y rotations by thz, thx, thy  Inverse is rotation by –thz, -thx, -thy  It can be shown that R -1 = R T –Matrices satisfying this property are said to be orthogonal

Shear  Shear in the x axis is defined by x’ = x + y cot th  Inverse users -th

Concatenation of Transforms  A sequence of transformations with T 1 followed by T 2 followed by T 3 can be composed as T 3 (T 2 (T 1 (p)))  If the corrersponding matrices are A, B, C this yields M = CBA  Thus a concatenation of transformations can be represented by a single matrix

Composed Transformaitons  Rotation in z about a fixed point T(p)R z (th)T(-p)  General rotation R x (thx) R y (thy) R z (thz)

Rotation about given vector  First change coordinates so given vector is on a coordinate axis –Use unit vector to avoid scaling  Then rotate about that coordinate axis  Finally restore to original coordinate system  Can translate for fixed point as before

Instance Transformations  When a particular kind of figure is used many times in a scene, it is convenient to construct one prototype and draw the objects by transforming that prototype  Convention is to center prototype on center of mass and then scale, rotate, and translate: TRS

Open GL Transformation Matrices  Current Transformation Matrix (CTM) is part of the pipeline  It can be set or modified  After setting matrix mode glLoadMatrixf(*matrix); //load matrix glLoadIdentity();

OpenGL Transformations  OpenGL has functions to perform basic operations glRotatef(angle, vx, vy, vz); // rotate about vector v glTranslatef(dx, dy, dz); glScalef(sx, sy, sz);  Applied in order called

OpenGL Rotation about Point  Rotate 45 o about line through origin and (1, 2, 3) with fixed point (4, 5, 6) glMatrixMode(GL_MODELVIEW);glLoadIdentity(); glTranslatef(4.0, 5.0, 6.0); glRotatef(45.0, 1.0, 2.0, 3.0); glTranslatef(-4.0, -5.0, -6.0);

Spinning the Cube  Mouse button click sets rotation axis  Idle callback adjusts rotation theta on selected axis  Display uses glRotatef() to set cube at desired angles in 3-d

Loading, Pushing, Popping  Can push and pop save and restore matrix –Projection stack is often limited to 2 levels; don’t usually transform it  Can load matrix from array with glLoadMatrix(myArray);  And multiply by our own matrix with glMultMatrix(myArray);  Can’t get OpenGL matrix into array

Smooth Rotation  Rotation is an arbitrary direction is equivalent to rotation about a great circle connecting the start and end positions of a point  Can recompute this incrementally –but requires much computation  Altenatively can compute one incremental step, save it, and then glMultMatrixf() for each step –Saves much computation