Monday, February 5, 2018

Find the 3x3 transformation matrix given a set of 3D points using Octave

I have 2 corresponding pair of 3 measured 3D points - one original coordinates (let's call as X) and the other destination or reference coordinates (say Y) . I wanted to find the transformation matrix (say A) that can transform the original coordinates to the destination coordinates.

Octave (an open source software alternative to Matlab. See https://www.gnu.org/software/octave/) has the tools to determine the 3x3 transformation matrix. This post shows how to perform the calculation.

Given the 3 original measured 3D points X:
x1 = (2, -1, 2)
x2 = (-1, 2, 2)
x3 = (2, 2, -1)

And the 3 measured destination 3D points Y:
y1 = (-2, -9, -30)
y2 = (-23, 12, 9)
y3 = (13, 6, -6)

  1. First, write out the transformation and coordinates in the following form

    AX=Y

    where A is the unknown transformation matrix,
    X is a matrix of the original coordinates formed by concatenating the points as column vectors X = [x1, x2, x3]
    Y is a matrix of the destination coordinates formed by concatenating the points as column vectors Y = [y1, y2, y3]
  2. Run Octave. In the command prompt, enter the X matrix values:

    $> X = [2 -1 2; -1 2 2; 2 2 -1]
  3. In the prompt, enter the Y matrix values:

    $> Y = [-2 -23 13; -9 12 6; -30 9 -6]
  4. Now calculate the inverse of X by typing the following into the prompt.

    $> IX = inv(X)
  5. The transformation matrix A can be calculated by simply multiplying the matrix Y with the inverse of X. Type in the following at the prompt:

    $> A = Y * IX
  6. Optional. Use the calculated matrix A and multiply with the original coordinates X and check whether the resultant values matches the measured Y coordinates.

No comments: