Transforming points and vectors - |...

43
1 © 2008 Steve Marschner • Cornell CS4620 Fall 2008 • Lecture 5 Transforming points and vectors Homogeneous coords. let us exclude translation just put 0 rather than 1 in the last place and note that subtracting two points cancels the extra coordinate, resulting in a vector!

Transcript of Transforming points and vectors - |...

1© 2008 Steve Marschner • Cornell CS4620 Fall 2008 • Lecture 5

Transforming points and vectors

• Homogeneous coords. let us exclude translation– just put 0 rather than 1 in the last place

– and note that subtracting two points cancels the extra coordinate, resulting in a vector!

2© 2008 Steve Marschner • Cornell CS4620 Fall 2008 • Lecture 5

Rigid motions (Proper Euclidean space)

• A transform made up of only translation and rotation is a rigid motion or a rigid body transformation

• The linear part is an orthonormal matrix

• Inverse of orthonormal matrix is transpose– so inverse of rigid motion is easy:

3D Rotations

Taesoo Kwon

R=R z R x R y

4

R=Rz R y RxEuler Angles:Do not use if possible

Euler’s Theorem• Euler’s Theorem

Any two independent orthonormal coordinate frames can be related by a sequence of (not more than three) rotations about coordinate axes.

• Gimbal: hardware implementation of Euler angles

5GSCT, KAIST

Euler Angles

Rot(z, )ϕ Rot(x’,θ) Rot(z’,a)

R=

• ZXZ Euler angle1. Rotate along Z-axis

2. Rotate along X-axis of the new frame

3. Rotate along Z-axis of the new frame

Euler angles:XYZ XZY XYX XZXYXZ YZX YXY YZYZXY ZYX ZXZ ZYZ

6GSCT, KAIST

Euler Angles

Rot(z, )ϕ Rot(x’,θ) Rot(z’,a)

R=

• ZXZ Euler angle1. Rotate along Z-axis

2. Rotate along X-axis of the new frame

3. Rotate along Z-axis of the new frame

Euler angles:XYZ XZY XYX XZXYXZ YZX YXY YZYZXY ZYX ZXZ ZYZ

7GSCT, KAIST

Vehicle Orientation: Roll-Pitch-Yaw

• Generally, for vehicles, it is most convenient to rotate in roll, pitc

h, and then yaw

• ZYX Euler angle Rotate about Z-axis (yaw), then about (new) Y-axis (pitch) of body fr

ame, finally about (new) X-axis (roll) of body frame (note: textbook is wrong in describing ZYX Euler angle (pg. 32))

R=Rz(ψ)RY(θ)Rx(ф)

8

“yaw-pitch-roll”

GSCT, KAIST

Gimbal Lock

• One potential problem that Euler angles can suffer from is ‘gimbal lock’

• This results when two axes effectively line up, resulting in a temporary loss of a degree of freedom

• Euler angles have singularities, i.e., it loses DoFs (can’t move in a certain direction) at some configurations

Normal situation.The plane can rotatein any directions

Gimbal lock:two out of the three gimbals are in the same plane, one DoF is lost

9GSCT, KAIST

Gimbal Lock

• One potential problem that Euler angles can suffer from is ‘gimbal lock’

• This results when two axes effectively line up, resulting in a temporary loss of a degree of freedom

• Euler angles have singularities, i.e., it loses DoFs (can’t move in a certain direction) at some configurations

Normal situation.The plane can rotatein any directions

Gimbal lock:two out of the three gimbals are in the same plane, one DoF is lost

10GSCT, KAIST

Axis angle: (angle, axis)

Rotation vector : axis*angle

Quaternion- a compact representation of a 3x3 rotation matrix (can be converted back and forth)- 4D vector (w,x,y,z) having unit length- angle, axis representation- definition : (cos(angle/2), sin(angle/2)*axis)

Axis-angle Representations

X

Y

Z

X

Y

Z '

3D Rotation

• Given two arbitrary orientations of a rigid object,

3D Rotation

• We can always find a fixed axis of rotation and an angle about the axis

v

Euler’s Rotation Theorem

In other words,• Arbitrary 3D rotation equals to one

rotation around an axis• Any 3D rotation leaves one vector

unchanged

The general displacement of a rigid body withone point fixed is a rotation about some axis

Leonhard Euler (1707­1783)

Let's compute the rotation matrix R

θ=30by                degreesaxis=(1,2,3)Rotation about 

Before rotation

Afterrotation

Let's compute the rotation matrix R

axis=(1,2,3)

Rz=(cos(θ) −sin(θ) 0sin (θ) cos(θ) 00 0 1)

Rotation about  by                degreesθ=30

=(√32

−0.5 0

0.5 √32

0

0 0 1)

R=Raz−1Rz Raz

1. We know the rotation matrix about Z­axis 

2. We know how to composite rotations

Where               is the matrix rotates the                          to Z­axisaxis=(1,2,3)Raz

Step 1: rotate the axis so that it is aligned with the Z­axis

Step 2: rotate about the Z­axis

Rz

Raz

Raz−1

Step 3: rotate the Z­axis back to the original axis

rotation axis of  Raz

How to compute

• This is an inefficient way to do this.• A better method will be explained later

a=axis

∥axis∥≈(0.27,0.53, 0.80)

∥v∥=√v⋅v=x2+ y2+z2 v=( x , y , z)

Raz

where

1. Calculate the unit­length rotation axis 

Matlab codes:> axis=[1 2 3]'> a=axis/norm(axis)

axis=(1,2,3)

How to compute

