COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates

Similar documents
Graphics and Interaction Transformation geometry and homogeneous coordinates

COMP30019 Graphics and Interaction Three-dimensional transformation geometry and perspective

2D and 3D Transformations AUI Course Denbigh Starkey

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

Math background. 2D Geometric Transformations. Implicit representations. Explicit representations. Read: CS 4620 Lecture 6

Vector Algebra Transformations. Lecture 4

Transforms. COMP 575/770 Spring 2013

Geometric transformations assign a point to a point, so it is a point valued function of points. Geometric transformation may destroy the equation

2D Image Transforms Computer Vision (Kris Kitani) Carnegie Mellon University

2D/3D Geometric Transformations and Scene Graphs

CT5510: Computer Graphics. Transformation BOCHANG MOON

2D Object Definition (1/3)

1 Affine and Projective Coordinate Notation

UNIT 2 2D TRANSFORMATIONS

Game Engineering: 2D

Lecture 5 2D Transformation

Linear algebra deals with matrixes: two-dimensional arrays of values. Here s a matrix: [ x + 5y + 7z 9x + 3y + 11z

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

Visual Recognition: Image Formation

Chapter 2 - Basic Mathematics for 3D Computer Graphics

Section III: TRANSFORMATIONS

Transformations: 2D Transforms

Computer Graphics Geometric Transformations

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

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

Overview. Affine Transformations (2D and 3D) Coordinate System Transformations Vectors Rays and Intersections

Vector Calculus: Understanding the Cross Product

Background for Surface Integration

Chapter 1. Linear Equations and Straight Lines. 2 of 71. Copyright 2014, 2010, 2007 Pearson Education, Inc.

Geometric Transformations

Matrices. Chapter Matrix A Mathematical Definition Matrix Dimensions and Notation

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

CALCULATING TRANSFORMATIONS OF KINEMATIC CHAINS USING HOMOGENEOUS COORDINATES

Geometry for Computer Graphics Part 1

Overview. By end of the week:

MATHEMATICS FOR ENGINEERING TUTORIAL 5 COORDINATE SYSTEMS

GEOMETRIC TRANSFORMATIONS AND VIEWING

Polynomials. Math 4800/6080 Project Course

Mastery. PRECALCULUS Student Learning Targets

2D and 3D Coordinate Systems and Transformations

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

2-9 Operations with Complex Numbers

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6

Coordinate transformations. 5554: Packet 8 1

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6. ) is graphed below:

Coordinate Transformations in Advanced Calculus

CSC418 / CSCD18 / CSC2504

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

PARAMETRIC EQUATIONS AND POLAR COORDINATES

COMP 558 lecture 19 Nov. 17, 2010

CS452/552; EE465/505. Geometry Transformations

(Refer Slide Time: 00:04:20)

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

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

Homework #1. Displays, Alpha Compositing, Image Processing, Affine Transformations, Hierarchical Modeling

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

Linear transformations Affine transformations Transformations in 3D. Graphics 2009/2010, period 1. Lecture 5: linear and affine transformations

Parallel Lines Investigation

Specifying Complex Scenes

Functions and Transformations

Today. Today. Introduction. Matrices. Matrices. Computergrafik. Transformations & matrices Introduction Matrices

Chapter 5. Transforming Shapes

Lecture 9: Transformations. CITS3003 Graphics & Animation

Math Boot Camp: Coordinate Systems

AQA GCSE Further Maths Topic Areas

Algebra II Trigonometric Functions

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

EECE 478. Learning Objectives. Learning Objectives. Linear Algebra and 3D Geometry. Linear algebra in 3D. Coordinate systems

CSE 252B: Computer Vision II

Calculus III. Math 233 Spring In-term exam April 11th. Suggested solutions

Hello, welcome to the video lecture series on Digital Image Processing. So in today's lecture

The Three Dimensional Coordinate System

Unit 3 Transformations and Clipping

