Lecture 3: Coordinate Systems and Transformations

Similar documents
Lecture L3 - Vectors, Matrices and Coordinate Transformations

Geometric Transformation CS 211A

Unified Lecture # 4 Vectors

TWO-DIMENSIONAL TRANSFORMATION

Linear Algebra Notes for Marsden and Tromba Vector Calculus

521493S Computer Graphics. Exercise 2 & course schedule change

Chapter 17. Orthogonal Matrices and Symmetries of Space

CS 4204 Computer Graphics

The Matrix Elements of a 3 3 Orthogonal Matrix Revisited

9.4. The Scalar Product. Introduction. Prerequisites. Learning Style. Learning Outcomes

Figure 1.1 Vector A and Vector F

Given a point cloud, polygon, or sampled parametric curve, we can use transformations for several purposes:

5.3 The Cross Product in R 3

Section 9.1 Vectors in Two Dimensions

Lectures notes on orthogonal matrices (with exercises) Linear Algebra II - Spring 2004 by D. Klain

Physics 235 Chapter 1. Chapter 1 Matrices, Vectors, and Vector Calculus

NOTES ON LINEAR TRANSFORMATIONS

5. Orthogonal matrices

Systems of Linear Equations

Rotation Matrices and Homogeneous Transformations

Cross product and determinants (Sect. 12.4) Two main ways to introduce the cross product

2D Geometric Transformations

1.3. DOT PRODUCT If θ is the angle (between 0 and π) between two non-zero vectors u and v,

Linear Algebra: Vectors

A vector is a directed line segment used to represent a vector quantity.

9 Multiplication of Vectors: The Scalar or Dot Product

Chapter 6. Linear Transformation. 6.1 Intro. to Linear Transformation

1 Introduction to Matrices

28 CHAPTER 1. VECTORS AND THE GEOMETRY OF SPACE. v x. u y v z u z v y u y u z. v y v z

Essential Mathematics for Computer Graphics fast

Lecture 14: Section 3.3

Lecture L22-2D Rigid Body Dynamics: Work and Energy

α = u v. In other words, Orthogonal Projection

3 Orthogonal Vectors and Matrices

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS. + + x 2. x n. a 11 a 12 a 1n b 1 a 21 a 22 a 2n b 2 a 31 a 32 a 3n b 3. a m1 a m2 a mn b m

Section 9.5: Equations of Lines and Planes

Solving Simultaneous Equations and Matrices

Mechanics lecture 7 Moment of a force, torque, equilibrium of a body

Section 1.4. Lines, Planes, and Hyperplanes. The Calculus of Functions of Several Variables

A linear combination is a sum of scalars times quantities. Such expressions arise quite frequently and have the form

Computer Graphics Labs

v w is orthogonal to both v and w. the three vectors v, w and v w form a right-handed set of vectors.

Orthogonal Projections

Geometry of Vectors. 1 Cartesian Coordinates. Carlo Tomasi

