Computer Graphics Bing-Yu Chen National Taiwan University.

Slides:



Advertisements
Similar presentations
Today Composing transformations 3D Transformations
Advertisements

Points, Vectors, Lines, Spheres and Matrices
1Computer Graphics Homogeneous Coordinates & Transformations Lecture 11/12 John Shearer Culture Lab – space 2
Transformations Ed Angel Professor Emeritus of Computer Science
Computer Graphics Lecture 4 Geometry & Transformations.
Geometric Transformations
Two-Dimensional Geometric Transformations
Chapter 4.1 Mathematical Concepts
Computer Graphics Recitation 2. 2 The plan today Learn about rotations in 2D and 3D. Representing rotations by quaternions.
Chapter 4.1 Mathematical Concepts. 2 Applied Trigonometry Trigonometric functions Defined using right triangle  x y h.
CS5500 Computer Graphics March 22, Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Coordinate-Free Geometry When we learned simple.
Ch. 2: Rigid Body Motions and Homogeneous Transforms
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
3-D Geometry.
3D orientation.
Transformations. 2 Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Coordinate-Free Geometry When we learned simple geometry, most of us.
Representation CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Transformations CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Vectors.
3D Graphics Goal: To produce 2D images of a mathematically described 3D environment Issues: –Describing the environment: Modeling (mostly later) –Computing.
Geometric Objects and Transformations Geometric Entities Representation vs. Reference System Geometric ADT (Abstract Data Types)
1 Kinematics ( 運動學 ) Primer Jyun-Ming Chen Fall 2009.
Mathematical Fundamentals
COS 397 Computer Graphics Svetla Boytcheva AUBG, Spring 2013.
Graphics CSE 581 – Interactive Computer Graphics Mathematics for Computer Graphics CSE 581 – Roger Crawfis (slides developed from Korea University slides)
Chapter 4.1 Mathematical Concepts
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.
CS 450: COMPUTER GRAPHICS QUATERNIONS SPRING 2015 DR. MICHAEL J. REALE.
CS 480/680 Computer Graphics Transformations Dr. Frederick C Harris, Jr.
Mathematical Foundations Sections A-1 to A-5 Some of the material in these slides may have been adapted from university of Virginia, MIT and Åbo Akademi.
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
Dx = 2 dy = 3 Y X D Translation A translation is applied to an object by repositioning it along a straight-line path.
Intro to 3D Models Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CSE 681 Review: Transformations. CSE 681 Transformations Modeling transformations build complex models by positioning (transforming) simple components.
Transformations Jehee Lee Seoul National University.
1 CS 430/536 Computer Graphics I 3D Transformations World Window to Viewport Transformation Week 2, Lecture 4 David Breen, William Regli and Maxim Peysakhov.
Advanced Computer Graphics Spring 2014
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Transformations of Objects – 3D
Geometric Objects and Transformation
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
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.
UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS Math Review.
Affine Geometry.
1 Representation. 2 Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames.
CS559: Computer Graphics Lecture 9: 3D Transformation and Projection Li Zhang Spring 2010 Most slides borrowed from Yungyu ChuangYungyu Chuang.
Euler Angles This means, that we can represent an orientation with 3 numbers Assuming we limit ourselves to 3 rotations without successive rotations about.
Homogeneous Coordinates and Matrix Representations Cartesian coordinate (x, y, z) Homogeneous coordinate (x h, y h, z h, h) Usually h = 1. But there are.
Computer Graphics I, Fall 2010 Transformations.
Week 5 - Monday.  What did we talk about last time?  Lines and planes  Trigonometry  Transforms  Affine transforms  Rotation  Scaling  Shearing.
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,
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Fundamentals of Computer Animation Orientation and Rotation.
Graphics Graphics Korea University kucg.korea.ac.kr Mathematics for Computer Graphics 고려대학교 컴퓨터 그래픽스 연구실.
Objectives Introduce standard transformations Introduce standard transformations Derive homogeneous coordinate transformation matrices Derive homogeneous.
CA 302 Computer Graphics and Visual Programming
Transformations Objectives
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.
2D Geometric Transformations
CSE 411 Computer Graphics Lecture #2 Mathematical Foundations
Transformations Ed Angel
Geometric Objects and Transformations (II)
Transformations Ed Angel Professor Emeritus of Computer Science
Isaac Gang University of Mary Hardin-Baylor
Game Programming Algorithms and Techniques
Presentation transcript:

Computer Graphics Bing-Yu Chen National Taiwan University

Geometrical Transformations  Mathematical Preliminaries  2D Transformations  Homogeneous Coordinates  3D Transformations  Quaternions 1

