CS559: Computer Graphics
Lecture 13: Hierarchical Modeling and Curves
Li Zhang
Spring 2010
Last time: 3D Example: A robot arm• Consider this robot arm with 3 degrees of freedom:
– Base rotates about its vertical axis by θ– Upper arm rotates in its xy‐plane by φ– Lower arm rotates in its xy‐plane by ψ
h1
h2 h3
Base
Upper armLower arm
ψφ
z
x
y
y
x
θ
x
• Q: What matrix do we use to transform the base to the world?
• R_y(θ)• Q: What matrix for the upper arm to the base?
• T(0,h1,0)R_z(φ)• Q: What matrix for the lower arm to the upper arm?
• T(0,h2,0)R_z(ψ)
Robot arm implementation• The robot arm can be displayed by keeping a global matrix and computing it
at each step:
Matrix M_model;
display(){
. . .
robot_arm();
. . .
}
robot_arm()
{
M_model = R_y(theta);
base();
M_model = R_y(theta)*T(0,h1,0)*R_z(phi);
upper_arm();
M_model = R_y(theta)*T(0,h1,0)*R_z(phi)*T(0,h2,0)*R_z(psi);
lower_arm();
}
Do the matrix computations seem wasteful?How to translate the whole robot?
• Q: What matrix do we use to transform the base to the world?
• R_y(θ)• Q: What matrix for the upper arm to the base?
• T(0,h1,0)R_z(φ)• Q: What matrix for the lower arm to the upper arm?
• T(0,h2,0)R_z(ψ)
• Instead of recalculating the global matrix each time, we can just update it in place by concatenating matrices on the right:
Robot arm implementation, better
Matrix M_model;
display(){
. . .
M_model = identity;
robot_arm();
. . .
}
robot_arm()
{
M_model *= R_y(theta);
base();
M_model *= T(0,h1,0)*R_z(phi);
upper_arm();
M_model *= T(0,h2,0)*R_z(psi);
lower_arm();
}
• OpenGL maintains the model‐view matrix, as a global state variable which is updated by concatenating matrices on the right.
display()
{
. . .
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
robot_arm();
. . .
}
robot_arm()
{
glRotatef( theta, 0.0, 1.0, 0.0 );
base();
glTranslatef( 0.0, h1, 0.0 );
glRotatef( phi, 0.0, 0.0, 1.0 );
lower_arm();
glTranslatef( 0.0, h2, 0.0 );
glRotatef( psi, 0.0, 0.0, 1.0 );
upper_arm();
}
Robot arm implementation, OpenGL
Hierarchical modeling
• Hierarchical models can be composed of instances using trees:
– edges contain geometric transformations– nodes contain geometry (and possibly drawing attributes)
How might we draw the tree for the car?
A complex example: human figure
• Q: What’s the most sensible way to traverse this tree?
Human figure implementation, OpenGLfigure()
{
torso();
glPushMatrix();
glTranslate( ... );
glRotate( ... );
head();
glPopMatrix();
glPushMatrix();
glTranslate( ... );
glRotate( ... );
left_upper_arm();
glPushMatrix();
glTranslate( ... );
glRotate( ... );
left_lower_arm();
glPopMatrix();
glPopMatrix();
. . .
}
Curves
x
y
line circlex
y
Freeformx
y
Curve Representation
x
y
line
baxy +=
circlex
y
0)()(),( 222 =−−+−= rdycxyxf0),( =+−= byaxyxf
⎥⎦
⎤⎢⎣
⎡⋅⋅
+⎥⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡trtr
dc
yx
sincos
c
d t
c
dtθ
⎥⎦
⎤⎢⎣
⎡⋅+⎥
⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡θθ
sincos
tdc
yx
Explicit:
Implicit:
Parametric:
Curve Representation
x
y
line circlex
y
⎥⎦
⎤⎢⎣
⎡⋅⋅
+⎥⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡trtr
dc
yx
2sin2cos
c
d t
c
dtθ
⎥⎦
⎤⎢⎣
⎡⋅+⎥
⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡θθ
sincos
2tdc
yx
Parametric:
Curve Representation
x
y
line circlex
y
⎥⎦
⎤⎢⎣
⎡
⋅⋅
+⎥⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡3
3
sincos
trtr
dc
yx
c
d t
c
dtθ
⎥⎦
⎤⎢⎣
⎡⋅+⎥
⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡θθ
sincos3t
dc
yx
Parametric:
Curve Representation
x
y
line circlex
y
⎥⎦
⎤⎢⎣
⎡⋅⋅
+⎥⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡)(sin)(cos
tgrtgr
dc
yx
c
d t
c
dtθ
⎥⎦
⎤⎢⎣
⎡⋅+⎥
⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡θθ
sincos
)(tgdc
yx
Parametric:
Any invertible function g will result in the same curve
What are Parametric Curves?
• Define a mapping from parameter space to 2D or 3D points– A function that takes parameter values and gives back 3D points
• The result is a parametric curve
0 t1
Mapping:F:t→(x,y,z)
0
1(Fx(t), Fy(t), Fz(t),)
An example of a complex curve
⎩⎨⎧
>−≤
=5.0)12(5.0)2(
)(tttt
tcircle
line
ff
f
Piecing together basic curves
Continuities
⎩⎨⎧
>−≤
=5.0)12(5.0)2(
)(tttt
tcircle
line
ff
f
)0()1(:0circleline
C ff =
)0()1(:1 ''circleline
C ff =
)0()1(:2 ''''circleline
C ff =
)0()1(:1 ''circleline
kG ff ⋅=
)0()1(:2 ''''circleline
kG ff ⋅=
Polynomial Pieces
nntatataatf ++++= L2
210)(
3
0)( Rtt i
n
i
ii ∈=∑
=
aaf
Polynomial functions:
Polynomial curves:
Polynomial Evaluation
nntatataatf ++++= L2
210)(Polynomial functions:
f = a[0];for i = 1:n
f += a[i]*power(t,i);end
f = a[0];s = 1;for i = 1:n
s *= t;f += a[i]*s;
end
( )11210)( −++++= n
ntataatatf L
( )( )( )nnn taataatatatf +++++= −− 12210)( L
( )( )23210)( −++++= n
ntataatatatf L
f = a[n];for i = n‐1:‐1:0
f = a[i]+t*f;end
A line Segment
• We have seen the parametric form for a line:
• Note that x, y and z are each given by an equation that involves:– The parameter t
– Some user specified control points, x0 and x1• This is an example of a parametric curve
10
10
10
)1()1()1(
tzztztyytytxxtx
+−=+−=+−=
10)1()( ppfp ⋅+⋅−== tttp0
p1
A line Segment
• We have seen the parametric form for a line:
10
10
10
)1()1()1(
tzztztyytytxxtx
+−=+−=+−=
10)1()( ppfp ⋅+⋅−== tttp0
p1
)()( 010 pppfp −⋅+== tt
3
0)( Rtt i
n
i
ii ∈=∑
=
aaf
011
00
ppapa−=
=⎥⎦
⎤⎢⎣
⎡⎥⎦
⎤⎢⎣
⎡−
=⎥⎦
⎤⎢⎣
⎡
1
0
1
0
1101
pp
aa
⎥⎦
⎤⎢⎣
⎡=
1
0
pp
B
From control points p, we can solve coefficients a
More control points
p0
p1
p2
More control points
p0
p1 2210)( ttt aaaf ++=
p2
22
100 00)0( aaafp ++==
22
101 5.05.0)5.0( aaafp ++==
22
102 11)0.1( aaafp ++==⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
2
1
0
2
1
0
11125.05.01001
aaa
ppp
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡=
2
1
0
aaa
C
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
−−−=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡−
2
1
0
2
1
01
2
1
0
242143
001
ppp
ppp
Caaa [ ]
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡=
2
1
021)(
aaa
f ttt
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡= −
2
1
01
ppp
tC⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡=
2
1
0
ppp
tBBy solving a matrix equation that satisfies the constraints,we can get polynomial coefficients
Two views on polynomial curves
[ ]⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡=
2
1
021)(
ppp
Bf ttt
[ ] )(1)(
2
1
02
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡=
ppp
Bf ttt
2210)( ttt aaaf ++=
[ ]⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡=
2
1
02 )1()(
ppp
Bf ttt
221100 )()()()( pppf tbtbtbt ++=
From control points p, we can compute coefficients a
Each point on the curve is a linear blending of the control points
[ ]⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡=
2
1
0
210 )()()(ppp
tbtbtb
What are b0(t), b1(t), …?
[ ]( ) ⎥⎦
⎤⎢⎣
⎡=
1
01)(pp
Bf tt
1100 )()()( ppf tbtbt +=
⎥⎦
⎤⎢⎣
⎡⎥⎦
⎤⎢⎣
⎡−
=⎥⎦
⎤⎢⎣
⎡
1
0
1
0
1101
pp
aa
Two control point case:
[ ] [ ] ⎥⎦
⎤⎢⎣
⎡−
=1101
1)()( 10 ttbtb
[ ]tt−= 1
b0(t) b1(t)
What are b0, b1, …?
[ ]⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡=
2
1
02 )1()(
ppp
Bf ttt
221100 )()()()( pppf tbtbtbt ++=
Three control point case:
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
−−−=
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
2
1
0
2
1
0
242143
001
ppp
aaa
[ ] [ ]⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
−−−=242143
0011)()()( 2
210 tttbtbtb
[ ]222 244231 tttttt +−−+−= ?)()()( 210 =++ tbtbtb 1≡Which is b0(t)?
What are b0, b1, …?
• Why is important?– Translation‐invariant interpolation
[ ]⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡=
2
1
02 )1()(
ppp
Bf ttt
221100 )()()()( pppf tbtbtbt ++=
Three control point case:
1)()()( 210 ≡++ tbtbtb
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
+++
⇒⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
dpdpdp
ppp
2
1
0
2
1
0 ))(())(())(()( 221100 dpdpdpf +++++= tbtbtbtnew
( )dppp
)()()()()()(
210
221100
tbtbtbtbtbtb
+++++=
df += )(t for any t
Many control points
p0
p1
p2pn
002
020100 )( paaaaf =++++= nntttt L
3
0)( Rtt i
n
i
ii ∈=∑
=
aaf
112
121101)( paaaaf =++++= nntttt L
L
nn
nnnnn tttt paaaaf =++++= L2
210)(⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
=
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢
⎣
⎡
nnnnn
n
n
tt
tttt
p
pp
a
aa
MM
L
L
L
L
1
0
1
0
11
00
1
11
Straightforward, but not intuitive
Many control points
• A shortcut
• Goal:
• Idea:
• Magic:
∑=
=n
iii tbt
0)()( pf
iit pf =)(
ijtbtb
ji
ii
≠==
0)(1)(
∏≠= −
−=
n
ijj ji
ji tt
tttb
,0
)(
ni
n
ii
i
ii
i
ii
i
ii tttt
tttt
tttt
tttt
tttt
tttt
−−
−−
−−
−−
−−
−−
=+
+
−
− LL1
1
1
1
1
1
0
0
Getting bi(t) is easier!
∑=
=n
ii tb
0?)( 1≡ Why?
?)(0
=∑=
n
iji tb nj L,1,0,1 =∀=
is a polynomial of degree n∑
=
=n
ii tbtB
0)()(
Lagrange Interpolation
If an n‐degree polynomial has the same value at n+1 locations, it must be a constant polynomial
Lagrange Polynomial Interpolation
Lagrange Interpolation Demo
• http://www.math.ucla.edu/~baker/java/hoefer/Lagrange.htm
• Properties:– The curve passes through all the control points
– Very smooth: Cn for n control points
– Do not have local control
– Overshooting
Piecewise Cubic Polynomials
• Desired Features:– Interpolation
– Local control
– C1 or C2
33
2210)( tttt aaaaf +++=
Natural Cubics
33
22
100 000)0( aaaafp +++==
32
211 0302)0( aaafp ⋅+⋅+=′=
322 062)0( aafp ⋅++=′′=
33
2210)( tttt aaaaf +++=
32103 )1( aaaafp +++==
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
=
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
3
2
1
0
3
2
1
0
1111020000100001
aaaa
pppp
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
−−−
=
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
3
2
1
0
3
2
1
0
15.01105.00000100001
pppp
aaaa
Natural Cubics
• If we have n points, how to use natural cubic to interpolate them? – Define the first and second derivatives for the starting point of the first segment.
– Compute the cubic for the first segment
– Copy the first and second derivatives for the end point of the first segment to the starting point for the second segment
• How many segments do we have for n control points? • n‐1
Natutral Cubic Curves
• Demo: http://www.cse.unsw.edu.au/~lambert/splines/
Natural CubicsInterpolate control points
Has local control C2 continuity
Natural cubics
Hermit Cubics
33
22
100 000)0( aaaafp +++==
32
211 0302)0( aaafp ⋅+⋅+=′=
3213 32)1( aaafp ++=′=
33
2210)( tttt aaaaf +++=
32102 )1( aaaafp +++==
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
=
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
3
2
1
0
3
2
1
0
3210111100100001
aaaa
pppp
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
−−−−
=
⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢
⎣
⎡
3
2
1
0
3
2
1
0
12121323
00100001
pppp
aaaa
Hermite Cubic Curves
• If we have n points, how to use Hermite cubic to interpolate them? – For each pair, using the first derivatives at starting and ending points to define the inbetween
• How many segments do we have for n controls? – n/2‐1
Hermite CubiesInterpolate control points
Has local control C2 continuity
Natural cubics Yes No Yes
Hermite cubics
Top Related