Computer Graphics IIgarryowen.csisdmz.ul.ie/~cs4085/resources/cs4085-lect08.pdf · 2020. 12....
Transcript of Computer Graphics IIgarryowen.csisdmz.ul.ie/~cs4085/resources/cs4085-lect08.pdf · 2020. 12....
-
3-D Rotations (contd.)An Alternative Take on Rotations
Computer Graphics II
P. Healy
CS1-08Computer Science Bldg.
tel: [email protected]
Autumn 2020–2021
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 1 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Outline
1 3-D Rotations (contd.)Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
2 An Alternative Take on Rotations
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 2 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Outline
1 3-D Rotations (contd.)Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
2 An Alternative Take on Rotations
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 3 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Amalgamating Steps 2, 3 & 4
Quaternions are a more compact way of solving the taskand lend themselves very easily to rotating through anangle θ one or more vectors (and, therefore, points) aboutan axis uLike previous two methods a translation of the axis to theorigin is required firstThe method of using quaternions is based on
formula for rotation of a vector around anaxis(See also, here )
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 4 / 15
http://en.wikipedia.org/wiki/Rodrigues%27_rotation_formulahttp://garryowen.csisdmz.ul.ie/~cs4085/resources/oth8.pdf
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Rodrigues Rotation Formula
A one-step method that rotates a vector around anarbitrary axis coincident with the originReminder: rotating a unit-length vector
#»s = 1#»
i + 0#»
j
through a positive angle θ gives the vector
#»
s′ = cos θ#»
i + sin θ#»
j
#»
j
#»
i1 =⇒
(cos θ, sin θ)
θ
1
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 5 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Rodrigues Rotation Formula (contd.)
Task: Rotate the vector #»p aroundthe axis #»r through aθ
(assuming || #»r || = 1)project #»p onto centre axis
#»u = ( #»p · #»r ) #»r
it is #»v = #»p − #»u that we need torotate in plane normal to #»r#»v = #»p − ( #»p · #»r ) #»r
#»r #»p
p
qθ
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 6 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Rodrigues Rotation Formula (contd.)
Task: Rotate the vector #»p aroundthe axis #»r through aθ
(assuming || #»r || = 1)project #»p onto centre axis
#»u = ( #»p · #»r ) #»r
it is #»v = #»p − #»u that we need torotate in plane normal to #»r#»v = #»p − ( #»p · #»r ) #»r
#»r
θ
#»p
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 6 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Rodrigues Rotation Formula (contd.)
Task: Rotate the vector #»p aroundthe axis #»r through aθ
(assuming || #»r || = 1)project #»p onto centre axis
#»u = ( #»p · #»r ) #»r
it is #»v = #»p − #»u that we need torotate in plane normal to #»r#»v = #»p − ( #»p · #»r ) #»r
#»p
#»u
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 6 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Rodrigues Rotation Formula (contd.)
Task: Rotate the vector #»p aroundthe axis #»r through aθ
(assuming || #»r || = 1)project #»p onto centre axis
#»u = ( #»p · #»r ) #»r
it is #»v = #»p − #»u that we need torotate in plane normal to #»r#»v = #»p − ( #»p · #»r ) #»r
#»p
#»u
#»v
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 6 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Rodrigues Rotation Formula (contd.)
#»v lies in defined by #»p and #»rThe vector #»s = #»r × #»p is ⊥ to thisplane; it is also ⊥ to #»v#»w has same orientation as #»s , andso is a scaled multiple of #»s ; #»w = k #»sBecause | #»r | = 1
#»w = #»r × #»p = #»s| #»w | = | #»v |
So #»v rotated through θ becomes#»v cos θ + #»w sin θ
#»p
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 7 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Rodrigues Rotation Formula (contd.)
#»v lies in defined by #»p and #»rThe vector #»s = #»r × #»p is ⊥ to thisplane; it is also ⊥ to #»v#»w has same orientation as #»s , andso is a scaled multiple of #»s ; #»w = k #»sBecause | #»r | = 1
#»w = #»r × #»p = #»s| #»w | = | #»v |
So #»v rotated through θ becomes#»v cos θ + #»w sin θ
#»s
#»p
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 7 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Rodrigues Rotation Formula (contd.)
#»v lies in defined by #»p and #»rThe vector #»s = #»r × #»p is ⊥ to thisplane; it is also ⊥ to #»v#»w has same orientation as #»s , andso is a scaled multiple of #»s ; #»w = k #»sBecause | #»r | = 1
#»w = #»r × #»p = #»s| #»w | = | #»v |
So #»v rotated through θ becomes#»v cos θ + #»w sin θ
#»v
#»w
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 7 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Rodrigues Rotation Formula (contd.)
#»v lies in defined by #»p and #»rThe vector #»s = #»r × #»p is ⊥ to thisplane; it is also ⊥ to #»v#»w has same orientation as #»s , andso is a scaled multiple of #»s ; #»w = k #»sBecause | #»r | = 1
#»w = #»r × #»p = #»s| #»w | = | #»v |
So #»v rotated through θ becomes#»v cos θ + #»w sin θ
θ
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 7 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Rodrigues Rotation Formula (contd.)
Rotation of #»p through θ around #»r is
R(θ, #»r , #»p ) = #»u + cos θ #»v + sin θ #»w= (
#»p · #»r ) #»r + cos θ( #»p − ( #»p · #»r ) #»r ) + sin θ #»r × #»p= cos θ
#»p + ( #»p · #»r )(1− cos θ) #»r + sin θ #»r × #»p
By noting that #»v = − #»r × ( #»r × #»p ) and #»p = #»u + #»v we canwrite R(θ, #»r , #»p ) as
R(θ, #»r , #»p ) = #»u + cos θ #»v + sin θ #»w= (
#»p − #»v ) + cos θ #»v + sin θ #»r × #»p=
#»p + (cos θ − 1) #»v + sin θ #»r × #»p=
#»p + (cos θ − 1)(− #»r × ( #»r × #»p )) + sin θ #»r × #»p=
#»p + (1− cos θ) #»r × ( #»r × #»p ) + sin θ #»r × #»p(1)
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 8 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Rodrigues Rotation Formula (contd.)
Rotation of #»p through θ around #»r is
R(θ, #»r , #»p ) = #»u + cos θ #»v + sin θ #»w= (
#»p · #»r ) #»r + cos θ( #»p − ( #»p · #»r ) #»r ) + sin θ #»r × #»p= cos θ
#»p + ( #»p · #»r )(1− cos θ) #»r + sin θ #»r × #»p
By noting that #»v = − #»r × ( #»r × #»p ) and #»p = #»u + #»v we canwrite R(θ, #»r , #»p ) as
R(θ, #»r , #»p ) = #»u + cos θ #»v + sin θ #»w= (
#»p − #»v ) + cos θ #»v + sin θ #»r × #»p=
#»p + (cos θ − 1) #»v + sin θ #»r × #»p=
#»p + (cos θ − 1)(− #»r × ( #»r × #»p )) + sin θ #»r × #»p=
#»p + (1− cos θ) #»r × ( #»r × #»p ) + sin θ #»r × #»p(1)
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 8 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Rodrigues Rotation Formula (contd.)
Rotation of #»p through θ around #»r is
R(θ, #»r , #»p ) = #»u + cos θ #»v + sin θ #»w= (
#»p · #»r ) #»r + cos θ( #»p − ( #»p · #»r ) #»r ) + sin θ #»r × #»p= cos θ
#»p + ( #»p · #»r )(1− cos θ) #»r + sin θ #»r × #»p
By noting that #»v = − #»r × ( #»r × #»p ) and #»p = #»u + #»v we canwrite R(θ, #»r , #»p ) as
R(θ, #»r , #»p ) = #»u + cos θ #»v + sin θ #»w= (
#»p − #»v ) + cos θ #»v + sin θ #»r × #»p=
#»p + (cos θ − 1) #»v + sin θ #»r × #»p=
#»p + (cos θ − 1)(− #»r × ( #»r × #»p )) + sin θ #»r × #»p=
#»p + (1− cos θ) #»r × ( #»r × #»p ) + sin θ #»r × #»p(1)
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 8 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Rodrigues Rotation Formula (contd.)
Graphical realisation of expressions:
First expressionSecond, more useful, form – eqn.(1) previously
#»p
#»q
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 9 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Rodrigues Rotation Formula (contd.)
Graphical realisation of expressions:
First expressionSecond, more useful, form – eqn.(1) previously
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 9 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Rodrigues Rotation Formula (contd.)
Graphical realisation of expressions:
First expressionSecond, more useful, form – eqn.(1) previously
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 9 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Euler-Rodrigues Rotation Formula
Using trig. identities:sin θ = 2 cos θ2 sin
θ2
cos θ = 1− 2 sin2 θ2 ≡ 1− cos θ = 2 sin2 θ
2
With #»r unit-length (as always), and lettinga = cos θ2ωt = sin θ2
#»r = (b, c,d)t
(not too difficult to show that a2 + b2 + c2 + d2 = 1)
Can now tidy up as follows
R(θ, #»r , #»p ) = #»p + (1− cos θ)( #»r × ( #»r × #»p )) + sin θ( #»r × #»p )R(a, #»ω, #»p ) = #»p + 2( #»ω × ( #»ω × #»p )) + 2a( #»ω × #»p )
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 10 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Euler-Rodrigues Rotation Formula (contd.)
We have seen that#»n = #»u × #»v
can be viewed as the #»u acting on #»v , “sending” it to thevector #»n . From this point of view #»u operates on #»v and inour case we can write
#»s = #»ω × #»p = M #»p
in terms of matrix multiplication where
M =
(0 −d cd 0 −b−c b 0
), (b, c,d)t = sin
θ
2#»r
Then #»ω × ( #»ω × #»p ) = M(M #»p ) = M2 #»p
R(a, #»ω, #»p ) = I #»p + 2M2 #»p + 2aM #»p = R #»p
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 11 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Euler-Rodrigues Rotation Formula (contd.)
R(a, #»ω, #»p ) = R #»p
where
R =
a2 + b2 − c2 − d2 2(bc − ad) 2(bd + ac)2(bc + ad) a2 + c2 − b2 − d2 2(cd − ab)2(bd − ac) 2(cd + ab) a2 + d2 − b2 − c2
Note
tr(R) = 3a2 − (b2 + c2 + d2)= 4a2 − 1 = 2(2a2 − 1) + 1
= 2(2 cos2θ
2− 1) + 1
= 2 cos θ + 1 3
To verify: detR = 1 ...P. Healy (University of Limerick) CS4085 Autumn 2020–2021 12 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Outline
1 3-D Rotations (contd.)Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
2 An Alternative Take on Rotations
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 13 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
Rodrigues Rotation Formula and QuaternionsDetermining the Axis and Angle from the Matrix
Going the other Way
We’ve seen how to construct the rotation matrixGiven a matrix, M how do we determine its axis and angle?We can firstly confirm that it is a 3-D rotation matrix bychecking that determinant is 1To find #»u , the axis, we observe that #»u is the only vectorwhen rotated that is itself
M #»u = #»u(M− I) #»u = 0
Solving for this gives #»uRecall in 3-D, s, the sum of the main diagonal elements(the trace) of the matrix sums to s = 1 + 2 cos θ
s = M11 + M22 + M33 = 1 + 2 cos θ
θ = cos−1(s − 1)/2
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 14 / 15
-
3-D Rotations (contd.)An Alternative Take on Rotations
xkcd’s
xkcd’s Matrix Transform
P. Healy (University of Limerick) CS4085 Autumn 2020–2021 15 / 15
https://xkcd.com/184/
3-D Rotations (contd.)Rodrigues Rotation Formula and Quaternions Determining the Axis and Angle from the Matrix
An Alternative Take on Rotations