程序代写代做代考 PowerPoint Presentation

PowerPoint Presentation

4: Homogeneous Transformations
Dr. Hamish Carr

COMP 5812M: Foundations of Modelling & Rendering
Changing Bases
Assume P is in B’

Where is P in B?
Depends on
the basis of B’

COMP 5812M: Foundations of Modelling & Rendering
Changing Bases

COMP 5812M: Foundations of Modelling & Rendering
Rotation Matrices

P

O
Basis B
x
y
z

P’

Basis B’
x’
y’
z’

COMP 5812M: Foundations of Modelling & Rendering
Constructing Rotation

P

O
Basis B
x
y
z

P’

Basis B’
x’
y’
z’

COMP 5812M: Foundations of Modelling & Rendering
More Rotations
Stand at the end of the axis of rotation
face in, and rotation is CCW
Find the matrix for a rotation around y
Find the matrix for a rotation around z
Any orthonormal basis is a rotation
How can we find the axis?

COMP 5812M: Foundations of Modelling & Rendering
Inverse Rotations
Inverse rotation given by transpose
only works for (orthonormal) rotations

COMP 5812M: Foundations of Modelling & Rendering

Scaling
Shrink or grow one coordinate, but not others
Negative scale is reflection

COMP 5812M: Foundations of Modelling & Rendering

Shearing
Slide the top sideways
by a vector multiplied by z

COMP 5812M: Foundations of Modelling & Rendering
Transforming Normals
If a surface rotates, the normal must also do so
We will apply the rotation to the normal too
Scaling distorts normals
as does shearing
So mostly used in modelling software
where they can be fixed without time issues

COMP 5812M: Foundations of Modelling & Rendering
Distorted Normals
Not a problem for rotation / translation
BIG problem for scaling / shearing

COMP 5812M: Foundations of Modelling & Rendering
Translation
Translation moves an object
in the direction given by a vector
add the vector to each vertex

Can’t do it with Cartesian matrix multiplication

COMP 5812M: Foundations of Modelling & Rendering
Applying Transformations
Rotate a cylinder, then translate it:

Translate a cylinder, then rotate it:

Specify transformations in reverse order

COMP 5812M: Foundations of Modelling & Rendering
Three Problems
Represent translation in matrix form
Apply sequences of transformations efficiently
Represent perspective in matrix form
Cartesian coordinates won’t work
But homogeneous coordinates will

COMP 5812M: Foundations of Modelling & Rendering
2D Homogeneous Coords
Homogeneous coords exist in all dimensions
In 2D, (x, y) becomes (x, y, 1)
w is a scale factor: usually 1
(x, y, w) refers to the point
(1, 2, 1) is the same as (3, 6, 3)

COMP 5812M: Foundations of Modelling & Rendering
Meaning of H.C.
Each point becomes a line in space
h.c. can represent projection as well

COMP 5812M: Foundations of Modelling & Rendering
3D Homogeneous Coords.
In 3D, homogeneous coordinates are (x, y, z, w)
x, y, z are the same as usual (almost)
w is the same as in 2D
(x, y, z, w) refers to the point
(1, 2, 3, 1) is the same as (3, 6, 9, 3)

COMP 5812M: Foundations of Modelling & Rendering
Homogeneous Vectors
Vectors can be written as: (x, y, z, 0)
Why?
Consider
As , the point travels outwards
So the vector (x, y, z) is (x, y, z, 0)
Alternately, (x, y, z, 0) is infinitely far out

COMP 5812M: Foundations of Modelling & Rendering
Rotations
Transformation matrices add 1 row/col
Result of the multiplication is the same

COMP 5812M: Foundations of Modelling & Rendering
Scaling
Again, pretty much the same

COMP 5812M: Foundations of Modelling & Rendering
Shearing

COMP 5812M: Foundations of Modelling & Rendering
Translation
To translate (x, y, z, w) by (a, b, c, 1):

COMP 5812M: Foundations of Modelling & Rendering
Translation
To translate (x, y, z, w) by (a, b, c, 1):

COMP 5812M: Foundations of Modelling & Rendering

