Basic Math Matrices & Transformations (revised)
Matrices An ordered table of numbers (or sub-tables) columns A{ 3 3 a a a 00 0 20 a a a 0 2 a a a 02 2 22 Rows Product : C BA AB, C a a 00 0 a a 0 b b 00 0 b b 0 a a 00 0 * b * b 00 00 + + a a 0 * b * b 0 0 a a 00 0 * b * b 0 0 + + a a 0 * b * b Identity : I 3 0 0 0 0 0 0
Definition: a c b d Example: Matrix Addition (+) x u y v + a+x c+u b+y d+v 5 2 6 0-2 -7 + 3 3 - Properties:. Closed result is always a matrix 2. Commutative A+B B+A 3. Associative (A+B)+C A+(B+C) 4. Identity A+0 A (null matrix) 5. Inverse A+A - 0 (negated matrix)
Matrix Multiplication (*) Definition: a c b d Example: x u y v * ax+cy au+cv bx+dy bu+dv 5 2 6 0-2 -7 + 5-37 6-46 Properties:. Closed result is always a matrix 2. NOT Commutative A*B! B*A 3. Associative (A*B)*C A*(B*C) 4. Identity A*I A (identity matrix) 5. Inverse A*A - I (difficult to obtain!) Distributive from either side (A+B)C AC + BC C(A+B) CA + CB
Examples: Vector is a special matrix v[x,y,z] row vector, x3 matrix v 2 column vector, 2x matrix
Vector addition: just like adding matrices Column vector a c b d x u y v + a+x c+u b+y d+v Row vector a c b d x u y v + a+x c+u b+y d+v
Matrix*Vector Multiplication: just like multiplying matrices y x v d c b a M 2 Mv v y x d c b a + + dy cx by ax Result is a new column vector Column vector on the right
Matrix*Vector Multiplication(example) 2 v 3 2 5 M 2 Mv v 2 3 2 5 + + 8 7 3*2 2* *2 5*
Matrices as transformations Matrix-vector multiplication creates a new vector. New vector means new location in space. If all points of an object is multiplied by a matrix, then the whole object assumes a new position (and may be new shape and size, too). This is called transformation. v x y y a M c v 2 Mv b d v v 2 x
Matrices as transformations (examples) 0 M 2 Mv v y x Transform 4 points [0,0], [,0],[,],[0,] using the matrix M. y 0 0, 0 0 v 2 v 0, 0 v v 2 v 2 v 2, v 2 v, 0 v v 2
S v v S 2 5 0 S 2 v 5 0 0 3 s x 0 0 s y 0 3 2 Scaling 5*+ 0*2 0*+ 3*2 S - /s x 0 0 /s y 5 6 S * S - I S s x 0 0 0 s y 0 0 0 s z 3D scaling matrix
Example: CT guidance i pixel (column index) NY number of pixels (typically 52) FOVY size of the body captured (in cm) dy FOVY / NY (pixel size, in cm) NX number of pixels (typically 52) FOVX size of the body captured (in cm) 2 0 dx FOVX / NX (pixel size, in cm) th slice thickness (cm or mm) S CT dx 0 0 0 dy 0 0 0 th
Rotation y v 2 R α v v 2 v v 2 R -α α v x
Rotation Matrix u and u _ u cos(α + β) sin(α + β) α β x cos(β) v v(x,y) and v ysin(β) cos(α) cos(β) sin(α) sin(β) sin(α) cos(β) + cos(α) sin(β)
Rotation Matrix u and u _ u cos(α + β) sin(α + β) α β x cos(β) v v(x,y) and v ysin(β) x cos(α) cos(β) sin(α) sin(β) sin(α) cos(β) + cos(α) sin(β) y
Rotation Matrix u and u _ u cos(α + β) sin(α + β) α β x cos(β) v v(x,y) and v ysin(β) x cos(α) cos(β) sin(α) sin(β) sin(α) cos(β) + cos(α) sin(β) y cos(α) x sin(α) y sin(α) x + cos(α) y cos(α) sin(α) sin(α) cos(α) x y _ v R α cos(α) sin(α) sin(α) cos(α) u R α v
Inverse of Rotation Matrix R α cos(α) sin(α) sin(α) cos(α) R - α cos(- α) sin(- α) sin(- α) cos(- α) R - α cos(α) sin(α) -sin(α) cos(α) - R α R - α The proof: R α * R - α I Series of Rotations R (α+β+γ) R α R β R χ
Rotation by α around z axis 3D Rotation Matrices R α cos(α) sin(α) 0 sin(α) cos(α) 0 0 0 v 2 R α v When applied on vector v, it does not change z coordinate. Try it! Rotation around all axes θ v 2 Example: 60, v, 2 Rv 0 R 60 / 2 3 / 2 3 / 2 / 2
Passage from reference system to another p a in F a α Frame a _ t p b in F b p b RSp a + t Frame b () scale, (2) rotate, and (3) translate to go from F a to F b
C-arm fluoroscopy j A pix (i.j,0) ADD L B i Pixel size dx,dy dx 0 0 S 0 dy 0 0 0 B [0,0,-ADD] SAD C S [0,0,SAD] A B + SA pix S
C-arm fluoroscopy i A 2pix (i 2.j 2,0) j A pix (i.j,0) j B2 B 2 R α B L 2 α ADD L B i Pixel size dx,dy dx 0 0 S 0 dy 0 0 0 S 2 R α S A 2 R α (B +S A 2pix ) SAD C B [0,0,-ADD] S [0,0,SAD] A B + SA pix S S2 TARGET L x L 2
Change of reference systems backwards (inverse transform) p b RSp a + t //subtract t p b t RSp a //left multiply by R - R - (p b t) Sp a //left multiply by S- S - R - (p b t) p a Slight problem: mixes translation vector with matrices Solution: make t translation vector appear as a matrix T in multiplications. Then the equations will read as: p b (T(R(Sp a )))
Introduce 4x4 Translation Matrix T 0 0 d x 0 0 d y 0 0 d z 0 0 0 v x y z Padding with (If I padded with 0 then inverse would not exist!) Tv 0 0 d x 0 0 d y 0 0 d z 0 0 0 x y z x+d x y+d y z+d z Problem: rotation and scaling matrices must also be padded, so that we can multiply all 4x4 matrices.
Homogeneous Matrices and Translation Matrix Rotation matrix by α around z axis Translation matrix R cos(a) sin(a) 0 0 α sin(a) cos(a) 0 0 0 0 0 0 0 0 T 0 0 d x 0 0 d y 0 0 d z 0 0 0 Scaling matrix S s x 0 0 0 0 s y 0 0 0 0 s z 0 0 0 0 v x y z Padding all vectors with p b (T(R(Sp a )))
Series of transformations Inverse transformation: Apq //apply A on p A - Ap A - q //mult both sides from left by A - pa - q //because A - AI Series of transformations CBApq //Apply A,B, then C on p (C (B (Ap))) q //use associative property Inverse of series of transformations CBApq //Apply A,B, then C on p A - B - C - qp //multiply by inverse from left forward inverse B A C A - B - p q p C - q
Inverse of coordinate transformations p b TRSp a Multiply from the left by T - T - p b RSp a Multiply from the left by R - R - T - p b Sp a Multiply from the left by S - S - R - T - p b p a
Reference frame transformations b p b p b T*R*S* p a F ab p a p b F ab p a a F ab is often called frame transformation or shortly frame
Series of reference frame transformation Most real systems involve complicated series of frames, where we traverse from frame to frame F ac b F bc c p c p c F bc F ab p a F ac p a F ab a All frames must be known: some of them are measured/calculated during the procedure, some of them are pre-operatively known through calibration.
Example: Robot-Assisted Ultrasound-Guided Liver Surgery LARS ROBOT Biopsy needle JHU 5-DOF needle driving robot Ultrasound System JHU volume visualization and planning display
Example cont d: some frames in the tracked dual-arm robot system Tracker p R F TR F HT F UH p U F HT F TR Handle Robot F UH US Target picked in US
Example: CT-guided Needle Placement with Robot Coordinate s CT Scanner Planning & control computer Robot Patient Surgeon Digital images Patient in the scanner with robot Screen of the surgical planning and control workstation Kidney biopsy Kavoussi & Stoianovici
Example cont d: Frames F R Robot F FR Fiducials p R F F p R F FR F CF p C F CF p C F C CT image
Example: Multi-Joint Serial Robots 4-joint serial robot F 4 p 4 F 3 p 0 p 4 F 34 F 23 F 2 F 0 p 0 F F 2 F 0
e e2 e3 orthonormal base e 2 e 3 v e Let e e 2 e 3 be orthonormal base vectors Let v be an arbitrary vector
Express v with e e 2 e 3 base vectors e 2 e 3 e 2 v v e e v
Express v with e e 2 e 3 base vectors e 2 (e 2 v ) e 2 e 3 e 2 v v e (e v ) e e v v (e v ) e + (e 2 v ) e 2 + (e 3 v ) e 3
Express v v 2 v 3 base with e e 2 e 3 base vectors e 3 v 3 v 2 e 2 v e v (e v ) e + (e 2 v ) e 2 + (e 3 v ) e 3 v 2 (e v 2 ) e + (e 2 v 2 ) e 2 + (e 3 v 2 ) e 3 v 3 (e v 3 ) e + (e 2 v 3 ) e 2 + (e 3 v 3 ) e 3
Express P in both coordinate systems P e 3 v 3 v 2 e 2 v e (Expressed v v 2 v 3 with (e e 2 e 3 ) orthonormal base vectors) v (e v ) e + (e 2 v ) e 2 + (e 3 v ) e 3 v 2 (e v 2 ) e + (e 2 v 2 ) e 2 + (e 3 v 2 ) e 3 v 3 (e v 3 ) e + (e 2 v 3 ) e 2 + (e 3 v 3 ) e 3 Express P in both coordinate systems P r e + s e 2 + te 3 (r, s, t are coordinate values) P x v + yv 2 + zv 3 (x, y, z are coordinate values)
Generalized rotation matrix Replace v, v 2 and v 3 with the long forms we just derived v (e v ) e + (e 2 v ) e 2 + (e 3 v ) e 3 v 2 (e v 2 ) e + (e 2 v 2 ) e 2 + (e 3 v 2 ) e 3 v 3 (e v 3 ) e + (e 2 v 3 ) e 2 + (e 3 v 3 ) e 3 P r e + s e 2 + te 3 (r, s, t are coordinate values) P x v + yv 2 + zv 3 (x, y, z are coordinate values) P x(e v ) e + x(e 2 v ) e 2 + x(e 3 v ) e 3 + y(e v 2 ) e + y(e 2 v 2 ) e 2 + y(e 3 v 2 ) e 3 + z(e v 3 ) e + z(e 2 v 3 ) e 2 + z(e 3 v 3 ) e 3 Group the e, e 2 and e 3 members P x(e v ) e + y(e v 2 ) e +z(e v 3 ) e + x(e 2 v ) e 2 + y(e 2 v 2 ) e 2 + z(e 2 v 3 ) e 2 + x(e 3 v ) e 3 + y(e 3 v 2 ) e 3 +z(e 3 v 3 ) e 3
Generalized rotation matrix Group the scale factors P (x(e v ) + y(e v 2 ) + z(e v 3 )) e + (x(e 2 v ) + y(e 2 v 2 ) + z(e 2 v 3 )) e 2 + (x(e 3 v ) + y(e 3 v 2 ) + z(e 3 v 3 )) e 3 P in (rst) Rearrange to column vector format. r s t x(e v ) + y(e v 2 ) + z(e v 3 ) x(e 2 v ) + y(e 2 v 2 ) + z(e 2 v 3 ) x(e 3 v ) + y(e 3 v 2 ) + z(e 3 v 3 ) Recognize matrix*vector product. r s t (e v ) (e v 2 ) (e v 3 ) (e 2 v ) (e 2 v 2 ) (e 2 v 3 ) (e 3 v ) (e 3 v 2 ) (e 3 v 3 ) x y z P in (xyz)
Generalized rotation matrix Direction cosines R e 2 (e v ) (e v 2 ) (e v 3 ) (e 2 v ) (e 2 v 2 ) (e 2 v 3 ) (e 3 v ) (e 3 v 2 ) (e 3 v 3 ) where ( e v ) cos (e v )cos (α) ( e 2 v ) cos (e 2 v )cos (β) ( e i v j ) cos (e i v j ) cos (β ij ) in special 2D case cos (b) sin (a) α e 2 v β α v e e v
Generalized rotation matrix R (e v ) (e v 2 ) (e v 3 ) (e 2 v ) (e 2 v 2 ) (e 2 v 3 ) (e 3 v ) (e 3 v 2 ) (e 3 v 3 ) e 3 v 3 v 2 e 2 v e