# Error in plane transformation

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 P, say a, b, c. Their centroid is denoted by c(a,b,c).

I pick the local origin as O = c(a,b,c) and local XYZ as:

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 d, e, f.

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 in 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?

I don't know if this is a typo in your question or the actual mistake:

x = normalize(Oa);
v = normalize(Ob);
z = a.crossProduct(b);
y = x.crossProduct(z);


For one you don't seem to be using v at all, but your z looks wrong to me. Did you mean the following?

z = normalize(Oa.crossProduct(Ob));


Note the Oa and Ob instead of a and b. The difference is the preserved perpendicularity of z on the plane P if P is moved away from the origin. I guess you wanted to do that through p.subtract(O) but that doesn't suffice.

Also note that I normalized z. This will result in orthonormal XYZ on both planes P and Q and means that scale is preserved. If the triangles abc and def are not similar (i.e. one is stretched) then T(P) = Q but T(a) != d. Don't normalize anything if you want to preserve stretching.

• Yes, it was a typo. I corrected it. You suggest that I don't normalize the vector don't you? – padawan Jul 11 '14 at 23:15
• It depends on what you want to achieve. T(P) = Q only, or that and T(abc) = def. – Jonas Bötel Jul 12 '14 at 1:30