Translation
To translate (x, y, z, w) by (a, b, c, 1):

COMP 5812M: Foundations of Modelling & Rendering

Translation
To translate (x, y, z, w) by (a, b, c, 1):

COMP 5812M: Foundations of Modelling & Rendering

p

p’

p

p’

Why this Works (2D)
In 2D, third column (w) is the same as z
Which means we have a shear matrix
p moves in direction v proportional to w
And lands on the line representing p’

COMP 5812M: Foundations of Modelling & Rendering

Arbitrary Rotation
Translate by (O – O’)
Rotate at O
Translate by (O’ – O)
Compose the matrices:

COMP 5812M: Foundations of Modelling & Rendering
Composition

COMP 5812M: Foundations of Modelling & Rendering
Cost of Transformation
Suppose we used Cartesian coordinates here
Add the vector, then rotate, then subtract
3 adds, 9 multiplies + 6 adds, 3 adds
12 adds, 9 multiplies total
If we perform three such rotations, we get:
36 adds, 27 multiplies
For 100 vertices, 3,600 adds, 2,700 multiplies

COMP 5812M: Foundations of Modelling & Rendering
Homogeneous Cost
Three arbitrary rotations for 100 vertices costs:
4,800 multiplies, 3,600 adds (4×4 matrices)
But we can pre-compute a single matrix:
128 multiplies & 96 adds
Then 1,600 multiplies, 1,200 adds
Total of 1,728 multiplies, 1,296 adds
Over 50% faster, and less book-keeping

COMP 5812M: Foundations of Modelling & Rendering
Homogeneous Matrix
Divides into
rotation (r)
also scale, shear
translation (t)
projection (p)
1

COMP 5812M: Foundations of Modelling & Rendering
Orthographic Projection
Projects a point p in the world
to a point q in the image plane
essentially an identity matrix
Keeps z (we’ll need it later)

COMP 5812M: Foundations of Modelling & Rendering
Oblique Projection
Shows a slanted view of an object
Slants lines perpendicular to plane
at a chosen angle

φ

COMP 5812M: Foundations of Modelling & Rendering
Perspective Projection
Lines are parallel in world
but converge in image to a vanishing point

COMP 5812M: Foundations of Modelling & Rendering
Receding Parallels
Parallel lines always converge
unless perpendicular to view direction

COMP 5812M: Foundations of Modelling & Rendering

Mathematical Perspective
Project p from the world to q in image plane

Use similar triangles to get coordinates

d is distance from eye to
image plane (usually 1)

COMP 5812M: Foundations of Modelling & Rendering
All 3 Coordinates

COMP 5812M: Foundations of Modelling & Rendering
Lines are Lines
A projected line is still a line
Look at the parametric form:

COMP 5812M: Foundations of Modelling & Rendering

Messy Algebra
Represent line in homogeneous coords
and apply the projection matrix

COMP 5812M: Foundations of Modelling & Rendering
Simple Case (vz = 0)
Line perpendicular to view direction
Assume d = 1, pz ≠ 0

A line in the plane z = 1

COMP 5812M: Foundations of Modelling & Rendering
Simplify the Vector
Now assume that vz ≠ 0, and simplify
Multiply v = (vx, vy, vz) by 1/ vz
We end up with (vx / vz, vy / vz, 1)
or just be lazy, and use v = (vx, vy, 1)

COMP 5812M: Foundations of Modelling & Rendering
Simplify the Point
If vz ≠ 0, there will be a point with pz = 0
Subtract pz v = pz(vx, vy, vz) to find it
(px’, py’, 0) = (px – vx pz, py – vz pz, pz – 1 pz)
I.e. we can assume that vz = 1, pz = 0
Make life simpler with d = 1

COMP 5812M: Foundations of Modelling & Rendering

COMP 5812M: Foundations of Modelling & Rendering
And not just any line
The point & vector have swapped
p = (px, py, 0) is now the vector
v = (vx, vy, 1) is now the point
Two parallel lines have the same v = (vx, vy, 1)
their projections both pass through (vx, vy, 1)
(vx, vy, 1) IS the vanishing point