+ i a y )( cosφ + isinφ) ( ) + i( a x. cosφ a y. = a x

Geometry I Can Statements I can describe the undefined terms: point, line, and distance along a line in a plane I can describe the undefined terms:

Chapter 18. Geometric Operations

Rectification and Distortion Correction

Isometries. 1 Identifying Isometries

Interactive Computer Graphics. Hearn & Baker, chapter D transforms Hearn & Baker, chapter 5. Aliasing and Anti-Aliasing

MATRIX REVIEW PROBLEMS: Our matrix test will be on Friday May 23rd. Here are some problems to help you review.

Generalized barycentric coordinates

Trigonometric ratios provide relationships between the sides and angles of a right angle triangle. The three most commonly used ratios are:

Cambridge IGCSE mapping

Affine Transformation. Edith Law & Mike Terry

Last week. Machiraju/Zhang/Möller

Computer Vision cmput 428/615

Chapter 2: Transformations. Chapter 2 Transformations Page 1

Algebra II. Slide 1 / 162. Slide 2 / 162. Slide 3 / 162. Trigonometric Functions. Trig Functions

Part 3: 2D Transformation

Unit 3 Higher topic list

SECONDARY DRAFT SYLLABUS. 2. Representation of functions. 3. Types of functions. 4. Composition of functions (two and three)

CLEP Pre-Calculus. Section 1: Time 30 Minutes 50 Questions. 1. According to the tables for f(x) and g(x) below, what is the value of [f + g]( 1)?

Image warping , , Computational Photography Fall 2017, Lecture 10

Goals: Course Unit: Describing Moving Objects Different Ways of Representing Functions Vector-valued Functions, or Parametric Curves

Linear Transformations

A lg e b ra II. Trig o n o m e tric F u n c tio

METR Robotics Tutorial 2 Week 2: Homogeneous Coordinates

Honors Precalculus: Solving equations and inequalities graphically and algebraically. Page 1

Early Fundamentals of Coordinate Changes and Rotation Matrices for 3D Computer Vision

Computer Graphics. Lecture 2. Doç. Dr. Mehmet Gokturk

Transcription:

COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates Department of Computer Science and Software Engineering The

Lecture outline Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Transformation geometry How are geometric transformations represented conveniently and efficiently? Aim: understand how two-dimensional (2D) transformations are combined conveniently and the benefits of homogeneous coordinates. Reading: Foley Sections 5.3 Homogeneous coordinates and matrix representation of 2D transformations, 5.4 Composition of 2D transformations and 5.6 Efficiency.

Review of two-dimensional (2D) geometry Points are represented either in absolute position, relative to origin in Cartesian coordinates: (x, y) R 2 or polar coordinates: (ρ, θ). [ ] vx Vectors represent relative displacement, v = and are subject to vector addition, subtraction, scalar product (dot product) or norm (magnitude) operations. v y

Curves can be modelled in either explicit functional form: y = F(x) or implicit equational form: G(x, y) = 0 or parametric form: e.g. some straight lines are: x = x(t) y = y(t) y = mx + b (explicit functional form) ax + by + c = 0 (implicit equational form) x cos θ + y sin θ = ρ (implicit equational form) x = x 0 + x 1 p(t), y = y 0 + y 1 p(t) (parametric form) Special forms include a line through two points or line segments such as endpoints or parameter bounds.

Geometric transformations General geometric transformations concern object points rather than transformation of the entire coordinate frame, x = g(x, y), y = h(x, y). More specific geometric transformations involve translations, where x = x + x t, and y = y + y t and linear transformations v = Mv (where v is a vector and M is a matrix) such as scaling, shear, rotation, reflection.

Vector and matrix conventions There are two conventions for vectors and matrices, the text (Rowe) uses this form, where vectors are written as columns: [ ] x v = y Matrices multiply on the left: Mv = = [ ] [ ] a b x c d y [ ] ax + by cx + dy

However, watch out for other forms where vectors are written as rows: v = [ x y ] [ ] T x = y Matrices multiply on the right: vm = [ x y ] [ ] a b c d [ ] ax + cy = bx + dy Really, you should understand the concepts, and be able to work with either notation.

Translation Translation is also known as shifting or displacement, where x = x + x t and y = y + y t. Translation in two-dimensional vector notation (by addition): [ ] x = y [ x y ] + [ xt y t ]

Rotation Rotation of an object about the origin

Rotation as a matrix operation (by multiplication): [ ] [ ] [ ] cos θ sin θ x x cos θ y sin θ = sin θ cos θ y x sin θ + y cos θ Convenient, as can combine a number of geometric rotations by multiplication, [ ] [ ] [ ] x cos θ sin θ x y = sin θ cos θ y Unfortunately translation is different to rotation, therefore can t treat as multiplication (also true for scaling). This means translations and rotations cannot be combined easily.

How are rotation matrices derived? ( 00, ) Increasing x f Increasing y q ( x, y ) ( xy, ) Hint: Consider the point above with polar coordinates (ρ, θ) (Rowe Fig 2.1). If rotated by angle φ around the origin, its polar coordinates are (ρ, θ + φ), converting to Cartesian coordinates gives, [ ] ρ cos(θ + φ) ρ sin(θ + φ)

We can expand and re-arrange this in terms of the cosine and sine angle-addition formulas, and the Cartesian coordinates of the original point x = ρ cos φ y = ρ sin φ to obtain a matrix expression for a rotation by angle θ. x = ρ cos(φ + θ) = ρ cos φ cos θ ρ sin φ sin θ y = ρ sin(φ + θ) = ρ cos φ sin θ + ρ sin φ cos θ x = ρ cos(φ + θ) =ρ cos φcos θ ρ sin φsin θ y = ρ sin(φ + θ) =ρ cos φsin θ+ρ sin φcos θ x = xcos θ ysin θ y = xsin θ+ycos θ

Rigid body transformations Rotation, translation, and reflection preserve distances (rigid motions). That is, if two points are a certain distance apart, they will still be the same distance apart after undergoing one of these transformations (or indeed any combination of them). Mathematically, they are the only transformations with this property of preserving distance.

Reflection Reflection in a line gives mirror image Move point to position at equal distance on opposite side of the line. Reflection in the x-axis: Reflection in the y-axis: x = x y = y x = x y = y

Reflection in the line y = x: x = y y = x All these can be expressed as matrix operations (details left to you). Reflections in an arbitrary line can be achieved by transforming line (by rotation and translation) to one of the coordinate axes, reflecting in that axis, and transforming back. Reflection reverses handedness an object goes to its mirror image. Rotation and translation preserve handedness they correspond to motions of rigid (solid) objects.

Homogeneous coordinates Homogeneous coordinates introduces a third dummy coordinate w, represented as (x, y, w). You imagine a third dimension z or (x/z, y/z), where a ray from the origin to point (x, y, z) in three-dimensions pierces the plane at z = 1. This paradoxically suggests that there is some ideal point (x, y, 0). More importantly it allows for many different homogeneous coordinate representations of the same point, e.g. (2, 3, 6) is the same as (4, 6, 12), etc.

In homogeneous coordinates this third dimension is often named w or (wx, wy, w) where w 0. You homogenise by dividing by w to get (x, y, 1) (Foley Figure 5.07). W P X Y W = 1 plane This imaginary dimension can also be considered as (x/z, y/z) where a ray from the origin to point (x, y, z) in three-dimensions pierces the plane at z = 1.

In Figure 5.7 (Foley, page 171): Each point subsequently has many different homogeneous coordinate representations, e.g. (2, 3, 6) is the same as (4, 6, 12), etc. Homogenise by dividing by w to get (x, y, 1).

Translation in homogeneous coordinates: 1 0 x t wx w(x + x t ) 0 1 y t wy = w(y + y t ) 0 0 1 w w The additional (redundant) dimension w allows translation becomes linear and allows the translation to be written as a matrix product rather than a sum. Translation in homogeneous coordinates (with w = 1): x 1 0 x t x x + x t y = 0 1 y t y = y + y t 1 0 0 1 1 1

Rotation in homogeneous coordinates cos θ sin θ 0 R = sin θ cos θ 0 0 0 1 inverse rotation, R -1 = R T, cos θ sin θ 0 R = sin θ cos θ 0 0 0 1 How does one rotate about an arbitrary point?

In general, with these transforms (except translation of course), we get the 3-by-3 homogeneous version by putting the 2-by-2 matrix down in the upper-left 2-by-2 block of what is otherwise a 3-by-3 identity matrix. Inverse rotation is rotation by negative angle θ. Since cos( θ) = cos(θ) and sin( θ) = sin(θ), the structure of the rotation matrix means that its inverse is its transpose. (Actually, this is a property common to all orthogonal matrices, of which rotation is a special case.)

Non-rigid body transformations Scaling is also known as dilatation, magnification or shrinking, where x = x s x and y = y s y. %epsfigfile=scale.eps, height=45mm, width=45mm Scaling is an affine transformation (affine transformations preserve collinearity of lines, or curvature).

Affine transformations An affine transformation preserves collinearity between points (ie. three points which lie on a line continue to be collinear after the transformation), and ratios of distances between any two points. Therefore translation, rotation, scaling and shear are all affine transformations.

Scaling as a matrix operation: [ ] [ ] [ ] x xs 0 x y = 0 y s y Scaling in homogeneous coordinates: x x s 0 0 x x s x y = 0 y s 0 y = y s y 1 0 0 1 1 1 This shows how scaling can be achieved as a matrix operation. If x s = y s, get isotropic scaling. Scaling is inverted by using reciprocals of scale factors, 1/x s and 1/y s. Using scale factors of 1 gives an identity transformation.

Shear Horizontal shear: x = x + x h y y = y Everything keeps its vertical position, but is dragged sideways in proportion to its vertical position. A square is dragged out into a parallelogram with the same height.

Horizontal shear in homogeneous coordinates: x 1 x h 0 x (x + x h y) y = 0 1 0 y = (y) 1 0 0 1 1 1

Vertical shear: x = x y = y + y h x Everything keeps its horizontal position, but is dragged up or down in proportion to its horizontal position. A square is dragged out into a parallelogram with the same width.

Vertical shear in homogeneous coordinates: x 1 0 0 x (x) y = y h 1 0 y = (y h x + y) 1 0 0 1 1 1 Shears are elementary transforms many useful transforms can be made by appropriate combinations of shears this can have theoretical and computational benefits for example, totations can be decomposed into shears and used for producing fast method of rotating, without need for using trogonometric function calls

Combining transformation matrices Any transformation (or combination of transformations) can be expressed in homogeneous coordinates by means of the matrix equation: x m 00 m 01 m 02 x y = m 10 m 11 m 12 y 1 0 0 1 1

Affine transformations in 2D Any affine transformation (or combination of transformations) can be expressed in homogeneous coordinates by means of the matrix equation: x y 1 = m 00 m 01 m 02 m 10 m 11 m 12 0 0 1 x y 1

1 0 x t 0 1 y t (translation) 0 0 1 x s 0 0 0 y s 0 (scaling) 0 0 1 cos θ sin θ 0 sin θ cos θ 0 (clockwise rotation by theta) 0 0 1] cos θ sin θ 0 sin θ cos θ 0 (anti-clockwise rotation by theta) 0 0 1

