# matrix to transform unit cube to space defined by 8 arbitrary points

I asked a question relating to similar to this already, but I think this is a clearer objective of what Im trying to achieve.. or whether its possible at all!

Im trying to find a transformation (matrix ideally) which would transform the 8 points of a 3d unit cube to 8 arbitrary points in space.

The 8 target points have no known structure.

e.g:

My gut feeling is that a matrix is unable to provide this xform since the cube faces vertices can be concave.. but are there any other methods of transformation? Thanks!

-
You can store 8 different transformations, one for each point. But since its not a linear transformation, 1 matrix will not do what you need. – Maik Semder Oct 28 '12 at 21:07
thanks yes, that seems a good idea- I need to establish tri-linear parameters to interpolate to a point within the space.. the best method I have so far is divide the volume into tetrahedra and work from that basis, so maybe I'll establish one xform per tetra and use the tetrahedra that satisfy the solution best – aadster Oct 28 '12 at 21:57
so it appears I actually need 5 transforms if I work with tetrahedra (4 at corners, 1 in centre) I presume I can just create a matrix in the form [AB,AC,AD] where A is the corner vertex? – aadster Oct 28 '12 at 23:05

The transformation is non-linear, so you cannot use a conventional transformation matrix for it.

You could go with trilinear interpolation between all the A0, A1, A2 etc. points. One way to compute it for an arbitrary point P(x,y,z) is:

f(P) = (1-z)*(1-y)*(1-x)*A0
+ (1-z)*(1-y)*  x  *A1
+ (1-z)*  y  *(1-x)*A2
+ (1-z)*  y  *  x  *A3
+   z  *  y  *(1-x)*A4
+   z  *  y  *  x  *A5
+   z  *(1-y)*(1-x)*A6
+   z  *(1-y)*  x  *A7

It can be rewritten as this simpler form:

f(P) = A0 + x*B1 + y*B2 + z*B3 + xy*C1 + yz*C2 + zx*C3 + xyz*D1

With the following precomputed constants:

A0
B1 =  A1-A0
B2 =  A2-A0
B3 =  A6-A0
C1 =  A3-A2-A1+A0
C2 = -A6+A4-A2+A0
C3 =  A7-A6-A1+A0
D1 = -A7+A6+A5-A4-A3+A2+A1-A0

Note that no matter how you perform the computation, you will need to store at least 24 constant floating point values to fully describe the transformation.

-

I have a gut feeling also, that

• The points have to close a convex area
• The points must be the corner points of the intersection of 6 planes.

Then, there may exist a matrix where

[a b c d ],  where (m+-a)x + (n+-b)y + (o+-c)z + (p+-d) == 0
[e f g h ]         (m+-e)x + (n+-f)y + (n+-f)z + (p+-h) == 0
[i j k l ]         (m+-i)x + (n+-j)y + (n+-k)z + (p+-l) == 0
[m n o p ]   are the equations of the 6 planes of the arbitrary shape

Then the matrix that transforms the cube to that shape is the inverse transform of the matrix == M^-1, as the forward matrix represents the transform from a viewing frustum to clip space (==unit cube). (Also we know that the frustum doesn't have to be symmetric, so there is quite a lot of degrees of freedom left...)

-