COMP30019 Graphics and Interaction Three-dimensional transformation - - PowerPoint PPT Presentation

comp30019 graphics and interaction three dimensional
SMART_READER_LITE
LIVE PREVIEW

COMP30019 Graphics and Interaction Three-dimensional transformation - - PowerPoint PPT Presentation

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation COMP30019 Graphics and Interaction Three-dimensional transformation geometry and perspective Adrian Pearce Department of Computer Science and


slide-1
SLIDE 1

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

COMP30019 Graphics and Interaction Three-dimensional transformation geometry and perspective

Adrian Pearce

Department of Computer Science and Software Engineering University of Melbourne

The University of Melbourne

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-2
SLIDE 2

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Lecture outline

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-3
SLIDE 3

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Three-dimensional transformations and perspective

How do three-dimensional transformations differ from two-dimensional transformations? Aim: understand how to transform arbitrary perspectives in three-dimensions (3D). Reading:

◮ Foley Sections 5.7 matrix representation of 3D

transformations and 5.8 composition of 3D transformations.

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-4
SLIDE 4

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Three-dimensional coordinate systems

3D (Cartesian) coordinates (X, Y, Z) can be considered in terms of left-handed and right-handed coordinate systems. The “right-hand rule”: thumb X axis index finger Y axis big finger Z axis Most conventional 3D analytic geometry is in terms of right-handed coordinates—what we’ll use. Though left-handed systems do crop up, sometimes by accident or design.

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-5
SLIDE 5

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Rotation about axis in the right-handed coordinate system

z y (out of page) x

Axis of rotation Direction of positive rotation x y to z y z to x z x to y

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-6
SLIDE 6

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Three-dimensional rotation

Need to specify axis of rotation, and by how much such as a 3D unit vector, plus rotation angle. Convention: rotation angle is clockwise looking along axis of rotation Note, this is consistent with ordinary 2D anti-clockwise convention: Really a rotation around a positive Z axis coming up out of the page in a right-handed coordinate frame.

Y X Z

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-7
SLIDE 7

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Example: rotation of a simple object

z x y P3 P2 (a) Initial position z x y P1 P3 P2 (b) Final position P1 Example from Section 5.8 of Foley.

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-8
SLIDE 8

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

y z x P′3 P′1 θ D1 P′2(x′2, y′2, z′2) (x′2, 0, z′2)

x y z D2 φ P 1 ′′ z 2 ′′ P 2 ′′ y 2 ′′

Rotation about the y axis (left) by −(90 − θ) followed by rotation around the x axis (right) by φ (shown for P1P3 only).

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-9
SLIDE 9

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

x y z y 3 P 3 P 1 P 2 D3 x 3 α ′′′ ′′′ ′′′ ′′′ ′′′

Final rotation about the z axis is by α. The composite matrix R for the overall transformation is calculated by multiplying the individual rotation matrices and translation matrix Rz(α) · Rx(φ) · Ry(θ − 90) · T(−x1, −y1, −z1) = R · T

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-10
SLIDE 10

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Rotations about an arbitrary axis

Two rotations about coordinate axes to line up axis of rotation with one of the coordinate axes. One rotation around this last axis, two rotations to undo the first two, and put the axis of rotation back where it was. If axis doesn’t pass through the origin, you’ll need to wrap an appropriate translation and its inverse around all this.

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-11
SLIDE 11

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Rotation to arbitrary orientations

In constructive geometry we often want to rotate an object from a known starting point, or alignment, to an arbitrary orientation. In Foley’s example, an aeroplane aligned along the Z axis is rotated to an arbitrary orientation.

yp xp zp

y x z yp xp zp DOF P Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-12
SLIDE 12

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Orthogonal matrix

An n × n matrix V is orthogonal if VV T = I Where V T is the transpose of V and I is the identity matrix. Special orthogonal: A matrix V is special orthogonal if it is orthogonal and det V = 1. For example:   cos θ − sin θ sin θ cos θ 1]  

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-13
SLIDE 13

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Orthonormal matrix

Orthonormal basis: A subset v1, . . . , vk of vector space V, where the inner product

  • f any two vectors vi and vj is zero.

That is, the vectors are mutually perpendicular and are unit vectors, inner product of vi with itself is one.

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-14
SLIDE 14

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Since the rotation matrix is orthonormal, we can construct a matrix whose rows are unit vectors in direction we want the

  • riginal X, Y, and Z axes to end up pointing in (based on the

direction of flight in the aeroplane example).

z x y P1 P3 P2 Rz Rx Ry

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-15
SLIDE 15

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Rz = [r1z, r2z, r3z]T = P1P2 |P1P2| Rx = [r1x, r2x, r3x]T = P1P3 × P1P2 |P1P3 × P1P2| Ry = [r1y, r2y, r3y]T = Rz × Rx     r1x r2x r3x r1y r2y r3y r1z r2z r3z 1     · T(−x1, −y1, −z1) = R · T

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-16
SLIDE 16

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

