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.