Transcript Document
CSCE 590E Spring 2007
Basic Math
By Jijun Tang
Applied Trigonometry
Trigonometric functions
Defined using right triangle
y
sin a
h
h
y
x
cos a
h
tan a
a
x
y sin a
x cos a
Applied Trigonometry
Angles measured in radians
radians
degrees
p
180
180
p
degrees
radians
Full circle contains 2p radians
Trigonometry
Trigonometric identities
sin a sin a
cos a sin a p 2
cos a cos a
tan a tan a
sin a cos a p 2
cos a sin a p 2
sin 2 a cos 2 a 1
sin a cos a p 2
sin a sin a p sin a p
cos a cos a p cos a p
Inverse trigonometric functions
Return angle for which sin, cos, or tan
function produces a particular value
If sin a = z, then a = sin-1 z
If cos a = z, then a = cos-1 z
If tan a = z, then a = tan-1 z
arcs
Vectors and Matrices
Scalars represent quantities that can
be described fully using one value
Mass
Time
Distance
Vectors describe a magnitude and
direction together using multiple values
Vectors and Matrices
Two vectors V and W are added by
placing the beginning of W at the end
of V
Subtraction reverses the second
vector
W
V
V+W
W
V–W
V
V
–W
Vectors and Matrices
Vectors add and subtract
componentwise
V W V1 W1 , V2 W2 ,
, Vn Wn
V W V1 W1 ,V2 W2 ,
,Vn Wn
Vectors and Matrices
The magnitude of an n-dimensional
vector V is given by
V
n
2
V
i
i 1
In three dimensions, this is
V Vx2 Vy2 Vz2
Vectors and Matrices
A vector having a magnitude of 1 is
called a unit vector
Any vector V can be resized to unit
length by dividing it by its magnitude:
V
ˆ
V
V
This process is called normalization
Vectors and Matrices
A matrix is a rectangular array of
numbers arranged as rows and
columns
A matrix having n rows and m columns is
1 2 3
an n m matrix
M
4 5 6
At the right, M is a
2 3 matrix
If n = m, the matrix is a square matrix
Vectors and Matrices
The transpose of a matrix M is
denoted MT and has its rows and
columns exchanged:
1 2 3
M
4 5 6
1 4
T
M 2 5
3 6
Vectors and Matrices
An n-dimensional vector V can be
thought of as an n 1 column matrix:
V V1 , V2 ,
V1
V2
, Vn
Vn
Or a 1 n row matrix:
V T V1 V2
Vn
Vectors and Matrices
Product of two matrices A and B
Number of columns of A must equal
number of rows of B
Entries of the product are given by
m
AB ij Aik Bkj
k 1
If A is a n m matrix, and B is an m p
matrix, then AB is an n p matrix
Vectors and Matrices
Example matrix product
2 3 2 1 8 13
M
1 1 4 5 6 6
M 11 2 2 3 4
M 12 2 1 3 5
13
8
M 21 1 2 1 4 6
M 22 1 1 1 5
6
Vectors and Matrices
Matrices are used to transform vectors
from one coordinate system to another
In three dimensions, the product of a
matrix and a column vector looks like:
M11
M 21
M 31
M12
M 22
M 32
M13 Vx M11Vx M 12Vy M 13Vz
M 23 Vy M 21Vx M 22Vy M 23Vz
M 33 Vz M 31Vx M 32Vy M 33Vz
Identity Matrix In
For any n n matrix M,
the product with the
identity matrix is M itself
I nM = M
MIn = M
Invertible
An n n matrix M is invertible if there
exists another matrix G such that
1 0
0 1
MG GM I n
0 0
0
0
1
The inverse of M is denoted M-1
Determinant
The determinant of a square matrix M
is denoted det M or |M|
A matrix is invertible if its determinant
is not zero
For a 2 2 matrix,
a b a b
det
ad bc
c d c d
Determinant
The determinant of a 3 3 matrix is
m11
m12
m13
m21
m22
m23 m11
m31
m32
m33
m22
m23
m32
m33
m12
m21
m23
m31
m33
m13
m21
m22
m31
m32
m11 m22 m33 m23 m32 m12 m21m33 m23 m31
m13 m21m32 m22 m31
Inverse
Explicit formulas exist for matrix
inverses
These are good for small matrices, but
other methods are generally used for
larger matrices
In computer graphics, we are usually
dealing with 2 2, 3 3, and a special
form of 4 4 matrices
Vectors and Matrices
A special type of 4 4 matrix used in
computer graphics looks like
R11
R21
M
R31
0
R12
R13
R22
R23
R32
R33
0
0
Tx
Ty
Tz
1
R is a 3 3 rotation matrix, and T is a
translation vector
Vectors and Matrices
The inverse of this 4 4 matrix is
M 1
R 1
0
R111
1
R T R211
R311
1 0
R121
R131
R221
1
R23
R321
R331
0
0
R 1T x
1
R T y
R 1T z
1
The Dot Product
The dot product is a product between
two vectors that produces a scalar
The dot product between two
n-dimensional vectors
V and W is
n
given by V W VW
i i
i 1
In three dimensions,
V W VxWx VyWy VzWz
The Dot Product
The dot product can be used to project
one vector onto another
V
a
V cos a
VW
W
W
The Dot Product
The dot product satisfies the formula
V W V W cos a
a is the angle between the two vectors
Dot product is always 0 between
perpendicular vectors
If V and W are unit vectors, the dot
product is 1 for parallel vectors pointing in
the same direction, -1 for opposite
The Dot Product
The dot product of a vector with itself
produces the squared magnitude
VV V V V
2
Often, the notation V 2 is used as
shorthand for V V
The Cross Product
The cross product is a product
between two vectors the produces a
vector
The cross product only applies in three
dimensions
The cross product is perpendicular to
both vectors being multiplied together
The cross product between two parallel
vectors is the zero vector (0, 0, 0)
The Cross Product
The cross product between V and W is
V W VyWz VzWy , VzWx VxWz , VxWy VyWx
A helpful tool for remembering this
formula is the pseudodeterminant
ˆi
ˆj
kˆ
V W Vx
Vy
Vz
Wx Wy Wz
The Cross Product
The cross product can also be
expressed as the matrix-vector product
0
V W Vz
Vy
Vz
0
Vx
Vy Wx
Vx Wy
0 Wz
The perpendicularity property means
V W V 0
V W W 0
The Cross Product
The cross product satisfies the
trigonometric relationship
V W V W sin a
This is the area of
the parallelogram
formed by
V
V and W
||V|| sin a
a
W
The Cross Product
The area A of a triangle with vertices
P1, P2, and P3 is thus given by
A
1
P2 P1 P3 P1
2
The Cross Product
Cross products obey the right hand
rule
If first vector points along right thumb,
and second vector points along right
fingers,
Then cross product points out of right
palm
W V V W
Reversing order of vectors negates the
cross product:
Transformations
Calculations are often carried out in
many different coordinate systems
We must be able to transform
information from one coordinate
system to another easily
Matrix multiplication allows us to do
this
Transformations
Suppose that the coordinate axes in
one coordinate system correspond to
the directions R, S, and T in another
Then we transform a vector V to the
RST system as follows
Rx
W R S T V Ry
Rz
Sx
Sy
Sz
Tx Vx
Ty Vy
Tz Vz
ILLustration
Transformation matrix
We transform back to the original
system by inverting the matrix:
Rx
V Ry
Rz
Sx
Sy
Sz
1
Tx
Ty W
Tz
Often, the matrix’s inverse is equal to
its transpose—such a matrix is called
orthogonal
Transformations
A 3 3 matrix can reorient the
coordinate axes in any way, but it
leaves the origin fixed
We must add a translation component
D to move the origin:
Rx
W Ry
Rz
Sx
Sy
Sz
Tx Vx Dx
Ty Vy Dy
Tz Vz Dz
Transformations
Homogeneous coordinates
Four-dimensional space
Combines 3 3 matrix and translation
into one 4 4 matrix
Rx
Ry
W
Rz
0
Sx
Tx
Sy
Ty
Sz
Tz
0
0
Dx Vx
Dy Vy
Dz Vz
1 Vw
Transformations
V is now a four-dimensional vector
The w-coordinate of V determines
whether V is a point or a direction vector
If w = 0, then V is a direction vector and
the fourth column of the transformation
matrix has no effect
If w 0, then V is a point and the fourth
column of the matrix translates the origin
Normally, w = 1 for points
Transformations
The three-dimensional counterpart of a
four-dimensional homogeneous vector
V is given by
Vx Vy Vz
V3D
, ,
Vw Vw Vw
Scaling a homogeneous vector thus
has no effect on its actual 3D value
Transformations
Transformation matrices are often the
result of combining several simple
transformations
Translations
Scales
Rotations
Transformations are combined by
multiplying their matrices together
Transformation Steps
Orderings
Orderings
Orderings of different type is important
A rotation followed by a translation is
different from a translation followed by
a rotation
Orderings of the same type does not
matter
Transformations
Translation matrix
M translate
1
0
0
0
0 0 Tx
1 0 Ty
0 1 Tz
0 0 1
Translates the origin by the vector T
Transformations
Scale matrix
M scale
a
0
0
0
0 0 0
b 0 0
0 c 0
0 0 1
Scales coordinate axes by a, b, and c
If a = b = c, the scale is uniform
Transformations
Rotation matrix
M z -rotate
cos q
sin q
0
0
sin q
0
0
cos q
0
0
0
1
0
0
0
1
Rotates points about the z-axis
through the angle q
Transformations
Similar matrices for rotations about x, y
M x -rotate
M y -rotate
1
0
0
0
0
cos q
sin q
0
0
sin q
cos q
0
0
0
0
1
0
sin q
0
1
0
0
0
cos q
0
0
0
1
cos q
0
sin q
0
Transformations
Normal vectors transform differently
than do ordinary points and directions
A normal vector represents the direction
pointing out of a surface
A normal vector is perpendicular to the
tangent plane
If a matrix M transforms points from one
coordinate system to another, then
normal vectors must be transformed by
(M-1)T
Geometry
A line in 3D space is represented by
P t S tV
S is a point on the line, and V is the
direction along which the line runs
Any point P on the line corresponds to a
value of the parameter t
Two lines are parallel if their direction
vectors are parallel
Geometry
A plane in 3D space can be defined by
a normal direction N and a point P
Other points in the plane satisfy
N Q P 0
N
Q
P
Geometry
A plane equation is commonly written
Ax By Cz D 0
A, B, and C are the components of the
normal direction N, and D is given by
D N P
for any point P in the plane
Geometry
A plane is often represented by the 4D
vector (A, B, C, D)
If a 4D homogeneous point P lies in
the plane, then (A, B, C, D) P = 0
If a point does not lie in the plane, then
the dot product tells us which side of
the plane the point lies on
Geometry
Distance d from a point P to a line
S+tV
P
P S
d
S
P S V
V
V
Geometry
Use Pythagorean theorem:
P S V
d 2 P S 2
V
Taking square root,
d P S 2
2
P S V 2
V2
If V is unit length, then V 2 = 1
Geometry
Intersection of a line and a plane
Let P(t) = S + t V be the line
Let L = (N, D) be the plane
We want to find t such that L P(t) = 0
Lx S x Ly S y Lz S z Lw
L S
t
LV
LxVx LyVy LzVz
Careful, S has w-coordinate of 1, and V
has w-coordinate of 0
Geometry
If L V = 0, the line is parallel to the
plane and no intersection occurs
Otherwise, the point of intersection is
L S
P t S
V
LV