COMP 5812M: Foundations of Modelling & Rendering
Foreshortening
Vertical spacing reduced further away
One of the cues to depth of image

COMP 5812M: Foundations of Modelling & Rendering
Foreshortening
We assumed that z = 0, c = 1
t is perpendicular distance to image plane
What happens to evenly spaced points?
P + 1V, P + 2V, P + 3V
These map to V + 1 P, V + 1/2 P, V + 1/3 P
No longer evenly spaced

COMP 5812M: Foundations of Modelling & Rendering
Homogeneous Coordinates
Give all affine transformations in a 4×4 matrix:
Rotation, Scaling, Shearing
Translation
Projection (Orthographic, Oblique, Perspective)
Also represent points & vectors differently
And they are much more efficient in practice
Despite having more coordinates!

COMP 5812M: Foundations of Modelling & Rendering

p0 = p
x

~e
x

0
+ p

y

~e
y

0
+ p

z

~e
z

0

= p
x

2

4
1

0

0

3

5
+ p

y

2

4
0

0

�1

3

5
+ p

z

2

4
0

1

0

3

5

=

2

4
1 0 0

0 0 1

0 �1 0

3

5

2

4
p
x

p
y

p
z

3

5

= Rp

3

Brief Article

The Author

October 17, 2016

S =

2

4
1 0 0
0 1 0
0 0 0.25

3

5

1

Brief Article

The Author

October 17, 2016

S =

2

4
1 0 0
0 1 0
0 0 0.25

3

5

H =

2

4
1 0 0
0 1 0.5
0 0 1

3

5

1

Brief Article

The Author

October 17, 2016

S =

2

4
1 0 0
0 1 0
0 0 0.25

3

5

H =

2

4
1 0 0
0 1 0.5
0 0 1

3

5

( x
w

,
y

w

)

1

Brief Article

The Author

October 17, 2016

S =

2

4
1 0 0
0 1 0
0 0 0.25

3

5

H =

2

4
1 0 0
0 1 0.5
0 0 1

3

5

( x
w

,
y

w

)

( x
w

,
y

w

, z
w

)

1

Brief Article

The Author

October 17, 2016

S =

2

4
1 0 0
0 1 0
0 0 0.25

3

5

H =

2

4
1 0 0
0 1 0.5
0 0 1

3

5

( x
w

,
y

w

)

( x
w

,
y

w

, z
w

)

lim
w!0(

x

w

,
y

w

, z
w

)

1

Brief Article

The Author

October 17, 2016

S =

2

4
1 0 0
0 1 0
0 0 0.25

3

5

H =

2

4
1 0 0
0 1 0.5
0 0 1

3

5

( x
w

,
y

w

)

( x
w

,
y

w

, z
w

)

lim
w!0(

x

w

,
y

w

, z
w

)
w ! 0

1

Brief Article

The Author

October 17, 2016

S =

2

4
1 0 0

0 1 0

0 0 0.25

3

5

H =

2

4
1 0 0

0 1 0.5
0 0 1

3

5

(

x

w

,
y

w

)

(

x

w

,
y

w

, z
w

)

lim

w!0(
x

w

,
y

w

, z
w

)

w ! 0
2

66
4

1 0 0 0

0 cos ✓ � sin ✓ 0
0 sin ✓ cos ✓ 0
0 0 0 1

3

77
5

2

66
4

x
y
z
w

3

77
5 =

2

66
4

x
y cos ✓ � z sin ✓
y sin ✓ + z cos ✓

w

3

77
5

1

Brief Article

The Author

October 17, 2016

S =

2

4
1 0 0

0 1 0

0 0 0.25

3

5

H =

2

4
1 0 0

0 1 0.5
0 0 1

3

5

(

x

w

,
y

w

)

(

x

w

,
y

w

, z
w

)

lim

w!0(
x

w

,
y

w

, z
w

)

w ! 0
2

66
4

1 0 0 0

0 cos ✓ � sin ✓ 0
0 sin ✓ cos ✓ 0
0 0 0 1

3

77
5

