For one of the current projects, I have a geometry that is currently being built physically by students. The geometry is not too accurate in relation to the 3D model that it is being made from.
I therefore need to adjust the vertices in the geometry but doing so would join the subsets of the .x file into one set and I can not color each triangle a separate color.
My plan is to calculate the transform from a generic triangle to each triangle in the geometry. And then apply the spread of transforms from the generic triangle to the others and thus having a spread of triangles I can adjust individually and still color each triangle individually.
Is there a simple way to calculate this, perhaps even a node or plugin.
sugoku, are you stoned? ah… no… sorry, i got it after reading it the 4th time. you suggest to store all triangles of the source mesh with the unit vectors and then transform them to their destination position by a matrix formed by the destination vectors… thats a quite pragmatic solution, i like it.
the other way i found when using arbitrary triangles, you would have to calculate a face normal with (b-a)x(c-a) to get 12 equations to solve for the matrix:
everything sounds quite interesting but i dont know what sunep wanted and what the matrix-transform is able to do (what you can not do with regular transform). someone wants to explain a bit more or maybe create a patch?
but to explain it a bit, the result would be a usual 4x4 matrix which would transform triangle 1 to triangle 2.
sunep would use it to alter some points of a mesh by hand, and use the matrix to transform the individual subsets of the mesh, instead of using the altered vertics to join a new mesh.
but there is a more general usage of this. say you mark 3 points on mesh and define 3 others somewhere else, then you would get a matrix, which would transform your whole mesh so that the 3 source points match the 3 destination points…
hm, that one is looking more like a complex homography, but still in 2D.
i think solvePnP (or calibrateProjector) is doing a similar stuff but more complicated, because it’s guessing the matrices from 2D points compared with 3D points.
but maybe i didn’t understand cats extensive contribution…
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:
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:
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: