41
Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

  • View
    216

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Geometry(Many slides adapted from Octavia Camps and Amitabh

Varshney)

Page 2: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Goals

• Represent points, lines and triangles as column vectors.

• Represent motion as matrices.

• Move geometric objects with matrix multiplication.

• Refresh memory about geometry and linear algebra

Page 3: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Vectors

• Ordered set of numbers: (1,2,3,4)

• Example: (x,y,z) coordinates of pt in space. runit vecto a is ,1 If

),(

1

2

,,21

vv

xv

xxxvn

i i

n

Page 4: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Vector Addition

),(),(),( 22112121 yxyxyyxx wv

vvww

V+wV+w

Page 5: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Scalar Product

),(),( 2121 axaxxxaa v

vv

avav

Page 6: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Inner (dot) Product

vv

ww

22112121 .),).(,(. yxyxyyxxwv

The inner product is a The inner product is a SCALAR!SCALAR!

cos||||||||),).(,(. 2121 wvyyxxwv

wvwv 0.

Page 7: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Points

Using these facts, we can represent points. Note:

(x,y,z) = x(1,0,0) + y(0,1,0) + z(0,0,1)

x = (x,y,z).(1,0,0) y = (x,y,z).(0,1,0)

z = (x,y,z).(0,0,1)

Page 8: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Lines• Line: y = mx + a

• Line: sum of a point and a vectorP = P1 + d

(whered is a column vector)

• Line: Affine sum of two points

P = P1 + P2, where + = 1

Line Segment: For 0 , 1, P lies between P1 and P2

• Line: set of points equidistant from the origin in the direction of a unit vector.

P1

d

P1

P2

Page 9: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Plane and Triangle• Plane: sum of a point and two vectors

P = P1 + u + v

Plane: set of points equidistant

from origin in direction

of a vector.

• Triangle: Affine sum of three points

with i 0

P = P1 + P2 + P3,

where + + = 1

P lies between P1, P2, P3

P1u

v

P1P2

P3

Page 10: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Generalizing ... Affine Sum of arbitrary number of points: Convex

Hull

P = P1 + P2 + … + nPn, where + + … + n = 1 and i 0

Page 11: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Normal of a Plane Plane: sum of a point and two vectors

P = P1 + u + v

P - P1 = u + v

Ifn is orthogonal tou andv (n =u v ) :

n T P - P1) = n T u + n

T v = 0

P1u

v

uP1

v

n

Page 12: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Implicit Equation of a Plane

n T P - P1) = 0

a x x1

Letn = b P = y P1 = y1

c z z1

Then, the equation of a plane becomes:

a (x - x1) + b (y - y1) + c (z - z1) = 0

a x + b y + c z + d = 0

Thus, the coefficients of x, y, z in a plane equation define the normal.

P1u

v

uP1

v

n

Page 13: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Normal of a TriangleNormal of the plane containing the triangle (P1, P2 , P3 ):

n = (P2 - P1) (P3 - P1)

P1 P2

n P3

P1 P2

P3

P1 P3

P2

Normal pointing towards you Normal pointing away from you

• Models constructed with consistent ordering of triangle vertices : all clockwise or all counter-clockwise.

• Usually normals point out of the model.

Page 14: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Normal of a Vertex in a Mesh

n1n2

n3

nk

nvnv = (n1 +n2 + … +nk) / k = ni / k = average of adjacent triangle normals

or better:

nv = i ni) / (k i) ) = area-weighted average of adjacent triangle normals

Page 15: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Geometry Continued

• Much of last classes’ material in Appendix A

Page 16: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Matrices

nmnn

m

m

m

mn

aaa

aaa

aaa

aaa

A

21

33231

22221

11211

mnmnmn BAC Sum:Sum:

ijijij bac

A and B must have the same A and B must have the same dimensionsdimensions

Page 17: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Matrices

pmmnpn BAC Product:Product:

m

kkjikij bac

1

A and B must have A and B must have compatible dimensionscompatible dimensions

nnnnnnnn ABBA

Identity Matrix:

AAIIAI

100

010

001

Page 18: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Matrices

• Associative T*(U*(V*p)) = (T*U*V)*p

• Distributive T*(u+v) = T*v + T*v

Page 19: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Matrices

mnT

nm AC Transpose:Transpose:

jiij ac TTT ABAB )(

TTT BABA )(

IfIf AAT A is symmetricA is symmetric

Page 20: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Matrices

Determinant:Determinant: A must be squareA must be square

3231

222113

3331

232112

3332

232211

333231

232221

131211

detaa

aaa

aa

aaa

aa

aaa

aaa

aaa

aaa

122122112221

1211

2221

1211det aaaaaa

aa

aa

aa

Page 21: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Euclidean transformations

Page 22: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

2D Translation

tt

PP

P’P’

Page 23: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

2D Translation Equation

PP

xx

yy

ttxx

ttyy

P’P’tt

tPP ),(' yx tytx

),(

),(

yx tt

yx

t

P

Page 24: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

2D Translation using Matrices

PP

xx

yy

ttxx

ttyy

P’P’tt

),(

),(

yx tt

yx

t

P

1

1

0

0

1' y

x

t

t

ty

tx

y

x

y

xP

tt PP

Page 25: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Scaling

PP

P’P’

Page 26: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Scaling Equation

PP

xx

yy

s.xs.x

P’P’s.ys.y

),('

),(

sysx

yx

P

P

PP s'

y

x

s

s

sy

sx

0

0'P

SPSP '

Page 27: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Rotation

PP

PP’’

Page 28: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Rotation Equations

Counter-clockwise rotation by an angle Counter-clockwise rotation by an angle

y

x

y

x

cossin

sincos

'

'

PP

xx

Y’Y’PP’’

X’X’

yy R.PP'

Page 29: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Degrees of Freedom

R is 2x2 R is 2x2 4 elements4 elements

BUT! There is only 1 degree of freedom: BUT! There is only 1 degree of freedom:

1)det(

R

IRRRR TT

The 4 elements must satisfy the following constraints:The 4 elements must satisfy the following constraints:

y

x

y

x

cossin

sincos

'

'

Page 30: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Transformations can be composed

• Matrix multiplication is associative.

• Combine series of transformations into one matrix. (example, whiteboard).

• In general, the order matters. (example, whiteboard).

• 2D Rotations can be interchanged. Why?

Page 31: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Rotation and Translation

cos -sin tx

sin cos ty

0 0 1

( )(x

y

1)

a -b tx

b a ty

0 0 1

( )(x

y

1)

Rotation, Scaling and Translation

Page 32: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Rotation about an arbitrary point

• Can translate to origin, rotate, translate back. (example, whiteboard).

• This is also rotation with one translation.– Intuitively, amount of rotation is same

either way.– But a translation is added.

Page 33: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Stretching Equation

PP

xx

yy

SSxx.x.x

P’P’SSyy.y.y

y

xs

s

ys

xs

y

x

y

x

0

0'P

),('

),(

ysxs

yx

yx

P

P

S

PSP '

Page 34: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Linear Transformation

y

xs

s

s

y

xs

s

y

x

dc

ba

y

x

y

y

x

sincos

cossin

10

0

sincos

cossin

sincos

cossin0

0

sincos

cossin

'PSVD

Page 35: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Affine Transformation

1

' y

x

tydc

txbaP

Page 36: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Viewing Position

• Express world in new coordinate system.

• If origins same, this is done by taking inner product with new coordinates.

• Otherwise, we must translate.

Page 37: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Simple 3D Rotation

n

n

n

zzz

yyy

xxx

21

21

21...

100

0cossin

0sincos

Rotation about z axis.

Rotates x,y coordinates. Leaves z coordinates fixed.

Page 38: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Full 3D Rotation

cossin0

sincos0

001

cos0sin

010

sin0cos

100

0cossin

0sincos

R

• Any rotation can be expressed as combination of three rotations about three axes.

100

010

001TRR

• Rows (and columns) of R are orthonormal vectors.

• R has determinant 1 (not -1).

Page 39: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

3D Rotation + Translation

• Just like 2D case

Page 40: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

3D Viewing Position

• Rows of rotation matrix correspond to new coordinate axis.

Page 41: Geometry (Many slides adapted from Octavia Camps and Amitabh Varshney)

Rotation about a known axis

• Suppose we want to rotate about u.

• Find R so that u will be the new z axis.– u is third row of R.– Second row is anything orthogonal to u.– Third row is cross-product of first two.– Make sure matrix has determinant 1.