• (This is an inefficient way, but ...)

a=axis

∥axis∥≈(0.27,0.53,0.80)

∥v∥=√v⋅v=x2+ y2+ z2 v=(x , y , z)

Raz

where

1. Let the normalize axis

p a

p=a×(0,0,1)

∥a×(0,0,1)∥

Matlab codes:> p=cross(a,[0;0;1])> p=p/norm(p)

(Axis a to axis z)

2. Calculate vector      that is perpendicular to both      and Z­axis  

p

20

21

How to compute Raz

Raz p

Raz a becomes (0,0,1)

becomes p

Raz ( p×a ) becomes p×(0,0,1)

Raz3. after rotation 

p

a

p×a

`

p

(0,0,1)

p×(0,0,1)

Raz

How to compute Raz3. Then after the rotation 

Raz p

Raz aRaz becomes (0,0,1)

becomes p

Raz ( p×a ) becomes p×(0,0,1)

Raz ( [a ] [ p ] [ p×a ])=(00 [ p ] [ p×(0,0,1)]1 )Therefore, 

Raz=(00 [ p ] [ p×(0,0,1)]1 ) ( [a ] [ p ] [ p×a ] )

−1

Finally,

Matlab codes:> z=[0;0;1]> Raz=[z p cross(p,z)] *inv([a p cross(p,a)])

Test orthonormality of R_az> Raz'*Raz→ identity

> Raz*Raz'→ identity

> Raz(:,1)> Raz(:,2)> Raz(:,1)'*Raz(:,2)> Raz(:,2)'*Raz(:,3)> Raz(:,3)'*Raz(:,1)

All combinations leads to 0

Finally,

Rz

Raz

Raz−1

• The rotation matrix R=Raz−1Rz Raz

> R= [  0.875595  ­0.381753   0.295900; 0.42   0.9043  ­0.076; ­0.23   R= [  0.875595  ­0.381753   0.295900; 0.42   0.9043  ­0.076; ­0.23   0.19   0.9521]0.19   0.9521]> RR =

   0.875595  ­0.381753   0.295900   0.420031   0.904300  ­0.076000  ­0.230000   0.190000   0.952100

> R*R'ans =

   9.9996e­01   6.9406e­05   7.8065e­03   6.9406e­05   9.9996e­01   2.8503e­03   7.8065e­03   2.8503e­03   9.9549e­01

Verity the solution using matlab or octave (a free alternative to matlab)

The resulting matrix R should be similar to this

Orthonormality → ans = Identity

m' means the transpose of m

> eig(R)ans =

   0.86528 + 0.49752i   0.86528 ­ 0.49752i   1.00143 + 0.00000i

> [v,d]=eig(R)v =

   0.68249 + 0.00000i   0.68249 ­ 0.00000i   0.26848 + 0.00000i  ­0.10502 ­ 0.59228i  ­0.10502 + 0.59228i   0.53329 + 0.00000i  ­0.15928 + 0.38341i  ­0.15928 ­ 0.38341i   0.80220 + 0.00000i

D = ...

Eigen values and vectors

Eigen value == 1

Eigen vector : a=

axis∥axis∥

≈(0.27,0.53,0.80)

More efficient solution:

• Use the following Rodrigues' rotation formula– The previous solution is slow because it involves

a matrix inversion (or transpose)

30

Homogeneous coordinates in 3D(Affine transformation)

(v1 x v2 x v3 x ox

v1 y v2 y v3 y o y

v1 z v2 z v3 z oz

0 0 0 1)(

c1

c2

c3

1)=(

v x⋅c+ox

v y⋅c+o y

v z⋅c+oz

1)=(V c+o

1 )X

Y

Z

X

Y

Z

X' Y' Z' O

31

32

Parallel to the axis 

Perpendicular to the axis

33

34

Parallel to the axis 

35

Perpendicular to the axis

36

Note that ||    ||  =  ||         ||

c

 = ||x|| sin(c)

is preserved after rotation

37

Note that ||    ||  =  ||         ||

c

 = ||x|| sin(c)

The above equation is obtained after substituting equations

38

c x=[1 0 0 00 1 0 00 0 1 00 0 0 1

]

x '= f ( x )

c x '=M=[ f (100) f (010) f (

001) o ]

where                 denotes the equation below

where

=uuT=[u xu yu z

] [ux u y u z ]

Let R be the upper­left 3x3 submatrix of      , and   a=[

u xu yuz0

]=[u0 ]

40

41

42

void matrix::fromAxisAngle(AxisAngle4d const & a1) { double c = cos(a1.angle); double s = sin(a1.angle); double t = 1.0 - c; // if axis is not already normalised then uncomment this // double magnitude = Math.sqrt(a1.x*a1.x + a1.y*a1.y + a1.z*a1.z); // if (magnitude==0) throw std::runtime_error(“”); // a1.x /= magnitude; // a1.y /= magnitude; // a1.z /= magnitude; m00 = c + a1.x*a1.x*t; m11 = c + a1.y*a1.y*t; m22 = c + a1.z*a1.z*t; double tmp1 = a1.x*a1.y*t; double tmp2 = a1.z*s; m10 = tmp1 + tmp2; m01 = tmp1 - tmp2; tmp1 = a1.x*a1.z*t; tmp2 = a1.y*s; m20 = tmp1 - tmp2; m02 = tmp1 + tmp2; tmp1 = a1.y*a1.z*t; tmp2 = a1.x*s; m21 = tmp1 + tmp2; m12 = tmp1 - tmp2;}

http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToMatrix/