1 Motivation (Horn87) Assume correspondence has been determined… • Registration of 3D Shapes n min Rpi b qi R ,b 2 i 1 Any other better solutions for this least-square problem? 2 Exercise • Configuration A • Configuration B – p1 = (3,0,0) – p2 = (0,3,0) – p3 = (0,0,3) – q1 = (3,3,-3) – q2 = (3,0,0) – q3 = (6,0,-3) Find the rotation and translation that takes configuration A to configuration B 3 Solution 3 3 6 3 0 0 R 0 3 0 d d d 3 0 0 3 0 3 0 0 3 4 1 3 d 1 1 0 2 1 3 This is a badly chosen example, where the three points are linearly independent. If this is not so (such as three coplanar points), this simple approach cannot be used. 3 0 0 3 3 3 0 0 3 3 6 3 0 3 0 0 0 R 0 3 0 3 0 0 0 0 0 3 3 0 3 3 3 3 0 3 0 0 0 1 R 1 0 0 0 1 0 4 Recap in CG Course (link) • • • • • New algebra defined (addition, multiplication) Length; unit quaternion as rotation Perform rotations Converting to/from rotation matrices slerp Rot(nˆ, ) q cos 2 sin 2 nˆ x qxq* ... (q02 q q ) x 2q0 q x 2q (q x) x pxp* x qxq* q pxp* q* (qp) x(qp)* sin (1 t ) sin t s(t ) q r sin sin cos q0 r0 q1r1 q2 r2 q3r3 q r 5 History • Quaternions were introduced by Irish mathematician Sir William Rowan Hamilton in 1843. Hamilton was looking for ways of extending complex numbers to higher spatial dimensions. He could not do so for 3 dimensions, but 4 dimensions produce quaternions. • According to the story Hamilton told, on October 16, he was out walking along the Royal Canal in Dublin with his wife when the solution in the form of the equation suddenly occurred to him; Hamilton then promptly carved this equation into the side of the nearby 6 Brougham Bridge Definitions1 Addition Multiplication 7 Definitions2 Complex conjugate Norm (of quaternion) pq p q 8 Alternative Formulation A quaternion can be conveniently thought of as either: • A vector with four components; • A scalar plus a vector with three components; or • A complex number with three different “imaginary” parts 9 Notation: we use to denote quaternion Treat quaternion as a vector in R4 Product in Matrix Form (Horn) R : Expand first quaternion r0 rx ry r r0 rz x R ry rz r0 rz ry rx RRT r rI RT R R R * rz r0 ry T rx ,R ry rx r0 rz “R is orthogonal”! Expand second quaternion : R Note the matrices are different! T rx ry r0 rz rz r0 ry rx rz ry rx r0 This is the “matrix way” to compute quaternion product 10 Details R* RT r r0 , rx , ry , rz r0 r x R ry rz rx r0 rz ry ry rz r0 rx r * r0 , rx , ry , rz rz r0 ry T rx R ry rx r0 rz rx r0 rz ry ry rz r0 rx (rx ) (ry ) ( rz ) r0 r0 (r ) r r ( r ) ( r ) x 0 z y x R* (ry ) ( rz ) r0 (rx ) ry ( r ) ( r ) ( r ) r y x 0 z rz rz ry rx r0 rx r0 rz ry ry rz r0 rx rz ry rx r0 11 This is new! Dot Product of Quaternions Def: 4D vector viewpoint p.9 pq p q pq r Q p r Q p T r pT Q T r pT Q *r p T rq * p rq * 12 Unit Quaternion as Rotation1 Observations: (why Lq(v) is a rotation…) 1. Length preserved after operation 2. If v is along q, it is left unchanged. [Horn] dot product and triple product preserved … 13 Unit Quaternion as Rotation2 Lq is linear over R3 Lq(v) = Lq(n+a) = Lq(n) + Lq(a) = Lq(n) + a v u n a q v=Lp(u) , w=Lq(v) w= Lq(v)=qvq*=q(pup*)q*=(qp)u(qp)*=Lqp(u) 14 Application: Data Registration Find the most appropriate rotation R and translation b Iterative (least square) solution or Closed form solution 15 Convert global coordinates to local coordinate (from centroid) 1 n 1 n centroidp pi , q qi n i 1 n i 1 pi pi p ; qi qi q 1 n pi pi p pi np pi n pi 0 i 1 i 1 i 1 i 1 n i 1 Similarly, n n n n n q 0 i 1 i 16 v w v wv w v v 2v w w w v 2 v w w 2 Objective function (minimization) 2 2 First, determine the rotation R, then the optimal translation by: Optimal rotation R: 2 17 Convert to quaternion: This correspond to R and R in p.8 is symmetric, with real eigenvalues l1, l2, l3, l4 and corresponding orthogonal unit eigenvectors v1, v2, v3, v4 in R4 18 Simplified to: maxqT Mq q Represent q in eigen basis q q 1v1 2 v2 3v3 4 v4 1v1 2 v2 3v3 4 v4 12 22 32 42 q is rotation q 1 12 22 32 42 1 Therefore, qT Mq l112 l2 22 l3 32 l4 42 l112 l1 22 l1 32 l1 42 l1 maximumoccurs at : 1 1, 2 3 4 0 q v1 l1: largest eigenvalue The optimum rotation is the eigenvector with largest eigenvalue. (It is already normalize). 19 Details T Pi Qi is symmetric p1 p2 p3 0 0 q1 q2 q3 p q 0 p p 0 q q 1 3 2 1 3 2 T Q Pi i p2 q2 q3 p3 0 p1 0 q1 p p p 0 q q q 0 2 1 2 1 3 3 p2 q3 p3q2 p3q1 p1q3 p1q1 p2 q2 p3q3 pq pq p1q1 p2 q2 p3q3 p1q2 p2 q1 3 2 2 3 T Pi Qi p3q1 p1q3 p1q2 p2 q1 p1q1 p2 q2 p3q3 p1q3 p3q1 p3q2 p2 q3 p2 q1 p1q2 p2 q1 p1q2 p1q3 p3q1 p3q2 p2 q3 p1q1 p2 q2 p3q3 20 The Real Exercise • Configuration A • Configuration B – p1 = (3,0,0) – p2 = (0,3,0) – p3 = (3,3,0) – q1 = (1,4,1) – q2 = (1,1,4) – q3 = (1,4,4) Find the rotation and translation that takes configuration A to configuration B 21 Quaternion in SVL 22