Matrix algebra, transformations

```CS I400/B659:
Intelligent Robotics
Transformations and Matrix Algebra
Agenda
• Principles, Ch. 3.5-8
Rigid Objects
Biological systems, virtual
characters
Articulated Robot
q2
q1
• Robot: usually a rigid
articulated structure
relative to reference
frames
• A configuration specifies
the placement of those
frames
Rigid Transformation in 2D
workspace
Frame T0
robot
ty
reference direction
q
reference point
tx
• Robot R0R2 given in reference frame T0
• Located at configuration q = (tx,ty,q) with q 
[0,2p)
Rigid Transformation in 2D
workspace
Frame T0
robot
P
reference direction
P
ty
q
reference point
tx
• Robot R0R2 given in reference frame T0
• Located at configuration q = (tx,ty,q) with q  [0,2p)
• Point P on the robot (e.g., a camera) has coordinates
0 in frame T0.
• What are the coordinates of P in the workspace?
Rigid Transformation in 2D
• Robot at configuration q = (tx,ty,q) with q  [0,2p)
• Point P on the robot (e.g., a camera) has coordinates
0 in frame T0.
• What are the coordinates of P in the workspace?
• Think of 2 steps: 1) rotating about the origin point by
angle q, then 2) translating the reference point to (tx,ty)
Rotations in 2D
-sin q
cos q
q
cos q
sin q
cos
−sin
• X axis of T0 gets coords  =
, Y axis gets  =
sin
cos
Rotations in 2D
-sin q
cos q
cos q
q
sin q
• X axis of T0 gets coords  =
cos
−sin
, Y axis gets  =
sin
cos
px
py
⋅
⋅

•  gets rotated to coords   +

Rotations in 2D
-sin q
cos q
cos q
q
sin q
• X axis of T0 gets coords  =
cos
−sin
, Y axis gets  =
sin
cos
pxcos q -pysin q
px
py
⋅
⋅

•  gets rotated to coords   +

pxsin q +
pycos q
Dot product
• For any P=(px,py) rotated by any q, we have the new coordinates
cos  −  sin
sin  +  cos
• We can express each element as a dot product:

cos
cos  −  sin  =
⋅
− sin

sin
sin  +  cos  =
⋅
cos
• Definition:  =  ⋅  = x1 y1 + x2 y2
• In 3D,  =  ⋅  = x1 y1 + x2 y2 + 3 3
• Key properties:
• Symmetric
• 0 only if  and  are perpendicular (orthogonal)
•
= ⋅
Properties of the dot product
•
•
•
•
In 2D:  ⋅  = x1 y1 + x2 y2
In 3D:  ⋅  = x1 y1 + x2 y2 + 3 3
In n-D:  ⋅  = =1
Key properties:
• Symmetric
• 0 only if  and  are perpendicular (orthogonal)
•
= ⋅
Properties of the dot product
•
•
•
•
In 2D:  ⋅  = x1 y1 + x2 y2
In 3D:  ⋅  = x1 y1 + x2 y2 + 3 3
In n-D:  ⋅  = =1
Key properties:
• Symmetric
• 0 only if  and  are perpendicular (orthogonal)
•
= ⋅

⋅
If  is a unit vector (  = 1)
then  ⋅  is the length of the
projection of  onto .
Properties of the dot product
•
•
•
•
In 2D:  ⋅  = x1 y1 + x2 y2
In 3D:  ⋅  = x1 y1 + x2 y2 + 3 3
In n-D:  ⋅  = =1
Key properties:
• Symmetric
• 0 only if  and  are perpendicular (orthogonal)
•
= ⋅

If  and  are unit vectors with
inner angle  then  ⋅ =cos

cos
Matrix-vector multiplication
• For any P=(px,py) rotated by any q, we have the new
coordinates
cos  −  sin
sin  +  cos
• We can express this as a matrix-vector product:
cos  −  sin
cos  − sin
=
sin  +  cos
sin  cos
Matrix-vector multiplication
• For any P=(px,py) rotated by any q, we have the new
coordinates
cos  −  sin
sin  +  cos
• We can express this as a matrix-vector product:
cos  −  sin
cos  − sin
=
sin  +  cos
sin  cos
• Or,  =  for A a 2x2 table of numbers
• Each entry of  is the dot product between the
corresponding row of A and
Matrix-vector multiplication
• For any P=(px,py) rotated by any q, we have the new
coordinates
cos  −  sin
sin  +  cos
• We can express this as a matrix-vector product:
cos  −  sin
cos  − sin
=
sin  +  cos
sin  cos
• Or,  =  for A a 2x2 table of numbers
• Each entry of  is the dot product between the corresponding
row of A and
Matrix-vector multiplication
• For any P=(px,py) rotated by any q, we have the new
coordinates
cos  −  sin
sin  +  cos
• We can express this as a matrix-vector product:
cos  −  sin
cos  − sin
=
sin  +  cos
sin  cos
• Or,  =  for A a 2x2 table of numbers
• Each entry of  is the dot product between the corresponding
row of A and
Matrix-vector product
examples
•
1 0 5.1
?
=
0 1 −7.3
?
•
3 0
2
?
=
1 −1 −7
?
3
• 1
0
0 0 2
?
−1 0 −7 = ?
0 5 −3
?
3
• 1
5
0 −1 2
?
−1 0 −7 = ?
0
5 −3
?
General equations
•  =
1,1 ⋯ 1, 1
1
⋱
⋮
⋮
• ⋮ = ⋮
,1 ⋯ ,

• A has dimensions m x n,  has m entries,  has n entries
•  = =1 ,  for each i=1,…,m
Matrix-vector product
examples
•
1 0
0 2
•
4
0
−3 = ?
1
10

=?

•

=?
Multiple rotations
cos  − sin
sin  cos
• We know that the new coordinates of a point  rotated by 1
is given by  = (1 )
• What if we rotate again by 2 ? What are the new coordinates
?
• Define the 2D rotation matrix   =
Multiple rotations
cos  − sin
sin  cos
• We know that the new coordinates of a point  rotated by 1
is given by  = (1 )
• What if we rotate again by 2 ? What are the new coordinates
?
•  = (2 )
• Define the 2D rotation matrix   =
Multiple rotations
cos  − sin
sin  cos
We know that the new coordinates of a point  rotated by 1
is given by  = (1 )
What if we rotate again by 2 ? What are the new coordinates
?
= (2 )
= (2 )( 1 )
• Define the 2D rotation matrix   =
•
•
•
•
Multiple rotations
cos  − sin
sin  cos
We know that the new coordinates of a point  rotated by 1
is given by  = (1 )
What if we rotate again by 2 ? What are the new coordinates
?
= (2 )
= (2 )( 1 )
• Define the 2D rotation matrix   =
•
•
•
•
Is it possible to define matrix-matrix multiplication so that
=  2  1 ?
Matrix-matrix multiplication
•  =  2  1  so  2  1 must be 2x2
? ?

•
=
? ?

ℎ
Matrix-matrix multiplication
•  =  2  1  so  2  1 must be 2x2
Entry (1,1)
Row 1
? ?

•
=
? ?

Column 1

ℎ
Matrix-matrix multiplication
•  =  2  1  so  2  1 must be 2x2
Entry (1,2)
+ ℎ
•
?
Row 1

?
=

?
Column 2

ℎ
Matrix-matrix multiplication
•  =  2  1  so  2  1 must be 2x2
Column 1
+ ℎ
•
?
Entry (2,1)
+ ℎ

=

?

Row 2

ℎ
Matrix-matrix multiplication
•  =  2  1  so  2  1 must be 2x2
Column 2
+ ℎ
•
+ ℎ
+ ℎ

=

?
Entry (2,2)

Row 2

ℎ
Matrix-matrix multiplication
•  =  2  1  so  2  1 must be 2x2
+
•
+
+ ℎ

=
+ ℎ

ℎ
Matrix-matrix multiplication
•  =  2  1  so  2  1 must be 2x2
+
•
+
+ ℎ

=
+ ℎ

+
• Verify that
+

ℎ
+ ℎ

⋅  =
+ ℎ

⋅

⋅
ℎ
Rotation matrix-matrix
multiplication
•  =  2  1  so  2  1 must be 2x2
+
•
+
+ ℎ

=
+ ℎ

cos 2

•
=
sin 2

cos 1
•
=
sin 1
ℎ
−sin 2
cos 2
−sin 1
cos 1

ℎ
Rotation matrix-matrix
multiplication
•  =  2  1  so  2  1 must be 2x2
•
+
+
+ ℎ

=
+ ℎ

ℎ
cos 2 −sin 2

=
sin 2 cos 2

cos 1 −sin 1
•
=
sin 1 cos 1
ℎ
•  +  =  + ℎ = cos 2 cos 1 − sin 2 sin 1 = cos(1 + 2 )
•  + ℎ = − +  = − cos 2 sin 1 − sin 2 cos 1 =
− sin(1 + 2 )
•
Rotation matrix-matrix
multiplication
•  =  2  1  so  2  1 must be 2x2
•
•
•
•
•
•
+
+
+ ℎ

=
+ ℎ

ℎ
cos 2 −sin 2

=
sin 2 cos 2

cos 1 −sin 1
=
sin 1 cos 1
ℎ
+  =  + ℎ = cos 2 cos 1 − sin 2 sin 1 = cos(1 + 2 )
+ ℎ = − +  = − cos 2 sin 1 − sin 2 cos 1 =
− sin(1 + 2 )
So,     =   +
General definition
• If A and B are m x p and p x n matrices, respectively, then the
matrix-matrix product is given by the m x n matrix C with
entries

, =
, ,
=1
Other Fun Facts
• An nxn identity matrix  has 1’s on its diagonals and 0s
everywhere else
•  =  for all vectors
•  =  for all nxm matrices
•  =  for all mxn matrices
• If A and B are square matrices such that  =  = , then B
is called the inverse of A (and A is the inverse of B)
• Not all matrices are invertible
• The transpose of a matrix mxn matrix  is the nxm matrix
formed swapping its rows and columns. It is denoted  .
• i.e.,
•

,
= ,
=
Consequence: rotation inverse
• Since  2  1 =  1 + 2 …
•    − =   −  =  0 =  =
matrix)
1 0
(the identity
0 1
• But  − =
• …so a rotation matrix’s inverse is its transpose.
Rigid Transformation in 2D
• q = (tx,ty,q) with q  [0,2p)
• Robot R0R2 given in reference frame T0
• What’s the new robot Rq?
{Tq(x,y) | (x,y)  R0}
• Define rigid transformation Tq(x,y) : R2 R2
Tq(x,y) =
cos θ -sin θ
sin θ cos θ
2D rotation matrix
x
y
+
tx
ty
Affine translation
Note: transforming points vs
directional quantities
• Rigid transform q = (tx,ty,q)
• A point with coordinates (x,y) in T0 undergoes
rotation and affine translation
Tq(x,y) =
cos θ -sin θ
sin θ cos θ
x
y
+
tx
ty
• Directional quantities (e.g., velocity, force) are
not affected by the affine translation!
Rq(vx,vy) =
cos θ -sin θ
sin θ cos θ
vx
vy
Next Lecture
• Optional: A Mathematical Introduction to Robotic
Manipulation, Ch. 2.1-3
• http://www.cds.caltech.edu/~murray/mlswiki/?title=First_edition
```