Section 5.3. Section 5.3. u m ] l jj. = l jj u j + + l mj u m. v j = [ u 1 u j. l mj

Vector Math Computer Graphics Scott D. Anderson

Vector Notation: AB represents the vector from point A to point B on a graph. The vector can be computed by B A.

Geometric Transformations

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS

LS.6 Solution Matrices

Part I. Basic Maths for Game Design

MATH10212 Linear Algebra. Systems of Linear Equations. Definition. An n-dimensional vector is a row or a column of n numbers (or letters): a 1.

Adding vectors We can do arithmetic with vectors. We ll start with vector addition and related operations. Suppose you have two vectors

13 MATH FACTS a = The elements of a vector have a graphical interpretation, which is particularly easy to see in two or three dimensions.

Geometric Camera Parameters

AP Physics - Vector Algrebra Tutorial

Methods for Finding Bases

[1] Diagonal factorization

MATH 304 Linear Algebra Lecture 18: Rank and nullity of a matrix.

1 VECTOR SPACES AND SUBSPACES

1 Symmetries of regular polyhedra

Equations Involving Lines and Planes Standard equations for lines in space

Geometric Transformations

Lecture 7. Matthew T. Mason. Mechanics of Manipulation. Lecture 7. Representing Rotation. Kinematic representation: goals, overview

PLANE TRUSSES. Definitions

Inner Product Spaces

5 VECTOR GEOMETRY. 5.0 Introduction. Objectives. Activity 1

Similarity and Diagonalization. Similar Matrices

One advantage of this algebraic approach is that we can write down

MATH2210 Notebook 1 Fall Semester 2016/ MATH2210 Notebook Solving Systems of Linear Equations... 3

2D Geometrical Transformations. Foley & Van Dam, Chapter 5

Least-Squares Intersection of Lines

Vectors 2. The METRIC Project, Imperial College. Imperial College of Science Technology and Medicine, 1996.

Vector has a magnitude and a direction. Scalar has a magnitude

12.5 Equations of Lines and Planes

Content. Chapter 4 Functions Basic concepts on real functions 62. Credits 11

Notes on Determinant

EDEXCEL NATIONAL CERTIFICATE/DIPLOMA MECHANICAL PRINCIPLES AND APPLICATIONS NQF LEVEL 3 OUTCOME 1 - LOADING SYSTEMS

Solutions to Math 51 First Exam January 29, 2015

BALTIC OLYMPIAD IN INFORMATICS Stockholm, April 18-22, 2009 Page 1 of?? ENG rectangle. Rectangle

Matrix Representations of Linear Transformations and Changes of Coordinates

Recall that two vectors in are perpendicular or orthogonal provided that their dot

MATH 304 Linear Algebra Lecture 20: Inner product spaces. Orthogonal sets.

Recall the basic property of the transpose (for any A): v A t Aw = v w, v, w R n.

Matrix Differentiation

Computing Euler angles from a rotation matrix

Let s first see how precession works in quantitative detail. The system is illustrated below: ...

Epipolar Geometry. Readings: See Sections 10.1 and 15.6 of Forsyth and Ponce. Right Image. Left Image. e(p ) Epipolar Lines. e(q ) q R.

Section 1.1. Introduction to R n

MATH APPLIED MATRIX THEORY

discuss how to describe points, lines and planes in 3 space.

Georgia Department of Education Kathy Cox, State Superintendent of Schools 7/19/2005 All Rights Reserved 1

Chapter 19. General Matrices. An n m matrix is an array. a 11 a 12 a 1m a 21 a 22 a 2m A = a n1 a n2 a nm. The matrix A has n row vectors

Introduction to Matrix Algebra

Section Inner Products and Norms

Mathematics Course 111: Algebra I Part IV: Vector Spaces

Vectors Math 122 Calculus III D Joyce, Fall 2012

13.4 THE CROSS PRODUCT

Elasticity Theory Basics

Transcription:

Lecture 3: Coordinate Systems and Transformations Topics: 1. Coordinate systems and frames 2. Change of frames 3. Affine transformations 4. Rotation, translation, scaling, and shear 5. Rotation about an arbitrary axis Chapter 4, Sections 4.3, 4.5, 4.6, 4.7, 4.8, 4.9. 1

Coordinate systems and frames Recall that a vector v lr 3 can be represented as a linear combination of three linearly independent basis vectors v 1, v 2, v 3, v = α 1 v 1 + α 2 v 2 + α 3 v 3. The scalars α 1, α 2, α 3 are the coordinates of v. v 1 = (1, 0, 0), v 2 = (0, 1, 0), v 3 = (0, 0, 1). We typically choose v 2 v = α 1 v 1 + α 2 v 2 + α 3 v 3 α 1 v 1 v 3 2

Suppose we want to (linearly) change the basis vectors v 1, v 2, v 3 to u 1, u 2, u 3. We express the new basis vectors as combinations of the old ones, u 1 = a 11 v 1 + a 12 v 2 + a 13 v 3, u 2 = a 21 v 1 + a 22 v 2 + a 23 v 3, u 3 = a 31 v 1 + a 32 v 2 + a 33 v 3, and thus obtain a 3 3 change of basis matrix M = a 11 a 12 a 13 a 21 a 22 a 23 a 31 a 32 a 33 If the two representations of a given vector v are v = a T v 1 v 2 v 3., and v = b T u 1 u 2, u 3 where a = ( α 1 α 2 α 3 ) T and b = ( β 1 β 2 β 3 ) T, then a T which implies that v 1 v 2 v 3 = v = b T u 1 u 2 = b T M u 3 a = M T b and b = (M T ) 1 a. v 1 v 2 v 3, 3

This 3D coordinate system is not, however, rich enough for use in computer graphics. Though the matrix M could be used to rotate and scale vectors, it cannot deal with points, and we want to be able to translate points (and objects). In fact an arbitary affine transformation can be achieved by multiplication by a 3 3 matrix and shift by a vector. However, in computer graphics we prefer to use frames to achieve the same thing. A frame is a richer coordinate system in which we have a reference point P 0 in addition to three linearly independent basis vectors v 1, v 2, v 3, and we represent vectors v and points P, differently, as v = α 1 v 1 + α 2 v 2 + α 3 v 3, P = P 0 + α 1 v 1 + α 2 v 2 + α 3 v 3. We can use vector and matrix notation and re-express the vector v and point P as v 1 v = ( α 1 α 2 α 3 v 0 ) 2, and P = ( α v 1 α 2 α 3 1 ) 3 P 0 The coefficients α 1, α 2, α 3, 0 and α 1, α 2, α 3, 1 are the homogeneous coordinates of v and P respectively. v 1 v 2 v 3 P 0. 4

Change of frames Suppose we want to change from the frame (v 1, v 2, v 3, P 0 ) to a new frame (u 1, u 2, u 3, Q 0 ). We express the new basis vectors and reference point in terms of the old ones, u 1 = a 11 v 1 + a 12 v 2 + a 13 v 3, u 2 = a 21 v 1 + a 22 v 2 + a 23 v 3, u 3 = a 31 v 1 + a 32 v 2 + a 33 v 3, Q 0 = a 41 v 1 + a 42 v 2 + a 43 v 3 + P 0, and thus obtain a 4 4 matrix a 11 a 12 a 13 0 a M = 21 a 22 a 23 0. a 31 a 32 a 33 0 a 41 a 42 a 43 1 Similar to 3D vector coordinates, we suppose now that a and b are the homogeneous representations of the same point or vector with respect to the two frames. Then a T which implies that v 1 v 2 v 3 P 0 = b T u 1 u 2 u 3 Q 0 = b T M v 1 v 2 v 3 P 0 a = M T b and b = (M T ) 1 a., 5

Affine transformations The transposed matrix a 11 a 21 a 31 a 41 M T a = 12 a 22 a 32 a 42, a 13 a 23 a 33 a 43 0 0 0 1 simply represents an arbitrary affine transformation, having 12 degrees of freedom. These degrees of freedom can be viewed as the nine elements of a 3 3 matrix plus the three components of a vector shift. The most important affine transformations are rotations, scalings, and translations, and in fact all affine transformations can be expressed as combinaitons of these three. Affine transformations preserve line segments. If a line segment P (α) = (1 α)p 0 + αp 1 is expressed in homogeneous coordinates as p(α) = (1 α)p 0 + αp 1, with respect to some frame, then an affine transformation matrix M sends the line segment P into the new one, Mp(α) = (1 α)mp 0 + αmp 1. Similarly, affine transformations map triangles to triangles and tetrahedra to tetrahedra. Thus many objects in OpenGL can be transformed by transforming their vertices only. 6

Rotation, translation, scaling, and shear Translation is an operation that displaces points by a fixed distance in a given direction. If the displacement vector is d then the point P will be moved to P = P + d. We can write this equation in homeogeneous coordinates as p = p + d, where so that p = x y, p = z 1 x y z, d = 1 α x α y. α z 0 x = x + α x, y = y + α y, z = z + α z. So the transformation matrix T which gives p = T p is clearly 1 0 0 α x 0 1 0 α T = T (α x, α y, α z ) = y, 0 0 1 α z 0 0 0 1 called the translation matrix. One can check that the inverse is T 1 (α x, α y, α z ) = T ( α x, α y, α z ). 7

Rotation depends on an axis of rotation and the angle turned through. Consider first rotation in the plane, about the origin. If a point (x, y) with coordinates x = ρ cos φ, y = ρ sin φ, is rotated through an angle θ, then the new position is (x, y ), where x = ρ cos(φ + θ), y = ρ sin(φ + θ). Expanding these latter expressions, we find x = x cos θ y sin θ, y = x sin θ + y cos θ, or ( ) ( x cos θ sin θ y = sin θ cos θ ) ( ) x. y y y x x 8

Thus the three rotation matrices corresponding to rotation about the z, x, and y axes in lr 3 are: cos θ sin θ 0 0 sin θ cos θ 0 0 R z = R z (θ) =, 0 0 1 0 0 0 0 1 1 0 0 0 0 cos θ sin θ 0 R x = R x (θ) =, 0 sin θ cos θ 0 0 0 0 1 cos θ 0 sin θ 0 0 1 0 0 R y = R y (θ) =. sin θ 0 cos θ 0 0 0 0 1 All three give positive rotations for positive θ with respect to the right hand rule for the axes x, y, z. If R = R(θ) denotes any of these matrices, its inverse is clearly R 1 (θ) = R( θ) = R T (θ). Translations and rotations are examples of solid-body transformations: transformations which do not alter the size or shape of an object. 9

Scaling can be applied in any of the three axes independently. If we send a point (x, y, z) to the new point x = β x x, y = β y y, z = β z z, then the corresponding matrix becomes with inverse β x 0 0 0 0 β S = S(β x, β y, β z ) = y 0 0, 0 0 β z 0 0 0 0 1 S 1 (β x, β y, β z ) = S(1/β x, 1/β y, 1/β z ). If the scaling factors β x, β y, β z are equal then the scaling is uniform: objects retain their shape but alter their size. Otherwise the scaling is non-uniform and the object is deformed. 10

Shears can be constructed from translations, rotations, and scalings, but are sometimes of independent interest. y y x x z z A shear in the x direction is defined by x = x + (cot θ)y, y = y, z = z, for some scalar a. The corresponding shearing matrix is therefore 1 cot θ 0 0 0 1 0 0 H x (θ) =, 0 0 1 0 0 0 0 1 with inverse Hx 1 (θ) = H x ( θ). 11

Rotation about an arbitrary axis How do we find the matrix which rotates an object about an arbitrary point p 0 and around a direction u = p 2 p 1, through an angle θ? y p 2 u p 1 x p 0 z The answer is to concatenate some of the matrices we have already developed. We will assume that u has length 1. The first step is to use translation to reduce the problem to that of rotation about the origin: M = T (p 0 ) R T ( p 0 ). To find the rotation matrix R for rotation around the vector u, we first align u with the z axis using two rotations θ x and θ y. Then we can apply a rotation of θ around the z-axis and afterwards undo the alignments, thus R = R x ( θ x )R y ( θ y )R z (θ)r y (θ y )R x (θ x ). 12

It remains to calculate θ x and θ y from u = (α x, α y, α z ). The first rotation R x (θ x ) will rotate the vector u around the x axis until it lies in the y = 0 plane. Using simple trigonometry, we find that where d = cos θ x = α z /d, sin θ x = α y /d, α 2 y + α 2 z, so, without needing θ x explicitly, we find R x (θ x ) = 1 0 0 0 0 α z /d α y /d 0. 0 α y /d α z /d 0 0 0 0 1 In the second alignment we find cos θ y = d, sin θ y = α x, and so R y (θ y ) = d 0 α x 0 0 1 0 0. α x 0 d 0 0 0 0 1 13

Example in OpenGL The following OpenGL sequence sets the model-view matrix to represent a 45-degree rotation about the line through the origin and the point (1, 2, 3) with a fixed point of (4, 5, 6): void myinit(void) { 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); } OpenGL concatenates the three matrices into the single matrix C = T (4, 5, 6) R(45, 1, 2, 3) T ( 4, 5, 6). Each vertex p specified after this code will be multiplied by C to yield q, q = Cp. 14

