* @throws jjil.core.Error if some of the edges in t1 are of length zero
*/
public TriangleMap(Triangle t1, Triangle t2) throws jjil.core.Error {
this.p1 = t1.getP1();
this.p2 = t2.getP1();
Vec2 s12, s13, s22, s23;
s12 = new Vec2(this.p1, t1.getP2());
s13 = new Vec2(this.p1, t1.getP3());
s22 = new Vec2(this.p2, t2.getP2());
s23 = new Vec2(this.p2, t2.getP3());
// The matrix transformation is
// A vT = u
// where vT is the original vector (s12 or s13), transposed,
// and u is the transformed vector (s22 or s23).
// The solution to the transformation is
// A = [s22T s23T][s12T s13T]-1 = [s22T s23T] B-1
// Where -1 indicates matrix inversion of the 2x2 matrix (denoted B) formed from
// the transposed vectors s12T and s13T.
// Matrix inversion of a 2x2 matrix is easy.
double detB = s12.getX() * s13.getY() - s13.getX() * s12.getY();
if (detB == 0.0d) {
throw new Error(
Error.PACKAGE.ALGORITHM,
ErrorCodes.PARAMETER_OUT_OF_RANGE,
t1.toString(),
null,
null);
}
double Binv[][] = new double[2][2];
Binv[0][0] = s13.getY() / detB;
Binv[0][1] = -s13.getX() / detB;
Binv[1][0] = -s12.getY() / detB;
Binv[1][1] = s12.getX() / detB;
// finally form A
this.A = new double[2][2];
this.A[0][0] = s22.getX() * Binv[0][0] + s23.getX() * Binv[1][0];
this.A[0][1] = s22.getX() * Binv[0][1] + s23.getX() * Binv[1][1];
this.A[1][0] = s22.getY() * Binv[0][0] + s23.getY() * Binv[1][0];