43
Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates Adrian Pearce Department of Computer Science and Software Engineering University of Melbourne The University of Melbourne Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

COMP30019 Graphics and InteractionTransformation geometry and homogeneous

coordinates

Adrian Pearce

Department of Computer Science and Software EngineeringUniversity of Melbourne

The University of Melbourne

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 2: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Lecture outline

Introduction

Vectors and matrices

Translation

Rotation

Homogeneous coordinates

Affine transformations

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 3: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Transformation geometry

How are geometric transformations represented convenientlyand efficiently?

Aim: understand how two-dimensional (2D) transformations arecombined conveniently and the benefits of homogeneouscoordinates.

Reading:I Foley Sections 5.3 Homogeneous coordinates and matrix

representation of 2D transformations, 5.4 Composition of2D transformations and 5.6 Efficiency.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 4: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Review of two-dimensional (2D) geometry

Points are represented either in absolute position, relative toorigin in Cartesian coordinates: (x , y) ∈ R2 or polarcoordinates: (ρ, θ).

Vectors represent relative displacement, v =

[vxvy

]and are

subject to vector addition, subtraction, scalar product (dotproduct) or norm (magnitude) operations.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 5: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Curves can be modelled in either explicit functional form:y = F (x) or implicit equational form: G(x , y) = 0 or parametricform:

x = x(t)y = y(t)

e.g. some straight lines are:I y = mx + b (explicit functional form)I ax + by + c = 0 (implicit equational form)I x cos θ + y sin θ = ρ (implicit equational form)I x = x0 + x1p(t), y = y0 + y1p(t) (parametric form)

Special forms include a line through two points or linesegments such as endpoints or parameter bounds.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 6: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Geometric transformations

General geometric transformations concern object points ratherthan transformation of the entire coordinate frame,

x ′ = g(x , y),

y ′ = h(x , y).

More specific geometric transformations involveI translations, where x ′ = x + xt , and y ′ = y + yt andI linear transformations v′ = Mv (where v′ is a vector and M

is a matrix) such as scaling, shear, rotation, reflection.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 7: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Vector and matrix conventions

There are two conventions for vectors and matrices, the text(Rowe) uses this form, where vectors are written as columns:

v =

[xy

]Matrices multiply on the left:

Mv =

[a bc d

] [xy

]=

[ax + bycx + dy

]

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 8: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

However, watch out for other forms where vectors are written asrows:

v =[x y

]=

[xy

]T

Matrices multiply on the right:

vM =[x y

] [a bc d

]=

[ax + cybx + dy

]Really, you should understand the concepts, and be able towork with either notation.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 9: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

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

x ′

y ′

]=

[xy

]+

[xtyt

]

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 10: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Rotation

Rotation of an object about the origin

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 11: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Rotation as a matrix operation (by multiplication):[cos θ − sin θsin θ cos θ

] [xy

]=

[x cos θ − y sin θx sin θ + y cos θ

]Convenient, as can combine a number of geometric rotationsby multiplication, [

x ′

y ′

]=

[cos θ − sin θsin θ cos θ

] [xy

]Unfortunately translation is different to rotation, therefore can’ttreat as multiplication (also true for scaling).This means translations and rotations cannot be combinedeasily.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 12: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

How are rotation matrices derived?Increasing x

Increasin

gy

x y

x y

,

,

,

( )

¢ ¢( )

( )0 0

q

f

Hint: Consider the point above with polar coordinates (ρ, θ)(Rowe Fig 2.1). If rotated by angle φ around the origin, its polarcoordinates are (ρ, θ + φ), converting to Cartesian coordinatesgives, [

ρ cos(θ + φ)ρ sin(θ + φ)

]Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 13: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

We can expand and re-arrange this in terms of the cosine andsine angle-addition formulas, and the Cartesian coordinates ofthe 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 θAdrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 14: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Rigid body transformations

Rotation, translation, and reflection preserve distances (rigidmotions).

That is, if two points are a certain distance apart, they will stillbe the same distance apart after undergoing one of thesetransformations (or indeed any combination of them).

Mathematically, they are the only transformations with thisproperty of preserving distance.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 15: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Reflection

Reflection in a line—gives mirror imageMove point to position at equal distance on opposite side of theline.Reflection in the x-axis:

x ′ = xy ′ = −y

Reflection in the y -axis:

x ′ = −xy ′ = y

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 16: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 17: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Reflection in the line y = x :

x ′ = yy ′ = x

All these can be expressed as matrix operations (details left toyou).

Reflections in an arbitrary line can be achieved by transformingline (by rotation and translation) to one of the coordinate axes,reflecting in that axis, and transforming back.

I Reflection reverses handedness—an object goes to itsmirror image.

I Rotation and translation preserve handedness—theycorrespond to motions of rigid (solid) objects.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 18: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Homogeneous coordinates

Homogeneous coordinates introduces a third dummycoordinate w , represented as (x , y ,w).

You imagine a third dimension z or (x/z, y/z), where a ray fromthe origin to point (x , y , z) in three-dimensions pierces theplane at z = 1.

I This paradoxically suggests that there is some ideal point(x , y ,0).

I More importantly it allows for many different homogeneouscoordinate representations of the same point, e.g. (2,3,6)is the same as (4,6,12), etc.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 19: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

In homogeneous coordinates this third dimension is oftennamed w or (wx ,wy ,w) where w 6= 0. You homogenise bydividing by w to get (x , y ,1) (Foley Figure 5.07).

W

X

Y

P

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-dimensionspierces the plane at z = 1.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 20: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

In Figure 5.7 (Foley, page 171):I Each point subsequently has many different homogeneous

coordinate representations, e.g. (2,3,6) is the same as(4,6,12), etc.

I Homogenise by dividing by w to get (x , y ,1).

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 21: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Translation in homogeneous coordinates:1 0 xt0 1 yt0 0 1

wxwyw

=

w(x + xt)w(y + yt)

w

The additional (redundant) dimension w allows translationbecomes linear and allows the translation to be written as amatrix product rather than a sum.

Translation in homogeneous coordinates (with w = 1):x ′

y ′

1

=

1 0 xt0 1 yt0 0 1

xy1

=

x + xty + yt

1

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 22: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Rotation in homogeneous coordinates

R =

cos θ − sin θ 0sin θ cos θ 0

0 0 1

inverse rotation, R-1 = RT,

R =

cos θ sin θ 0− sin θ cos θ 0

0 0 1

How does one rotate about an arbitrary point?

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 23: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

In general, with these transforms (except translation of course),we get the 3-by-3 homogeneous version by putting the 2-by-2matrix down in the upper-left 2-by-2 block of what is otherwise a3-by-3 identity matrix.

I Inverse rotation is rotation by negative angle −θ. Sincecos(−θ) = cos(θ) and sin(−θ) = − sin(θ), the structure ofthe rotation matrix means that its inverse is its transpose.(Actually, this is a property common to all orthogonalmatrices, of which rotation is a special case.)

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 24: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Non-rigid body transformationsScaling is also known as dilatation, magnification or shrinking,where x ′ = xsx and y ′ = ysy .

%epsfigfile=scale.eps, height=45mm, width=45mm

Scaling is an affine transformation (affine transformationspreserve collinearity of lines, or curvature).

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 25: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Affine transformations

An affine transformation preservesI collinearity between points (ie. three points which lie on a

line continue to be collinear after the transformation), andI ratios of distances between any two points.

Therefore translation, rotation, scaling and shear are all affinetransformations.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 26: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Scaling as a matrix operation:[x ′

y ′

]=

[xs 00 ys

] [xy

]Scaling in homogeneous coordinates:x ′

y ′

1

=

xs 0 00 ys 00 0 1

xy1

=

xsxysy1

This shows how scaling can be achieved as a matrix operation.

I If xs = ys, get isotropic scaling.I Scaling is inverted by using reciprocals of scale factors,

1/xs and 1/ys.I Using scale factors of 1 gives an identity transformation.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 27: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

ShearHorizontal shear:

x ′ = x + xhyy ′ = y

Everything keeps its vertical position, but is dragged sidewaysin proportion to its vertical position. A square is dragged outinto a parallelogram with the same height.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 28: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Horizontal shear in homogeneous coordinates:x ′

y ′

1

=

1 xh 00 1 00 0 1

xy1

=

(x + xh ∗ y)(y)1

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 29: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Vertical shear:

x ′ = xy ′ = y + yhx

Everything keeps its horizontal position, but is dragged up ordown in proportion to its horizontal position.A square is dragged out into a parallelogram with the samewidth.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 30: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Vertical shear in homogeneous coordinates:x ′

y ′

1

=

1 0 0yh 1 00 0 1

xy1

=

(x)(yh ∗ x + y)

1

Shears are elementary transforms

I many useful transforms can be made by appropriatecombinations of shears

I this can have theoretical and computational benefitsI for example, totations can be decomposed into shears and

used for producing fast method of rotating, without need forusing trogonometric function calls

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 31: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Combining transformation matrices

Any transformation (or combination of transformations) can beexpressed in homogeneous coordinates by means of the matrixequation: x ′

y ′

1

=

m00 m01 m02m10 m11 m12

0 0 1

xy1

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 32: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Affine transformations in 2D

Any affine transformation (or combination of transformations)can be expressed in homogeneous coordinates by means ofthe matrix equation: x ′

y ′

1

=

m00 m01 m02m10 m11 m12

0 0 1

xy1

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 33: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

I

1 0 xt0 1 yt0 0 1

(translation)

I

xs 0 00 ys 00 0 1

(scaling)

I

cos θ − sin θ 0sin θ cos θ 0

0 0 1]

(clockwise rotation by theta)

I

cos θ sin θ 0− sin θ cos θ 0

0 0 1

(anti-clockwise rotation by theta)

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 34: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Example: rotation around an arbitrary 2D point