R =     |yp × DOF| |DOF × (yp × DOF)| |DOF| 1     To find the rotation matrix, we just determine in what direction each of the xp, yp, and zp axes is heading and normalise as direction vectors and use these as column vectors in a rotation matrix.

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-17
SLIDE 17

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Homogeneous versions

In 3D the point in homogeneous coordinates (X, Y, Z, W) corresponds to the Cartesian point (X/W, Y/W, Z/W) for W = 0 Completely analogous to the 2D case, where W = 1. Translation:     x′ y′ z′ 1     =     1 xt 1 yt 1 zt 1         x y z 1    

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-18
SLIDE 18

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Scaling:     x′ y′ z′ 1     =     xs ys zs 1         x y z 1     Rotation counterclockwise using right-handed coordinate system about Z axis:     x′ y′ z′ 1     =     cosθ −sinθ sinθ cosθ 1 1         x y z 1    

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-19
SLIDE 19

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Rotation around the y axis:     x′ y′ z′ 1     =     cosθ sinθ 1 −sinθ cosθ 1         x y z 1     Rotation around the x axis:     x′ y′ z′ 1     =     1 cosθ −sinθ −sinθ cosθ 1         x y z 1     Note cyclic wrap-around of factors for each axis.

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-20
SLIDE 20

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Arbitrary camera orientation

Suppose objects are in some world coordinate system, consider the pose (position and orientation) of a camera in this system. An objects’ position must be transformed into camera-centred coordinates before a projection can be done, requiring

◮ a translation (to put cameras optical centre at origin) ◮ a three-dimensional rotation to line up Z-axis with optical

axis (requires two coordinate axis rotations)

◮ another rotation around Z-axis to line up X and Y axes

(which way is up)

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-21
SLIDE 21

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Projections as transformations

Recall oblique parallel projection can be formulated as pints projected parallel to projection vector d = (dx, dy, dz) (Rowe Figure 4.3). (xv, yv) = px − pzdx dz , py − pzdy dz )

  • rigin

P x y

v v

,

( )

x y d p Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-22
SLIDE 22

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Consider the vector equation of the line r = p + td where r = (x, y, z) is the vector pointing to a point on the line and t is a scalar parameter. Using the z component, we can obtain the value of t where the line intersects the xy plane, given t = pz dz

◮ Substitution gives projection (as shown in Rowe Figure 4.3)

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-23
SLIDE 23

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Matrix for oblique parallel projection

For oblique parallel projection of point px, py, pz along projection vector d = (dx, dy, dz) the transformation can be written     xv yv zv 1     =      1

−dx dz

1

−dy dz

1 1          px py pz 1     You can see that this is actually a shearing operation with functions in the x and y direction determined by the components of the projection vector d

◮ zv is simply ignored, since only interested in obtaining the

projection onto the view plane.

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-24
SLIDE 24

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Matrix form of perspective projection

Perspective projection can be expressed as a matrix operation in homogeneous coordinates, where the 3D point (X, Y, Z) is represented by the homogeneous coordinates (wX, wY, wZ, w), where w = 0 and is typically 1. Hint: think of perspective projection as a mapping from 3D to 2D, then it can be expressed as a multiplication by a 4 × 3 matrix (that is, 3 rows, 4 columns).

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-25
SLIDE 25

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

We want the homogeneous point (X, Y, Z, 1) in 3D to “go to” the homogeneous point (fX/Z, fY/Z, 1) in 2D—this comes straight from the equations of perspective projection. This latter point is the same as (X, Y, Z/f), since multiplication throughout by the constant Z/f gives the same point in homogeneous coordinates, and   1 1 1/f       X Y Z 1     =   X Y Z/f   →   fX/Z fY/Z 1  

◮ Rightarrow is just homogenisation (dividing through to

make homogeneous coordinate equal to one (1)!

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-26
SLIDE 26

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Perspective projection can also be thought of as a mapping from one 3D vector to another 3D vector, given by a 4 × 4 transformation matrix using a monotonic function of depth, called pseudo-depth.     1 1 1 1/f         X Y Z 1     =     X Y 1 Z/f     →     fX/Z fY/Z f/Z 1     Pseudo-depth can make perspective projection into an invertible affine transformation (as it stores unused Z dimension in two-dimensions until you need it to go back to three-dimensions again).

◮ Pseudo-depth can be used conveniently for ordering points

in hidden-surface elimination, and similar processes.

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective

slide-27
SLIDE 27

Introduction Rotation about artibrary axis Homogeneous versions Arbitrary camera orientation

Summary

◮ In three-dimensional transformations the convention is to

rotate clockwise looking along axis of rotation, using the right-hand rule for coordinates.

◮ Rotations about an arbitrary axis involves two rotations to

line up axis of rotation with a coordinate axis, a rotation around this last axis then two rotations to undo the first two (and some translations if rotation axis does not pass through origin).

◮ Rotations to an arbitrary orientation (from a known starting

axis) can also be done using unit vectors and cross products to fill in transformation matrix directly.

◮ Projections from three-dimensions to two-dimensions can

be conveniently represented as matrix transformations, allowing for projection variants according to matrix factors.

Adrian Pearce University of Melbourne COMP30019 Graphics and InteractionThree-dimensional transformation geometry and perspective