2

66
4

x
y
z
w

3

77
5 =

2

66
4

x
y cos ✓ � z sin ✓
y sin ✓ + z cos ✓

w

3

77
5

2

66
4

s
x

0 0 0

0 s
y

0 0

0 0 s
z

0

0 0 0 1

3

77
5

2

66
4

x
y
z
w

3

77
5 =

2

66
4

s
x

x
s
y

y
s
z

z
w

3

77
5

1

Brief Article

The Author

October 17, 2016

S =

2

4
1 0 0

0 1 0

0 0 0.25

3

5

H =

2

4
1 0 0

0 1 0.5
0 0 1

3

5

(

x

w

,
y

w

)

(

x

w

,
y

w

, z
w

)

lim

w!0(
x

w

,
y

w

, z
w

)

w ! 0
2

66
4

1 0 0 0

0 cos ✓ � sin ✓ 0
0 sin ✓ cos ✓ 0
0 0 0 1

3

77
5

2

66
4

x
y
z
w

3

77
5 =

2

66
4

x
y cos ✓ � z sin ✓
y sin ✓ + z cos ✓

w

3

77
5

2

66
4

s
x

0 0 0

0 s
y

0 0

0 0 s
z

0

0 0 0 1

3

77
5

2

66
4

x
y
z
w

3

77
5 =

2

66
4

s
x

x
s
y

y
s
z

z
w

3

77
5

2

66
4

s
x

s
xy

0 0

0 s
y

0 0

0 0 s
z

0

0 0 0 1

3

77
5

2

66
4

x
y
z
w

3

77
5 =

2

66
4

s
x

x+ s
xy

y
s
y

y
s
z

z
w

3

77
5

1

2

66
4

1 0 0 a
0 1 0 b
0 0 1 c
0 0 0 1

3

77
5

2

66
4

x
y
z
w

3

77
5 =

2

66
4

x+ aw
y + bw
z + cw

w

3

77
5


=

2

4
x+aw
w

y+bw
w

z+cw
w

3

5

=

2

4
x

w

+ a
y

w

+ b
z

w

+ c

3

5

=

2

4
x

w

y

w

z

w

3

5
+

2

4
a
b
c

3

5

2

2

66
4

1 0 0 a
0 1 0 b
0 0 1 c
0 0 0 1

3

77
5

2

66
4

x
y
z
w

3

77
5 =

2

66
4

x+ aw
y + bw
z + cw

w

3

77
5


=

2

4
x+aw
w

y+bw
w

z+cw
w

3

5

=

2

4
x

w

+ a
y

w

+ b
z

w

+ c

3

5

=

2

4
x

w

y

w

z

w

3

5
+

2

4
a
b
c

3

5

2

2

66
4

1 0 0 a
0 1 0 b
0 0 1 c
0 0 0 1

3

77
5

2

66
4

x
y
z
w

3

77
5 =

2

66
4

x+ aw
y + bw
z + cw

w

3

77
5


=

2

4
x+aw
w

y+bw
w

z+cw
w

3

5

=

2

4
x

w

+ a
y

w

+ b
z

w

+ c

3

5

=

2

4
x

w

y

w

z

w

3

5
+

2

4
a
b
c

3

5

2

2

66
4

1 0 0 a
0 1 0 b
0 0 1 c
0 0 0 1

3

77
5

2

66
4

x
y
z
w

3

77
5 =

2

66
4

x+ aw
y + bw
z + cw

w

3

77
5


=

2

4
x+aw
w

y+bw
w

z+cw
w

3

5

=

2

4
x

w

+ a
y

w

+ b
z

w

+ c

3

5

=

2

4
x

w

y

w

z

w

3

5
+

2

4
a
b
c

3

5

2

2

66
4

1 0 0 a
0 1 0 b
0 0 1 c
0 0 0 1

3

77
5

2

66
4

x
y
z
w

3

77
5 =

2

66
4

x+ aw
y + bw
z + cw

w

3

77
5


=

2

4
x+aw
w

y+bw
w

z+cw
w

3

5

=

2

4
x

w

+ a
y