Vectors  A vector is an entity that possesses magnitude and direction.  A ray (directed line segment), that possesses position, magnitude, and direction. 2

Vectors  an n-tuple of real numbers (scalars)  two operations: addition & multiplication  Commutative Laws a + b = b + a a b = b a  Identities a + 0 = a a 1 = a  Associative Laws (a + b) + c = a + (b + c) (a b) c = a (b c)  Distributive Laws a (b + c) = a b + a c (a + b) c = a c + b c  Inverse a + b = 0 b = -a 3

Addition of Vectors  parallelogram rule 4

The Vector Dot Product  length = 5

Properties of the Dot Product  symmetric  nondegenerate only when  bilinear  unit vector (normalizing)  angle between the vectors 6

Projection 7

Cross Product of Vectors  Definition where are standard unit vectors  Application A normal vector to a polygon is calculated from 3 (non-collinear) vertices of the polygon. 8

Matrices  matrix multiplication  identity matrix  determinant  cross product  matrix transpose  matrix inverse 9

Matrix Basics  Definition  Transpose  Addition 10

Matrix Basics  Scalar-matrix multiplication  Matrix-matrix multiplication  Matrix multiplication are not commutative 11

General Transformations  A transformation maps points to other points and/or vectors to other vectors 12

Pipeline Implementation transformationrasterizer vertices pixels frame buffer (from application program) 13

Representation  We can represent a point, in the plane as a column vector as a row vector 14

2D Transformations  2D Translation  2D Scaling  2D Reflection  2D Shearing  2D Rotation 15

Translation  Move (translate, displace) a point to a new location  Displacement determined by a vector d Three degrees of freedom P ’ =P+d P P’ d 16

2D Translation y x (4,5)(7,5) y x (7,1)(10,1) 17

2D Scaling y x (4,5)(7,5) y x (2,5/4) (7/2,5/4) 18

2D Reflection y x (4,5)(7,5) y x (-7,5)(-4,5) 19

2D Shearing y x (4,5)(7,5) y x (9,5)(12,5) 20

2D Rotation y x (4,5)(7,5) y x (2.1,4.9) (4.9,7.8) 21