Spinning the Cube The following program rotates a cube, using the three buttons of the mouse. There are three callbacks: glutdisplayfunc(display); glutidlefunc(spincube); glutmousefunc(mouse); The display callback sets the model-view matrix with three angles determined by the mouse callback, and then draws the cube (see Section 4.4 of the book). void display() { glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); glloadidentity(); glrotatef(theta[0], 1.0, 0.0, 0.0); glrotatef(theta[1], 0.0, 1.0, 0.0); glrotatef(theta[2], 0.0, 0.0, 1.0); colorcube(); glutswapbuffers(); } 15

The mouse callback selects the axis of rotation. void mouse(int btn, int state, int x, int y) { if(btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN) axis = 0; if(btn == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) axis = 1; if(btn == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) axis = 2; } The idle callback increments the angle of the chosen axis by 2 degrees. void spincube() { theta[axis] += 2.0; if(theta[axis] >= 360.0) theta[axis] -= 360.0; glutpostredisplay(); } 16

A little bit about quarternions Quarternions offer an alternative way of describing rotations, and have been used in hardware implementations. In the complex plane, rotation through an angle φ can be expressed as multiplication by the complex number e iφ = cos φ + i sin φ. This rotates a given point re iθ in the complex plane to the new point re iθ e iφ = re i(θ+φ). Analogously, quarternions can be used to elegantly describe rotations in three dimensions. A quarternion consists of a scalar and a vector, a = (q 0, q 1, q 2, q 3 ) = (q 0, q). We can write the vector part q as q = q 1 i + q 2 j + q 3 k, where i, j, k play a similar role to that of the unit vectors in lr 3, and obey the properties i 2 = j 2 = k 2 = 1, and ij = k = ji, jk = i = kj, ki = j = ik. 17