w

+ b
z

w

+ c

3

5

=

2

4
x

w

y

w

z

w

3

5
+

2

4
a
b
c

3

5

p0 =

2

4
1 0 v

x

0 1 v
y

0 0 1

3

5 p

2

2

66
4

1 0 0 a
0 1 0 b
0 0 1 c
0 0 0 1

3

77
5

2

66
4

x
y
z
w

3

77
5 =

2

66
4

x+ aw
y + bw
z + cw

w

3

77
5


=

2

4
x+aw
w

y+bw
w

z+cw
w

3

5

=

2

4
x

w

+ a
y

w

+ b
z

w

+ c

3

5

=

2

4
x

w

y

w

z

w

3

5
+

2

4
a
b
c

3

5

p0 =

2

4
1 0 v

x

0 1 v
y

0 0 1

3

5 p

M = TRT�1

2

2

66
4

1 0 0 a
0 1 0 b
0 0 1 c
0 0 0 1

3

77
5

2

66
4

x
y
z
w

3

77
5 =

2

66
4

x+ aw
y + bw
z + cw

w

3

77
5


=

2

4
x+aw
w

y+bw
w

z+cw
w

3

5

=

2

4
x

w

+ a
y

w

+ b
z

w

+ c

3

5

=

2

4
x

w

y

w

z

w

3

5
+

2

4
a
b
c

3

5

p0 =

2

4
1 0 v

x

0 1 v
y

0 0 1

3

5 p

M = TRT�1

Mp = TRT�1p

=

2

66
4

1 0 0 �a
0 1 0 �b
0 0 1 �c
0 0 0 1

3

77
5

2

66
4

1 0 0 a
0 cos ✓ � sin ✓ b
0 sin ✓ cos ✓ c
0 0 0 1

3

77
5

2

66
4

1 0 0 a
0 1 0 b
0 0 1 c
0 0 0 1

3

77
5

2

66
4

p
x

p
y

p
z

p
w

3

77
5

=

2

66
4

1 0 0 a
0 cos ✓ � sin ✓ b cos ✓ � c sin ✓ � b
0 0 1 b sin ✓ + c cos ✓ � b
0 0 0 1

3

77
5

2

66
4

p
x

p
y

p
z

p
w

3

77
5

2

Brief Article

The Author

October 18, 2016

q
x

q
z

=
p
x

p
z

q
x

= q
z

p
x

p
z

= d
p
x

p
z

1

Brief Article

The Author

October 18, 2016

q
x

q
z

=

p
x

p
z

q
x

= q
z

p
x

p
z

= d
p
x

p
z

(q
x

, q
y

, q
z

) =


p
x

·
d

p
z

, p
y

·
d

p
z

, d

=


p
x

·
d

p
z

, p
y

·
d

p
z

, p
z

·
d

p
z


=


p
x

, p
y

, p
z

,
p
z

d


(homogeneous coordinates)


=

2

66
4

1 0 0 0

0 1 0 0

0 0 1 0

0 0

1
d

0

3

77
5

2

66
4

p
x

p
y

p
z

1

3

77
5

1

2

66
4

1 0 0 0

0 1 0 0

0 0 1 0

0 0

1
d

0

3

77
5

2

66
4

p
x

+ v
x

t
p
y

+ v
y

t
p
z

+ v
z

t
1

3

77
5 =

2

66
4

p
x

+ v
x

t
p
y

+ v
y

t
p
z

+ v
z

t
p

z

+v
z

t

d

3

77
5


=

2

6
4

d(p
x

+v
x

t)
p

z

+v
z

t

d(p
y

+v
y

t)
p

z

+v
z

t

d

3

7
5

l = p+ ~vt

p = (p
x

, p
y

, p
z

)

v = (v
x

, v
y

, v
z

)

2

6
4

d(p
x

+v
x

t)
p

z

+v
z

t

d(p
y

+v
y

t)
p

z

+v
z

t

d(p
z

+v
z

t)
p

z

+v
z

t

3

7
5 =

2

6
4

1(p
x

+v
x

t)
p

z

