Compute rotation matrix from fitting a plane with its own coordinate system

256 Views Asked by At

I'm trying to find rotation matrix for a plane from given 4 points $X_1 ... X_4$ that form a square. These points are fixed on a rigid square that can take any position in world coordinate system. I have only 3D coordinates (in world CS) $X_1 ... X_4$ of these points.

enter image description here

The algorithm that I am aware of is following:

  1. From each point subtract centroid
  2. Calculate SVD
  3. Find normal as 3rd column of matrix $U$

It allows to compute a plane that fits that 4 points and a normal for that plane.

In my case, I need to compute rotation matrix (from plane coordinate system to world coordinate system).

The plane/local (more exactly, that rigid square) coordinate system is defined as:

  • X axis goes in the same direction as vector from $X_1$ to $X_2$
  • Y axis goes in the same direction as vector from $X_3$ to $X_2$
  • Z axis goes "up", as in right-handed coordinate system
  • origin is located at the centroid

Now, having $X_1 ... X_4$ and $U$, how can I compute $R$ that will transform any point from plane (local) coordinate system to world coordinate system?