View
221
Download
0
Embed Size (px)
Citation preview
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
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
Vector Addition
),(),(),( 22112121 yxyxyyxx wv
vvww
V+wV+w
Scalar Product
),(),( 2121 axaxxxaa v
vv
avav
Inner (dot) Product
vv
ww
22112121 .),).(,(. yxyxyyxxwv
The inner product is a The inner product is a SCALAR!SCALAR!
cos||||||||),).(,(. 2121 wvyyxxwv
wvwv 0.
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)
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
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
Generalizing ... Affine Sum of arbitrary number of points: Convex
Hull
P = P1 + P2 + … + nPn, where + + … + n = 1 and i 0
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
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
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.
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
Geometry Continued
• Much of last classes’ material in Appendix A
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
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
Matrices
• Associative T*(U*(V*p)) = (T*U*V)*p
• Distributive T*(u+v) = T*v + T*v
Matrices
mnT
nm AC Transpose:Transpose:
jiij ac TTT ABAB )(
TTT BABA )(
IfIf AAT A is symmetricA is symmetric
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
Euclidean transformations
2D Translation
tt
PP
P’P’
2D Translation Equation
PP
xx
yy
ttxx
ttyy
P’P’tt
tPP ),(' yx tytx
),(
),(
yx tt
yx
t
P
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
Scaling
PP
P’P’
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 '
Rotation
PP
PP’’
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'
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
'
'
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?
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
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.
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 '
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
Affine Transformation
1
' y
x
tydc
txbaP
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.
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.
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).
3D Rotation + Translation
• Just like 2D case
3D Viewing Position
• Rows of rotation matrix correspond to new coordinate axis.
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.