I have a set of points $N = \{n_1, n_2, ...\}$ on a plane $z = 0$.
And I have another set of points $M = \{m_1, m_2, ...\}$ on plane $ax + by + cz + d = 0$.
$|N| = |M|$
$\forall n_i, n_j \in N$ and $\forall m_i, m_j \in M$, $d(n_i, n_j) = d(m_i, m_j)$
where $d(i,j)$ denotes the euclidean distance between $i$ and $j$.
I want to rotate the point set $N$ in 3-D, such that $\forall n_i \in N$ and $\forall m_i \in M$, $n_i = m_i$.
First, I use three points from $M$, namely $m_i, m_j, m_k$ to find $a, b, c, d$.
$\vec{PQ} = m_j - m_i$
$\vec{PR} = m_k - m_i$
$\vec{abc} = \vec{PQ} \times \vec{PR}$
$d = \vec{m_i} \cdot \vec{abc}$
Then I rotate all the points in $N$.
New coordinates of points $N$ are on $ax+by+cz = 0$ plane. But still, they are in a different plane in 3-D space.
How can I do the proper rotation? I also want to use $d$ component of the plane and make $M$ and $N$ identical.
As you can see in the image, there is a point cluster on the right. This cluster needs to be a part of the cluster on the left. I think I have to shift the points. But how?
Here are the results of another trial:
coordinates on z=0 estimated coordinates actual coordinates
(-436.31, -270.11, 0.00) (40.06, -460.13, 223.60) (987.20, 968.48, 31.88)
(-451.92, -243.67, 0.00) (62.38, -448.82, 241.41) (966.37, 972.10, 9.61)
(-38.95, -50.98, 0.00) (-11.96, -61.74, 12.67) (873.16, 533.53, 91.34)
(-404.89, -228.80, 0.00) (49.82, -410.18, 213.43) (960.88, 924.93, 22.94)
(-434.90, -246.23, 0.00) (53.25, -440.94, 229.13) (970.11, 958.16, 18.91)
(-185.93, -64.57, 0.00) (46.30, -157.20, 109.01) (866.53, 668.09, 31.03)
(207.76, 51.25, 0.00) (-63.82, 159.58, -127.48) (826.81, 276.60, 147.47)
(-136.68, -124.92, 0.00) (-10.76, -175.15, 59.10) (915.75, 648.40, 88.10)
(-400.62, -203.17, 0.00) (62.73, -387.99, 217.49) (942.80, 911.10, 10.37)
(-430.38, -244.84, 0.00) (52.02, -437.27, 226.43) (969.61, 953.65, 20.22)
(575.78, -92.01, 0.00) (-312.24, 262.21, -416.82) (971.80, 9.06, 399.19)
(-465.18, -267.26, 0.00) (54.70, -474.63, 244.03) (982.02, 993.08, 16.90)
(-126.75, -134.57, 0.00) (-20.80, -176.83, 49.73) (923.85, 643.45, 98.18)
(300.67, 15.86, 0.00) (-126.09, 186.09, -200.32) (862.85, 208.75, 210.59)
(-450.28, -245.68, 0.00) (60.48, -449.42, 239.75) (968.01, 971.45, 11.51)
(587.99, -108.94, 0.00) (-327.52, 256.24, -429.73) (985.43, 4.95, 414.46)
(160.43, -56.50, 0.00) (-104.85, 49.32, -124.52) (899.52, 360.38, 186.76)
(-146.45, -150.19, 0.00) (-20.98, -200.24, 58.89) (932.95, 666.88, 97.93)
(-117.88, -189.20, 0.00) (-56.39, -213.73, 28.86) (964.40, 657.03, 133.32)
(568.87, -109.73, 0.00) (-319.38, 244.58, -416.93) (983.86, 22.07, 406.06)
(-153.17, -15.13, 0.00) (60.15, -100.22, 100.13) (834.40, 619.94, 18.11)
(-461.96, -245.70, 0.00) (65.73, -456.18, 247.69) (966.74, 981.76, 6.12)
(-76.37, -185.94, 0.00) (-73.18, -187.21, 1.50) (966.69, 619.25, 150.68)
Edit:
Both answers are great. But terminology does not match with mine. Please post an answer that shows the steps that I need to apply $\forall n_i \in N$
Edit2: Here is my Java code:
double[] rotate(double[] point, double[] currentEquation, double[] targetEquation)
{
double[] currentNormal = new double[]{currentEquation[0], currentEquation[1], currentEquation[2]};
double[] targetNormal = new double[]{targetEquation[0], targetEquation[1], targetEquation[2]};
targetNormal = normalize(targetNormal);
double angle = angleBetween(currentNormal, targetNormal);
double[] axis = cross(targetNormal, currentNormal);
double[][] R = getRotationMatrix(axis, angle);
return rotated;
}
double[][] getRotationMatrix(double[] axis, double angle)
{
axis = normalize(axis);
double cA = (float)Math.cos(angle);
double sA = (float)Math.sin(angle);
Matrix I = Matrix.identity(3, 3);
Matrix a = new Matrix(axis, 3);
Matrix aT = a.transpose();
Matrix a2 = a.times(aT);
double[][] B =
{
{0, axis[2], -1*axis[1]},
{-1*axis[2], 0, axis[0]},
{axis[1], -1*axis[0], 0}
};
Matrix A = new Matrix(B);
Matrix R = I.minus(a2);
R = R.times(cA);
R = R.plus(a2);
R = R.plus(A.times(sA));
return R.getArray();
}