Example: rotation around an arbitrary 2D point y y y y P 1 P 1 Original house x After translation of P 1 to origin x After rotation q x After translation to original P 1 x (Foley Figure 5.10)

Rotating a point (x, y) about an arbitrary fixed point (rather than the origin), to obtain a new point (x r, y r ). x r y r 1 1 0 c x cos θ sin θ 0 1 0 c x x = 0 1 c y sin θ cos θ 0 0 1 c y y 0 0 1 0 0 1 0 0 1 1 = cos θ sin θ c x (1 cos θ) + c y sin θ sin θ cos θ c y (1 cos θ) c x sin θ 0 0 1 Homogeneous coordinates simplify process of combining transformation, similarly for scaling an object about an arbitrary point. x y 1

Example: rotation, scaling and translation P 2 P 1 Original house Translate P 1 to origin T (x 2, y 2 ) R(θ) S(s x, s y ) T ( x 1, y 1 ) (Foley Figure 5.11) Scale Rotate Translate to final position P 2

Commutivity of transformation matrices If M 1 and M 2 each represent a fundamental translation, scaling or rotation, when is M 1 M 2 = M 2 M 1? In general, for two matrices matrix multiplication is not commutative, that is M 1 M 2 M 2 M 1 However, commutivity holds in the following special cases when M 1 M 2 Translate Translate Scale Scale Rotate Rotate Scale (with s x = s y ) Rotate When s x = s y, termed isotropic scaling.