+0t
1(p

y

+v
y

t)
p

z

+0t

1

3

7
5

=

2

4
p

x

p

z

+

v

x

p

z

t
p

y

p

z

+

v

y

p

z

t

1

3

5

=

2

4
p

x

p

z

p

y

p

z

1

3

5
+

2

4
v

x

p

z

v

y

p

z

0

3

5 t

=

1

p
z

2

4
p
x

p
y

1

3

5
+

1

p
z

2

4
v
x

v
y

0

3

5

2

2

66
4

1 0 0 0

0 1 0 0

0 0 1 0

0 0

1
d

0

3

77
5

2

66
4

p
x

+ v
x

t
p
y

+ v
y

t
p
z

+ v
z

t
1

3

77
5 =

2

66
4

p
x

+ v
x

t
p
y

+ v
y

t
p
z

+ v
z

t
p

z

+v
z

t

d

3

77
5


=

2

6
4

d(p
x

+v
x

t)
p

z

+v
z

t

d(p
y

+v
y

t)
p

z

+v
z

t

d

3

7
5

2

6
4

d(p
x

+v
x

t)
p

z

+v
z

t

d(p
y

+v
y

t)
p

z

+v
z

t

d(p
z

+v
z

t)
p

z

+v
z

t

3

7
5 =

2

6
4

1(p
x

+v
x

t)
p

z

+0t
1(p

y

+v
y

t)
p

z

+0t

1

3

7
5

=

2

4
p

x

p

z

+

v

x

p

z

t
p

y

p

z

+

v

y

p

z

t

1

3

5

=

2

4
p

x

p

z

p

y

p

z

1

3

5
+

2

4
v

x

p

z

v

y

p

z

0

3

5 t

=

1

p
z

2

4
p
x

p
y

1

3

5
+

1

p
z

2

4
v
x

v
y

0

3

5

2

2

66
4

1 0 0 0

0 1 0 0

0 0 1 0

0 0

1
d

0

3

77
5

2

66
4

p
x

+ v
x

t
p
y

+ v
y

t
p
z

+ v
z

t
1

3

77
5 =

2

66
4

p
x

+ v
x

t
p
y

+ v
y

t
p
z

+ v
z

t
p

z

+v
z

t

d

3

77
5


=

2

6
4

d(p
x

+v
x

t)
p

z

+v
z

t

d(p
y

+v
y

t)
p

z

+v
z

t

d

3

7
5

2

6
4

d(p
x

+v
x

t)
p

z

+v
z

t

d(p
y

+v
y

t)
p

z

+v
z

t

d(p
z

+v
z

t)
p

z

+v
z

t

3

7
5 =

2

6
4

1(p
x

+v
x

t)
p

z

+0t
1(p

y

+v
y

t)
p

z

+0t

1

3

7
5

=

2

4
p

x

p

z

+

v

x

p

z

t
p

y

p

z

+

v

y

p

z

t

1

3

5

=

2

4
p

x

p

z

p

y

p

z

1

3

5
+

2

4
v

x

p

z

v

y

p

z

0

3

5 t

=

1

p
z

2

4
p
x

p
y

1

3

5
+

1

p
z

2

4
v
x

v
y

0

3

5

2

2

6
4

d(p
x

+v
x

t)
p

z

+v
z

t

d(p
y

+v
y

t)
p

z

+v
z

t

d(p
z

+v
z

t)
p

z

+v
z

t

3

7
5 =

2

6
4

1(p
x

+v
x

t)
0+1t

1(p
y

+v
y

t)
0+1t

1(0+1t)
0+1t

3

7
5

=

2

4
p

x

+v
x

t

t

p

y

+v
y

t

t

1

3

5

=

2

4
v
x

+ p
x

1
t

v
y

+ p
y

1
t

1

3

5

Let u =
1

t
and we get :

2

4
v
x

+ p
x

u
v
y

+ p
y

u
1 + 0u

3

5
=

2

4
v
x

v
y

v
z

3

5
+

2

4
v
x

v
y

v
z

3

5u

= v + ~pu

a line in the plane z = 1

3