2D Rotation  Consider rotation about the origin by  degrees radius stays the same, angle increases by  x’=x cos  –y sin  y’ = x sin  + y cos  x = r cos  y = r sin  x’ = r cos (  y’ = r sin (  22

Limitations of a 2X2 matrix  Scaling  Rotation  Reflection  Shearing  What do we miss? 23

Homogeneous Coordinates  Why & What is homogeneous coordinates ? if points are expressed in homogeneous coordinates, all transformations can be treated as multiplications. usually 1 can not be 0 24

Homogeneous Coordinates X Y W P W=1 plane 25

Homogeneous Coordinates for 2D Translation 26

Homogeneous Coordinates for 2D Translation 27

Homogeneous Coordinates for 2D Scaling 28

Homogeneous Coordinates for 2D Rotation 29

Properties of Transformations  rigid-body transformations rotation & translation preserving angles and lengths  affine transformations rotation & translation & scaling preserving parallelism of lines 30

Composition of 2D Transformations Original After translation of P 1 to origin After rotation After translation to original P 1 P1P1 P1P1 x y x y x y x y 31

Composition of 2D Transformations 32

The Window-to-Viewport Transformation Viewport 1 Viewport 2 Window World coordinatesScreen coordinates Maximum range of screen coordinates 33

The Window-to-Viewport Transformation Window in world coordinates Translated to origin Scaled to size of viewport Translated to final position x y x y u v u v (x min,y min ) (x max,y max ) (u min,v min ) (u max,v max ) Maximum range of screen coordinates 34

Right-handed Coordinate System 35

3D Translation & 3D Scaling 36

3D Reflection & 3D Shearing 37

3D Rotations 38

Rotation About a Fixed Point other than the Origin  Move fixed point to origin  Rotate  Move fixed point back  39

Rotation About an Arbitrary Axis  A rotation by about an arbitrary axis can be decomposed into the concatenation of rotations about the,, and axes,, are called the Euler angles  Note that rotations do not commute We can use rotations in another order but with different angles. 40

Euler Angles  An Euler angle is a rotation about a single axis.  A rotation is described as a sequence of rotations about three mutually orthogonal coordinates axes fixed in space X-roll, Y-roll, Z-roll X-roll, Y-roll, Z-roll  There are 6 possible ways to define a rotation. 3! 41

Euler Angles & Interpolation  Interpolation happening on each angle  Multiple routes for interpolation  More keys for constrains z x y R z x y R 42

Interpolating Euler Angles  Natural orientation representation: 3 angles for 3 degrees of freedom  Unnatural interpolation: A rotation of 90 o first around Z and then around Y = 120 o around (1, 1, 1). But 30 o around Z then Y differs from 40 o around (1, 1, 1). a b c a c b a b c = a b c c b a a b c a b c a b c 43

Smooth Rotation  From a practical standpoint, we are often want to use transformations to move and reorient an object smoothly Problem: find a sequence of model-view matrices,,…, so that when they are applied successively to one or more objects we see a smooth transition  For orientating an object, we can use the fact that every rotation corresponds to part of a great circle on a sphere Find the axis of rotation and angle Virtual trackball 44

Incremental Rotation  Consider the two approaches For a sequence of rotation matrices,,…,, find the Euler angles for each and use  Not very efficient Use the final positions to determine the axis and angle of rotation, then increment only the angle  Quaternions can be more efficient than either 45

Solution: Quaternion Interpolation  Interpolate orientation on the unit sphere  By analogy: 1-, 2-, 3-DOF rotations as constrained points on 1-, 2-, 3- spheres 46

1D-Sphere and Complex Plane  Interpolate orientation in 2D  1 angle but messy because modulo  Use interpolation in (complex) 2D plane  Orientation = complex argument of the number 47

Quaternions  Quaternions are unit vectors on 3- sphere (in 4D)  Right-hand rotation of radians about is often noted  Requires one real and three imaginary components,, where is called scalar and is called vector 48

Quaternions  Extension of imaginary numbers from 2 to 3 dimensions  Requires one real and three imaginary components,, where is called scalar and is called vector  Quaternions can express rotations on sphere smoothly and efficiently. Process: Model-view matrix  Quaternion Carry out operations with Quaternions Quaternion  Model-view matrix 49

Basic Operations Using Quaternions  Addition  Multiplication  Conjugate  Length  Norm  Inverse  Unit Quaternion is a unit quaternion if and then  Identity [1, (0, 0, 0)] (when involving multiplication) [0, (0, 0, 0)] (when involving addition) 50

Angle and Axis & Eular Angles  Angle and Axis  Eular Angles  51

Matrix-to-Quaternion Conversion MatToQuat (float m[4][4], QUAT * quat) { float tr, s, q[4]; int i, j, k; int nxt[3] = {1, 2, 0}; tr = m[0][0] + m[1][1] + m[2][2]; if (tr > 0.0) { s = sqrt (tr + 1.0); quat->w = s / 2.0; s = 0.5 / s; quat->x = (m[1][2] - m[2][1]) * s; quat->y = (m[2][0] - m[0][2]) * s; quat->z = (m[0][1] - m[1][0]) * s; } else { i = 0; if (m[1][1] > m[0][0]) i = 1; if (m[2][2] > m[i][i]) i = 2; j = nxt[i]; k = nxt[j]; s = sqrt ((m[i][i] - (m[j][j] + m[k][k])) + 1.0); q[i] = s * 0.5; if (s != 0.0) s = 0.5 / s; q[3] = (m[j][k] - m[k][j]) * s; q[j] = (m[i][j] + m[j][i]) * s; q[k] = (m[i][k] + m[k][i]) * s; quat->x = q[0]; quat->y = q[1]; quat->z = q[2]; quat->w = q[3]; } 52

Quaternion-to-Matrix Conversion QuatToMatrix (QUAT * quat, float m[4][4]) { float wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2; x2 = quat->x + quat->x; y2 = quat->y + quat->y; z2 = quat->z + quat->z; xx = quat->x * x2; xy = quat->x * y2; xz = quat->x * z2; yy = quat->y * y2; yz = quat->y * z2; zz = quat->z * z2; wx = quat->w * x2; wy = quat->w * y2; wz = quat->w * z2; m[0][0] = (yy + zz); m[1][0] = xy - wz; m[2][0] = xz + wy; m[3][0] = 0.0; m[0][1] = xy + wz; m[1][1] = (xx + zz); m[2][1] = yz - wx; m[3][1] = 0.0; m[0][2] = xz - wy; m[1][2] = yz + wx; m[2][2] = (xx + yy); m[3][2] = 0.0; m[0][3] = 0; m[1][3] = 0; m[2][3] = 0; m[3][3] = 1; } 53

SLERP-Spherical Linear intERPolation  Interpolate between two quaternion rotations along the shortest arc.  where  If two orientations are too close, use linear interpolation to avoid any divisions by zero. 54