Example: drawing circles and ellipses If a point is rotated incrementally by some (small) angle δ, then the trajectory it traces out is a circle. If we draw (short) line segments connecting successive points, this leads to an important fast method for drawing circles or parts of circles circular [ arcs ] (if δ is small enough). x0 More specifically, if x 0 = is our starting point on the circle, y 0 then we compute the sequence x k+1 = R δ x k where R δ is a rotation (note this draws a circle centred on the origin). How would the circle-drawing methods be adapted to draw ellipses with arbitrary centres?

That is, we want a matrix E such that the sequence of points generated by x k+1 = Ex k lies along the ellipse. However, R δ only steps us along successive points that lie on a circle, incremented by angle δ. What about an ellipse? Our method for drawing circles should be able to be adapted for drawing ellipses quickly, using a combination of matrix transformations. Note that an ellipse at arbitrary orientation can be created by stretching and rotating a unit circle. Initially, let s consider only ellipses centred at the origin.

We can obtain an ellipse by stretching and rotating the points of a unit circle. This can be achieved by 1. multiplying by a scaling matrix to achieve the ellipsoid shape [ ] sx 0 S = 0 s y (note different scaling in x and y directions for ellipse), followed by 2. multiplying by a rotation R θ to orient the point along the path of the ellipse. thus SR θ

