SlideShare a Scribd company logo
8
Most read
10
Most read
13
Most read
Maths and Technologies for Games
Quaternions
CO3303
Week 1
• We have used two methods to store a rotation:
Representing Rotations
2. Three Euler/Fixed angles:
– X, Y & Z, (or yaw, pitch & roll)
– Can be combined in any order
– Used in TL-Engine
[See Van Verth for more detail]












1
0
0
0
0
0
0
z
y
x
z
y
x
z
y
x
Z
Z
Z
Y
Y
Y
X
X
X
1. A matrix:
– Can just use 3x3 matrix
for rotation
– Used these in DirectX
Converting between Formats
• We can create a matrix from fixed angles
– Create a rotation matrix for each angle:
– E.g. Z rotation matrix of α:
• Multiply the matrices together: M = RX*RY*RZ
– Different results for different multiplication orders
• Can also convert matrix back to fixed angles
– See Van Verth or the matrix class in the labs














1
0
0
0
0
1
0
0
0
0
cos
sin
0
0
sin
cos




Z
R
Euler Angles – Pros/Cons
• Concise storage – just three floats
• Euler/Fixed angles seem intuitive
– But which order to multiply when forming a matrix?
– Different orders in same app can cause problems
• Are the rotations world or local rotations?
– Depends on order again
• Gimbal lock can occur when one angle is 90°
– The other angles interfere with each other, result is ambiguous
– E.g. causing strange spinning effects when looking straight up or
down (you will have seen this problem in some games)
Matrices – Pros/Cons
• Unambiguous definition of rotation
– As compared to Euler angles
• 4x4 matrix can also hold position and scale
– And totally different things: projection matrix
• Used by graphics hardware
– Must convert all forms to matrices eventually
• But uses 16 floats
– Much processing/storage even for simple operations
• Can be stored in two ways, by row or by column
– APIs (DirectX) and maths texts use different forms
Axis-Angle Rotations
• Look for other ways to specify rotations…
• Can specify any rotation as a rotation axis r (a vector)
and an angle θ (a scalar):
• Can convert to and from matrices
(see Van Verth or matrix class)
• Useful way to think about rotation
• But operations are generally
complex with this form
– Including interpolation (see later)
Quaternions
• Quaternions can be used to represent rotation
• A general quaternion takes the form:
– We will use these forms interchangeably
• We will mostly consider normalised quaternions:
• However, several quaternion formulae result in un-
normalised quaternions
– Often need to renormalise quaternions before reuse
)
,
,
(
where
)
,
(
or
)
,
,
,
(
z
y
x
w
z
y
x
w



v
v
q
q
1
where 2
2
2
2



 z
y
x
w
= examinable
Quaternions
• A quaternion is a form of axis-angle rotation
– When in a normalised form
• If we rewrite a quaternion in this form:
• Then r and θ form an axis-angle
rotation as described before:
– r is a unit vector here
)
)
2
/
sin(
),
2
/
(cos(
)
,
( r
v
q 


 w
Quaternions – Pros/Cons
• Why use this more complex variation on angle-axis form?
• Because quaternions can easily be:
– Combined together
– Used to transform points/vectors
– Quaternions can be interpolated easily
• A feature vital for animation, which is more difficult with matrices
• Quaternions only use 4 floats for storage
• However, they lack hardware support
– So we need to convert them to and from matrices
Quaternion Formulae 1
• A quaternion can be converted to a matrix:
– A little expensive, can be simplified in code
– Transposed from Van Verth book for row-based system (DirectX / math
text difference)
• Reverse conversion is also possible (see Van Verth)
• Quaternions don’t convert easily to Euler angles
normalised
not
is
if
1
by
result
multiply
1
0
0
0
0
2
2
1
2
2
2
2
0
2
2
2
2
1
2
2
0
2
2
2
2
2
2
1
then
,
)
,
,
,
(
If
2
2
2
2
2
2
2
2
2
2
q
M
q
q
z
y
x
w
y
x
wx
yz
wy
xz
wx
yz
z
x
wz
xy
wy
xz
wz
xy
z
y
z
y
x
w































Quaternion Formulae 2
• Quaternions can be added and scaled:
– Scaling is used for normalisation
• Two quaternions can be multiplied to create a single
quaternion performing both rotations:
– Same effect as multiplying matrices, order important
– Coded efficiently this is faster than matrix multiplication
– N.B. Swapped multiplication order from text for row-based system
)
,
,
,
(
)
,
,
,
(
)
,
,
,
( 2
1
2
1
2
1
2
1
2
2
2
2
1
1
1
1 z
z
y
y
x
x
w
w
z
y
x
w
z
y
x
w 





)
,
,
,
(
)
,
,
,
( az
ay
ax
aw
z
y
x
w
a 
)
,
(
)
,
( 1
2
2
1
2
1
2
1 v
v
v
v
v
v
v
q
q 1
2
2
1 





 w
w
w
w
w
Quaternion Formulae 3
• Inverse of a quaternion (the rotation in the opposite
direction) is simple:
– Assumes quaternion is normalised
– Much faster than matrix equivalent, which can be complex
• We can also represent vectors as quaternions
– Just set w = 0:
)
,
(
1
v
q 


w
quaternion
a
as
)
,
,
,
0
(
)
,
,
(
Vector z
y
x
z
y
x 

p
Quaternion Formulae 4
• Rotate a vertex or vector p by a quaternion q=(w,v):
– Slower than matrix equivalent
– 1st formula reversed for row-based system (2nd remains same)
– N.B. The formula in earlier Van Verth edition is incorrect
• Derivation of most formulae in Van Verth
– As well as further detail
pq
q
p 1
q


)
(
Rotate
)
(
2
)
(
2
)
1
2
( 2
p
v
v
p
v
p 




 w
w
Quaternions: Initial Summary
• Quaternions can perform similar operations to matrices
– With comparable performance
– But need to convert to / from matrices
– And can’t store position / scaling
• No compelling reason to use them yet
• But next week we will see how quaternions compare to
matrices for interpolation
– And how this is used this for animation

More Related Content

PPT
lecture-9-online WORK PART UNIFORMITY IN
PPT
lecture-9-online.pptVHVHJBJBJBBJBJBBBBBHHBH
PPT
Lecture 9-online
PPT
affine transformation for computer graphics
PPT
september4.ppt
PDF
Mesh Shape Editing
PDF
2d Transformation.pdf
PPT
GeometricTransformations.ppt
lecture-9-online WORK PART UNIFORMITY IN
lecture-9-online.pptVHVHJBJBJBBJBJBBBBBHHBH
Lecture 9-online
affine transformation for computer graphics
september4.ppt
Mesh Shape Editing
2d Transformation.pdf
GeometricTransformations.ppt

Similar to CO3303-1 Lecture 2.ppt (20)

PDF
Geometric objects and transformations
PPT
CO3303-2 Lecture.ppt
PPT
Computer graphics
PPTX
2 d transformations and homogeneous coordinates
PDF
Robotics Representing Position & Orientation 1
PPTX
Digital control systems (dcs) lecture 18-19-20
PPT
Mk slides.ppt
PPTX
Eigen values and Eigen vectors ppt world
PDF
Chapter_2_Representing Position and Orientation.pdf
PPT
Transformations in Computer Graphics
PPT
Transformations
PPTX
2A_ROBOT KINEMATICS.pptx
PPTX
5_6221983039971394498.pptx
PDF
Computer Graphics - Lecture 02 transformation
PPTX
PhasePlane1-1.pptx
PPTX
04 image transformations_ii
PPTX
Loop parallelization & pipelining
PPT
robotics presentation (2).ppt is good for the student life and easy to gain t...
PPTX
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIA
Geometric objects and transformations
CO3303-2 Lecture.ppt
Computer graphics
2 d transformations and homogeneous coordinates
Robotics Representing Position & Orientation 1
Digital control systems (dcs) lecture 18-19-20
Mk slides.ppt
Eigen values and Eigen vectors ppt world
Chapter_2_Representing Position and Orientation.pdf
Transformations in Computer Graphics
Transformations
2A_ROBOT KINEMATICS.pptx
5_6221983039971394498.pptx
Computer Graphics - Lecture 02 transformation
PhasePlane1-1.pptx
04 image transformations_ii
Loop parallelization & pipelining
robotics presentation (2).ppt is good for the student life and easy to gain t...
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIA
Ad

Recently uploaded (20)

PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Cell Types and Its function , kingdom of life
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Classroom Observation Tools for Teachers
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Lesson notes of climatology university.
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Trump Administration's workforce development strategy
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
O7-L3 Supply Chain Operations - ICLT Program
O5-L3 Freight Transport Ops (International) V1.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Cell Types and Its function , kingdom of life
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
human mycosis Human fungal infections are called human mycosis..pptx
GDM (1) (1).pptx small presentation for students
Classroom Observation Tools for Teachers
Complications of Minimal Access Surgery at WLH
Lesson notes of climatology university.
Chinmaya Tiranga quiz Grand Finale.pdf
Weekly quiz Compilation Jan -July 25.pdf
Supply Chain Operations Speaking Notes -ICLT Program
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Microbial disease of the cardiovascular and lymphatic systems
Trump Administration's workforce development strategy
A systematic review of self-coping strategies used by university students to ...
O7-L3 Supply Chain Operations - ICLT Program
Ad

CO3303-1 Lecture 2.ppt

  • 1. Maths and Technologies for Games Quaternions CO3303 Week 1
  • 2. • We have used two methods to store a rotation: Representing Rotations 2. Three Euler/Fixed angles: – X, Y & Z, (or yaw, pitch & roll) – Can be combined in any order – Used in TL-Engine [See Van Verth for more detail]             1 0 0 0 0 0 0 z y x z y x z y x Z Z Z Y Y Y X X X 1. A matrix: – Can just use 3x3 matrix for rotation – Used these in DirectX
  • 3. Converting between Formats • We can create a matrix from fixed angles – Create a rotation matrix for each angle: – E.g. Z rotation matrix of α: • Multiply the matrices together: M = RX*RY*RZ – Different results for different multiplication orders • Can also convert matrix back to fixed angles – See Van Verth or the matrix class in the labs               1 0 0 0 0 1 0 0 0 0 cos sin 0 0 sin cos     Z R
  • 4. Euler Angles – Pros/Cons • Concise storage – just three floats • Euler/Fixed angles seem intuitive – But which order to multiply when forming a matrix? – Different orders in same app can cause problems • Are the rotations world or local rotations? – Depends on order again • Gimbal lock can occur when one angle is 90° – The other angles interfere with each other, result is ambiguous – E.g. causing strange spinning effects when looking straight up or down (you will have seen this problem in some games)
  • 5. Matrices – Pros/Cons • Unambiguous definition of rotation – As compared to Euler angles • 4x4 matrix can also hold position and scale – And totally different things: projection matrix • Used by graphics hardware – Must convert all forms to matrices eventually • But uses 16 floats – Much processing/storage even for simple operations • Can be stored in two ways, by row or by column – APIs (DirectX) and maths texts use different forms
  • 6. Axis-Angle Rotations • Look for other ways to specify rotations… • Can specify any rotation as a rotation axis r (a vector) and an angle θ (a scalar): • Can convert to and from matrices (see Van Verth or matrix class) • Useful way to think about rotation • But operations are generally complex with this form – Including interpolation (see later)
  • 7. Quaternions • Quaternions can be used to represent rotation • A general quaternion takes the form: – We will use these forms interchangeably • We will mostly consider normalised quaternions: • However, several quaternion formulae result in un- normalised quaternions – Often need to renormalise quaternions before reuse ) , , ( where ) , ( or ) , , , ( z y x w z y x w    v v q q 1 where 2 2 2 2     z y x w = examinable
  • 8. Quaternions • A quaternion is a form of axis-angle rotation – When in a normalised form • If we rewrite a quaternion in this form: • Then r and θ form an axis-angle rotation as described before: – r is a unit vector here ) ) 2 / sin( ), 2 / (cos( ) , ( r v q     w
  • 9. Quaternions – Pros/Cons • Why use this more complex variation on angle-axis form? • Because quaternions can easily be: – Combined together – Used to transform points/vectors – Quaternions can be interpolated easily • A feature vital for animation, which is more difficult with matrices • Quaternions only use 4 floats for storage • However, they lack hardware support – So we need to convert them to and from matrices
  • 10. Quaternion Formulae 1 • A quaternion can be converted to a matrix: – A little expensive, can be simplified in code – Transposed from Van Verth book for row-based system (DirectX / math text difference) • Reverse conversion is also possible (see Van Verth) • Quaternions don’t convert easily to Euler angles normalised not is if 1 by result multiply 1 0 0 0 0 2 2 1 2 2 2 2 0 2 2 2 2 1 2 2 0 2 2 2 2 2 2 1 then , ) , , , ( If 2 2 2 2 2 2 2 2 2 2 q M q q z y x w y x wx yz wy xz wx yz z x wz xy wy xz wz xy z y z y x w                               
  • 11. Quaternion Formulae 2 • Quaternions can be added and scaled: – Scaling is used for normalisation • Two quaternions can be multiplied to create a single quaternion performing both rotations: – Same effect as multiplying matrices, order important – Coded efficiently this is faster than matrix multiplication – N.B. Swapped multiplication order from text for row-based system ) , , , ( ) , , , ( ) , , , ( 2 1 2 1 2 1 2 1 2 2 2 2 1 1 1 1 z z y y x x w w z y x w z y x w       ) , , , ( ) , , , ( az ay ax aw z y x w a  ) , ( ) , ( 1 2 2 1 2 1 2 1 v v v v v v v q q 1 2 2 1        w w w w w
  • 12. Quaternion Formulae 3 • Inverse of a quaternion (the rotation in the opposite direction) is simple: – Assumes quaternion is normalised – Much faster than matrix equivalent, which can be complex • We can also represent vectors as quaternions – Just set w = 0: ) , ( 1 v q    w quaternion a as ) , , , 0 ( ) , , ( Vector z y x z y x   p
  • 13. Quaternion Formulae 4 • Rotate a vertex or vector p by a quaternion q=(w,v): – Slower than matrix equivalent – 1st formula reversed for row-based system (2nd remains same) – N.B. The formula in earlier Van Verth edition is incorrect • Derivation of most formulae in Van Verth – As well as further detail pq q p 1 q   ) ( Rotate ) ( 2 ) ( 2 ) 1 2 ( 2 p v v p v p       w w
  • 14. Quaternions: Initial Summary • Quaternions can perform similar operations to matrices – With comparable performance – But need to convert to / from matrices – And can’t store position / scaling • No compelling reason to use them yet • But next week we will see how quaternions compare to matrices for interpolation – And how this is used this for animation