neat stuff from vector calculus & related subjects chris hecker checker@d6.com definition six,...
Post on 27-Mar-2015
225 Views
Preview:
TRANSCRIPT
Neat Stuff from Vector CalculusNeat Stuff from Vector Calculus&&
Related SubjectsRelated Subjects
Chris Heckerchecker@d6.com
definition six, inc. & Maxis
Related SubjectsRelated Subjects
vectorcalculus
scalarcalculus
linearalgebra
differentialgeometryclassical
mechanics,dynamics
optimization &constraints
differential &integral calculus
Intro & PrerequisitesIntro & Prerequisites
• this is a total hodge-podge, not a gentle introduction– lack of rationale for caring about this stuff, trust me? :)
• stuff that I found non-intuitive or hard to figure out• tour of fairly basic examples building on themselves to get
firm grounding and intuition in calculus concepts for the kinds of math games do– touch on lots of different areas during tour, many sidestreets
• comfortable with algebra, linear algebra• need to understand scalar calc, at least at the plug’n’chug
level of differentiating functions– f(x) = ax2+bx+c f’(x) = 2ax + b
• a function maps values from the domain to the range uniquely– can be multivalued in range, but not domain
What is a Function?What is a Function?
)(xfy
sin
cos)( f
y
x01),( 22 yxyxf
mnf RR:
)(xfy -1
0
1
2 -1
0
1
2
0
2
4
6
8
-1
0
1
2
1),( 22 yxyxfz
),( vufy
x
• derivative is another function that maps changes in the domain to changes in the range, “normalized”
What is a Derivative?What is a Derivative?
)( xxfyy
)(xfy y
x
x
xfxxf
x
y
)()(
• the key insight of calculus: the change is so small that you can ignore it anytime it’s multiplied by itself...so, you can treat any continuous function as linear if you’re zoomed in far enough (to 1st order)– “continuity” keeps us from dividing by zero– normalization makes the numbers finite
Derivatives are LinearDerivatives are Linear
202
1000 )()()()( xxfxxfxfxxf
)()()(
000 xf
x
xfxxf
)(xfy
x0
)(xfy
x0
boom!
Random but Nifty Example of Ignoring InfinitessimalsRandom but Nifty Example of Ignoring Infinitessimals(nothing up my sleeve!)(nothing up my sleeve!)
• prove infinitessimal rotations in 3D are vectors (add, commute, etc.)– angular velocity is a vector, cross product differentiates rotating vectors
11)1)(1( TT T
infinitessimal rotations are vectors:
3x3 skew symmetric matrices are isomorphic to vectors
rrrdt
drv dt ~ 1
rrrrdr )( vec ' angular velocity differentiates with cross product:
1 ' RRRrr Tfinite rotation: rrrr )1('infinitessimal rotation:
21212121 11)1)(1( infinitessimal rotations add and commute:
Scalar Derivatives: a lineScalar Derivatives: a line
• how does y (or f(x)) change for a change in x?– for lines, the change (derivative) is constant
everywhere
– drawn as red vector, but actually a scalar, “slope”
)(xfy
a
1
baxxf )(axf )('
adxdf
RR: f
RR: df
adx
df
Scalar Derivatives: a curveScalar Derivatives: a curve
• for curves, the derivative is position dependent– derivative is a function itself, mapping change in
domain to change in range
– both direction and magnitude, but still a scalar
cbxaxxf 2)(
)(xfy
RR: f
RR: df
baxxf 2)('dxbaxdf )2(
• vectors are columns of numbers in this talk, not rows• we right-multiply matrices by column vectors: v’ = Mv
• matrix & vector ops “fit together” nicely• keeping the shapes right is the key to sanity with vector calc• “m by n * n by p = m by p”
• this is why “v’=vM” makes no sense for column vectors– either you’re using row vectors, or you’re confused– either way, you’re in for some pain when trying to do real math
• because all math books use columns for vectors and rows are special• early computer graphics books got this backwards, and hosed everybody
The Shape of Matrix OperationsThe Shape of Matrix Operations
131211 aaa
31
21
11
b
b
b
11c
ab = c = aTb = c
333231
232221
131211
aaa
aaa
aaa
31
21
11
b
b
b
31
21
11
c
c
c
Ab=c
232221
131211
aaa
aaa
34333231
24232221
14131211
bbbb
bbbb
bbbb
24232221
14131211
cccc
ccccm
n
n
p
AB=C
Shape of DerivativesShape of Derivativesdf needs to accept a df needs to accept a domain linearly (ie. right-multiplied vector or domain linearly (ie. right-multiplied vector or
scalar) to produce a scalar) to produce a rangerange
• scalar valued function of scalar– y=f(x) dy =dfdx
• vector valued function of scalar– v=f(t) dv = dfdt
• scalar valued function of vector– z=f(x,y)
• vector valued function of vector– p=f(u,v)
d
d
d
d
df
Shape of Derivatives (cont.)Shape of Derivatives (cont.)
• scalar valued function of vector: expands to row vector– the resulting range value depends on all the domain values– the differential needs a slot for a delta/change in each domain
dimension...so it must be a row vector, there’s no T or – z=f(x,y)– dz=dfdx
• vector valued function of vector: expands to matrix– p=f(u,v)
df = d
df = d
dy
dx
y
f
x
fdf
dyy
fdxx
fdz
xx
dz = dfdx = d
dp = dfdx = d
• for a change in the parameter (domain), how does the function (range) change?– in this case, differential is a vector
Derivatives: a parametric functionDerivatives: a parametric function“a vector function of a scalar”“a vector function of a scalar”
sin
cos
y
x
dd
d
dy
dx
cos
sin
cos
sin
2RR: f2RR: df
Derivatives: a scalar function of a vectorDerivatives: a scalar function of a vector“height field”“height field”
• differential is not in range of function
0 0.5 1 1.5 20
0.5
1
1.5
2
dcybxyaxyxfz 22),(
dycybxdxbyax )2()2(
dyy
fdxx
fdfdz
dy
dxcybxbyax 22
RR: 2 f
RR: 2 df
-1
0
1
2 -1
0
1
2
0
2
4
6
8
-1
0
1
2
row vector
column vector
-1
0
1
2 -1
0
1
2
0
2
4
6
8
-1
0
1
2
Derivatives: a scalar function of a vectorDerivatives: a scalar function of a vector
• view “height field” as implicit surface in 3d– write g(x,y,z) > 0 above surface
– differential is surface normal (not unit)
),(),,( yxfzzyxg
dz
dy
dx
cybxbyax
dzz
gdyy
gdxx
gdg
122
RR: 3 f
RR: 3 df
1
2
2
cybx
byaxg
gT
x
Derivatives: a scalar function of a vectorDerivatives: a scalar function of a vector
• example plane
),(),,( yxfzzyxg
dz
dy
dx
dzz
gdyy
gdxx
gdg
111
RR: 3 f
RR: 3 df
-1
-0.5
0
0.5
1 -1
-0.5
0
0.5
1
-2
-1
0
1
2
-1
-0.5
0
0.5
1
0 dpnz
y
x
pn ,
1
1
1
dyxyxfz
dzyx
),(
0
dyxzzyxg ),,(
Derivatives: a scalar function of a vectorDerivatives: a scalar function of a vector
• example sphere 1),,( 222 zyxzyxg
dz
dy
dx
zyx
dzz
gdyy
gdxx
gdg
222
RR: 3 f
RR: 3 df
A Surface Normal is Not a Vector!A Surface Normal is Not a Vector!this is why you need to keep shapes distinctthis is why you need to keep shapes distinct
• vector is a difference between two points
• normal is “really” a mapping from a vector to a scalar
a
b
n
v
'''
'''
'
'
abv
abTaTbTvv
abv
Tbb
Taa
points &vectors transform like this:
T
T
TT
T
T
T
TS
ST
SnTv
SnTv
TvvSnn
nv
nvnv
1
0
0)(
' ,'
0''
0
normals transform like this:
0.5 1 1.5 2
-1
-0.5
0.5
1
Normals and Vectors ExampleNormals and Vectors Example
• scaling an ellipse 1),( 22 yaxyxg
yaxg
22
x
2
4
11
41
21
xa
x values for y=0
Derivative of Vector MappingsDerivative of Vector Mappings
• barycentric coordinates in 2D triangle– vector function of a vector
– if square, can invert Jacobian to find du,dv given dp– function is linear in this case, but works generally
– determinant of Jacobian is how areas distort under function
e1
e2
p0
p1
p2
pdv
duee
dv
du
v
f
u
fv
f
u
f
ddyy
xx
21
uu
fp
22 RR: f22 RR: df
veuepvufp 210),(
Jacobian matrix
Barycentric Coordinates in 3D TriangleBarycentric Coordinates in 3D Triangle
• now jacobian is 3x2– can still find du,dv from dp with least squares
e1
e2
p0
p1
p2
p
dv
duee
dv
du
v
f
u
fv
f
u
fv
f
u
f
ddp
zz
yy
xx
21
uu
f
32 RR: f32 RR: df
veuepvufp 210),(
bAAxAbAx TT
dpe
e
dv
duee
e
eT
T
T
T
2
121
2
1
dv
du
eeee
eeee
dpe
dpeTT
TT
T
T
2212
2111
2
1
same as projecting dp down into triangle
Implicit FunctionsImplicit Functions• equalities (constraints) subtract off DOFs
• explicit to implicit is easy: z = f(x,y) g(x,y,z) = z – f(x,y) =0
• implicit to explicit is hard: f(x,y) = 0 y = f(x)• solving nonlinear equations, sometimes multiple or no solutions
• but, inverting it differentially is easy because of linearization:
0),,( zyxg
0),,( zyxf
21 xy
0
xxdf
0
dyy
fdxx
f
dxdy
dxdyy
fx
f
01),( 22 yxyxf dxdy yx
22
shape/rank of jacobian will tell you how constrained you are as well
f(x,y) = 0
dxdy 0
Product Rule for Vector DerivativesProduct Rule for Vector Derivatives
• for scalar multiplication:• differential of a scalar function of a scalar is a scalar
dbabdabad )(
Product Rule for Vector DerivativesProduct Rule for Vector Derivatives
• for scalar multiplication:• differential of a scalar function of a scalar is a scalar
• for dot product it’s a little wackier• if vectors in dot are functions of scalars, it’s the same
dbabdabad )(
dbabdabad )(
Product Rule for Vector DerivativesProduct Rule for Vector Derivatives
• for scalar multiplication:• differential of a scalar function of a scalar is a scalar
• for dot product it’s a little wackier• if vectors in dot are functions of scalars, it’s the same
• if vectors in dot are functions of vectors, need to watch shape!– we know result must be row:
dbabdabad )(
dbabdabad )(
d
Product Rule for Vector DerivativesProduct Rule for Vector Derivatives
• for scalar multiplication:• differential of a scalar function of a scalar is a scalar
• for dot product it’s a little wackier• if vectors in dot are functions of scalars, it’s the same
• if vectors in dot are functions of vectors, need to watch shape!– we know result must be row:
dbabdabad )(
dbabdabad )(
d
d d ???
dbabdabad TTT )(use transpose picture to reason about it:
Product Rule for Vector DerivativesProduct Rule for Vector Derivatives
• for scalar multiplication:• differential of a scalar function of a scalar is a scalar
• for dot product it’s a little wackier• if vectors in dot are functions of scalars, it’s the same
• if vectors in dot are functions of vectors, need to watch shape!– we know result must be row:
dbabdabad )(
dbabdabad )(
dbadabbad TTT )(
d
d d ???
dbabdabad TTT )(
don’t want to use tensors, so we pull a fast one with the commutativity of dot (ab=ba)
d d
use transpose picture to reason about it:
Dot Product Derivative ExampleDot Product Derivative Example
• derivative of squared length of vector
qpr 22 )( qprrrrr T
)()(2 qpqpddr T
dprdpqpdr TT 2)(22
)()()()(2 qpdqpqpdqpdr TT
dbadabbad TTT )(
p
q
rdp
makes intuitive sense:if dp is orthogonal, length doesn’t change
Cross Product Works the Same WayCross Product Works the Same Way
• if cross is a vector function of vectors...• result must be a matrix
• use the skew symmetric picture of cross product
abbaba~~
d d ???
dbadabbad ~~)~(
dbabdabad )(
same problem with tensors, so we pull the same (skew-)commutativity trick
Cross Product Derivative ExampleCross Product Derivative Example
• differentiate a cross product of moving vector with constant vector
nr
dr
c
dc
drndc
nrc nrdnrddc ~)(
drndnrdrnnrd ~~~~
dbadabbad ~~)~(
again, makes intuitive sense:dc changes orthogonally to dr changes
ReferencesReferences
• Advanced Calculus of Several Variables– Edwards, Dover
• Calculus and Analytic Geometry– Thomas & Finney
• Classical Mechanics– Goldstein
top related