If we have a point on an ellipse, we can move it back to the corresponding point on the unit circle, by multiplying it by the inverse of these transforms (SR θ ) -1. Once we get it on the unit circle, we can step it to the next point by multiplying by R δ. Then we can get that point back on the ellipse by multiplying by (SR θ ). Thus E = (SR θ ) -1 R δ (SR θ ) = R θ -1 S -1 R δ SR θ = R ( θ) S -1 R δ SR θ

Note that, in general, scaling and rotation don t commute, so there s no obvious way to simplify this formula further. The main computational property of this method is that E can be computed just once, so that each point generated along the ellipse requires just a matrix multiply. Note that although can calculate sin(δ) and cos(δ) will need to calculate coefficients containing sin(θ) and cos(θ) at each step, since the transformation of a point at each step through different angles of the ellipse changes. A nice property is that the steps are smaller where the curvature of the ellipse is higher (at the ends), and bigger where the curvature of the ellipse is lower (along the sides). The method adapts to distribute the number of points used along the ellipse to represent it most accurately when straight line segments are drawn between points.

Summary Geometric transformations can be conveniently encoded as operations in matrix algebra. Rigid body transformations (rotation, translation and reflection) preserve distances and correspond to rigid motion that is typically modelled in computer graphics. However, translations and rotations cannot be conveniently combined using only multiplication. Representing geometric transformations as matrices in homogeneous coordinates allows the combination of multiple transformations using matrix multiplication. Translation, rotation and reflection are affine transformation (they preserve distances between points). Scaling and shear are not affine and do not preserve distances, however rotations can be decomposed into shears with computational benefits.