a general linear equation system is of the form A*x=b, where A is NxN square matrix and x and b are vectors of dimension N and * denotes the matrix-vector multiplication. the matrix A and the vector b must be known in order to solve for the vector x.
what we are looking for is the 12 m values of the 4x4 matrix M:
m01 m02 m03 m04
m05 m06 m07 m08
m09 m10 m11 m12
0 0 0 1
so the vector x = (m01, m02, m03, …, m12), and N = 12 here.
now we have to find a matrix A with 12x12 values generated from the source triangle T and a vector b (solution) with 12 values generated from the destination triangle T’. each triangle gives us 12 values, 3 corners ABC + normal n. as we need 12 values for b this sounds good, all of them will probably be in b, but which is where? and how can we get 144 values for A?
this needs some insight into the operation we will perform with the m values later and how the vector-matrix multiplication works:
we know:
M*v = v’
where v is any vector we will transform with the matrix M. let’s have a look how the transformation works for the x value of the result:
m01vx + m02vy + m03vz + m041 = v’x
if we now replace v with a corner of T and v’ with a corner of T’ this is basically equation 1. so the m01…m04 values multiplied with the xyzw values of the source vector are responsible for the x value of the destination vector. this means we can write 4 equations for all the ABCn destination x values that we know:
m01Ax + m02Ay + m03Az + m041 = A’x
m01Bx + m02By + m03Bz + m041 = B’x
m01Cx + m02Cy + m03Cz + m041 = C’x
m01nx + m02ny + m03nz + m040 = n’x
which is the same as:
Ax Ay Az 1 m01 A’x
Bx By Bz 1 * m02 = B’x
Cx Cy Cz 1 m03 C’x
nx ny nz 0 m04 n’x
with these 4 equations we can already solve for m01…m04. And as you can guess, we can do exactly the same for m05…m08 with the y and m09…m12 with z values giving us 12 equations. we can now solve the 3 4x4 systems or write all together into one big 12x12 system which would look like this:
im am not sure which is faster with the solver we have in vvvv. have a look in the patch:
triangle_map.zip (10.4 kB)