y

xAfter translationof P1 to origin

P1

y

xOriginal house

q

y

xAfter rotation

y

xAfter translationto original P1

P1

(Foley Figure 5.10)

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 35: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Rotating a point (x , y) about an arbitrary fixed point (rather thanthe origin), to obtain a new point (xr , yr ). xr

yr1

=

1 0 cx0 1 cy0 0 1

cos θ − sin θ 0sin θ cos θ 0

0 0 1

1 0 −cx0 1 −cy0 0 1

xy1

=

cos θ − sin θ cx(1− cos θ) + cy sin θsin θ cos θ cy (1− cos θ)− cx sin θ

0 0 1

xy1

Homogeneous coordinates simplify process of combiningtransformation, similarly for scaling an object about an arbitrarypoint.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 36: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Example: rotation, scaling and translation

P1

Originalhouse

Translate P1to origin

Scale Rotate Translate tofinal position P2

P2

T (x2, y2) · R(θ) · S(sx , sy ) · T (−x1,−y1)(Foley Figure 5.11)

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 37: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Commutivity of transformation matricesIf M1 and M2 each represent a fundamental translation, scalingor rotation, when is M1 ·M2 = M2 ·M1?In general, for two matrices matrix multiplication is notcommutative, that is

M1 ·M2 6= M2 ·M1

However, commutivity holds in the following special cases when

M1 M2Translate TranslateScale ScaleRotate RotateScale (with sx = sy ) Rotate

When sx = sy , termed isotropic scaling.Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 38: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

Example: drawing circles and ellipsesIf a point is rotated incrementally by some (small) angle δ, thenthe 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 orparts of circles—circular arcs (if δ is small enough).

More specifically, if x0 =

[x0y0

]is our starting point on the circle,

then we compute the sequence

xk+1 = Rδxk

where Rδ is a rotation (note this draws a circle centred on theorigin).How would the circle-drawing methods be adapted to drawellipses with arbitrary centres?

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 39: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

That is, we want a matrix E such that the sequence of pointsgenerated by

xk+1 = Exk

lies along the ellipse.However, Rδ only steps us along successive points that lie on acircle, incremented by angle δ.What about an ellipse?Our method for drawing circles should be able to be adapted fordrawing ellipses quickly, using a combination of matrixtransformations.Note that an ellipse at arbitrary orientation can be created bystretching and rotating a unit circle. Initially, let’s consider onlyellipses centred at the origin.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 40: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

We can obtain an ellipse by stretching and rotating the points ofa unit circle. This can be achieved by

1. multiplying by a scaling matrix to achieve the ellipsoidshape

S =

[sx 00 sy

](note different scaling in x and y directions for ellipse),followed by

2. multiplying by a rotation Rθ to orient the point along thepath of the ellipse.

thus

SRθ

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 41: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

If we have a point on an ellipse, we can move it back to thecorresponding point on the unit circle, by multiplying it by theinverse of these transforms (SRθ)

-1.

Once we get it on the unit circle, we can step it to the next pointby multiplying by Rδ. Then we can get that point back on theellipse by multiplying by (SRθ).

Thus

E = (SRθ)-1Rδ (SRθ)

= Rθ-1S-1RδSRθ

= R(−θ)S-1RδSRθ

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 42: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

I Note that, in general, scaling and rotation don’t commute,so there’s no obvious way to simplify this formula further.

I The main computational property of this method is that Ecan be computed just once, so that each point generatedalong the ellipse requires just a matrix multiply.

I Note that although can calculate sin(δ) and cos(δ) willneed to calculate coefficients containing sin(θ) and cos(θ)at each step, since the transformation of a point at eachstep through different angles of the ellipse changes.

I A nice property is that the steps are smaller where thecurvature of the ellipse is higher (at the ends), and biggerwhere the curvature of the ellipse is lower (along thesides). The method adapts to distribute the number ofpoints used along the ellipse to represent it mostaccurately when straight line segments are drawn betweenpoints.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates

Page 43: COMP30019 Graphics and Interaction Transformation geometry and homogeneous … · 2012-07-17 · Transformation geometry and homogeneous coordinates Adrian Pearce ... Rigid body transformations

Introduction Vectors and matrices Translation Rotation Homogeneous coordinates Affine transformations

SummaryI Geometric transformations can be conveniently encoded

as operations in matrix algebra.I Rigid body transformations (rotation, translation and

reflection) preserve distances and correspond to rigidmotion that is typically modelled in computer graphics.

I However, translations and rotations cannot be convenientlycombined using only multiplication.

I Representing geometric transformations as matrices inhomogeneous coordinates allows the combination ofmultiple transformations using matrix multiplication.

I Translation, rotation and reflection are affine transformation(they preserve distances between points).

I Scaling and shear are not affine and do not preservedistances, however rotations can be decomposed intoshears with computational benefits.

Adrian Pearce University of Melbourne

COMP30019 Graphics and InteractionTransformation geometry and homogeneous coordinates