These properties imply that the sum and multiple of two quarternions a = (q 0, q) and b = (p 0, p) are a + b = (q 0 + p 0, q + p), and ab = (q 0 p 0 q p, q 0 p + p 0 q + q p). The magnitude and inverse of a are a = q0 2 + q q, a 1 = 1 a (q 0, q). Rotation. Suppose now that v is a unit vector in lr 3, and let p be an arbitrary point. Denote by p the rotation of p about the axis v, placed at the origin. To find p using quarternions, we let r be the quarterion r = (cos(θ/2), sin(θ/2)v), of unit length, whose inverse is clearly r 1 = (cos(θ/2), sin(θ/2)v). Then if p and p are the quarternions p = (0, p), p = (0, p ), we claim that p = r 1 pr. 18

Let s check that this is correct! Following the rule for multiplication, a little computation shows that p does indeed have the form (0, p ), and that p = cos 2 θ 2 p + θ sin2 2 (v p)v + 2 sin θ 2 cos θ 2 (v p) + θ sin2 v (v p). 2 But using the identity p = (v p)v v (v p), (1) and the multiple-angle formulas for cos and sin, this simplifies to p = (v p)v + cos θ(v p) v + sin θ(v p). This formula can easily be verified from a geometric interpretation. It is a linear combination of three orthogonal vectors. The first term (v p)v is the projection of p onto the axis of rotation, and the second and third terms describe a rotation in the plane perpendicular to v. Notice also that the formula clearly represents an affine transformation; all terms are linear in p. The formula can be used to find the coefficients of the corresponding transformation matrix directly. 19