I have a bunch of coplanar points, who sit on plane
P. I want to translate the plane to
Q with the points upon. Here is what I do:
I take three points from
c. Their centroid is denoted by
I pick the local origin as
O = c(a,b,c) and local
x = normalize(Oa); v = normalize(Ob); z = x.crossProduct(v); y = x.crossProduct(z);
I apply the same method to their global coordinates on
Q, which are
O_ = c(d,e,f); x_ = normalize(Od); v_ = normalize(Oe); z_ = x_.crossProduct(v_); y_ = x_.crossproduct(z_);
Then, I use the transformation matrix as follows:
Matrix input = [x,y,z]; Matrix output = [x_,y_,z_]; Matrix T = output.multiply(input.transpose());
After this step, I multiply the coordinates of a point
p that sit in plane
P with matrix
T. Of course, before that, I take the vector difference
p - O.
The result should be the transformed point minus target origin (
q - O_).
Hence, for each
P, I transform
p to its place in
Q, which is denoted by
q using the following computation:
q = T.multiply(p.subtract(O)).add(O_);
But what I get is, the reflection of the points through an imaginary (I don't know which) axis.
Am I missing some step? Is there a wrong computation?