I'm trying to implement an algorithm that from six 2-D matrices of X,Y,Z points store them in a 3D matrix of X,Y,Z points in such a manner that their connectivity is preserved. An example will clarify the problem.
I've to represent with three 3-D matrices
( M3D_X(:,:,:), M3D_Y(:,:,:),M_3D_Z(:,:,:) )
an hexahedral region of space. Of that hexahedral region will be known only its faces, stored in three 2-D matrices
( [face1_x(:,:,:),face1_y(:,:,:),face1_z(:,:,:)], [face2_x.....]....,],...,[...,face6_Z(:,:,:)] )
The only information known about connectivity between faces is that face_i have a side in common with face_j. It isn't given which side is in common. So,how to store the 2-D matrices in the 3-D matrix so that contiguity between faces is preserved ? Just to clarify, the interior of the hexahedral region will be created with 3-D transfinite interpolation.
Example ( with only two faces instead of six):
! []-->matrix ,--> column separator ;--> row separator
! face_i_x= [p11_x, p12_x,..,p1n_x;
....................
pm1_x,..........,pmn_x]
face1_x = [0.0,0.5,1.0;
0.0,0.5,1.0;
0.0,0.5,1.0]
face1_y = [0.0,0.0,0.0;
0.5,0.5,0.5;
1.0,1.0,1.0]
face1_z = [0.0,0.0,0.0;
0.0,0.0,0.0;
0.0,0.0,0.0]
face2_x = [0.0,0.5,1.0;
0.0,0.5,1.0;
0.0,0.5,1.0]
face2_y = [1.0,1.0,1.0;
1.0,1.0,1.0;
1.0,1.0,1.0]
face2_z = [0.0,0.0,0.0;
0.5,0.5,0.5;
1.0,1.0,1.0]
cube3D_x = (:,:,:)
cube3D_y = (:,:,:)
cube3D_z = (:,:,:)
face1 represent the face at z=0 of the unit cube. face2 represents the face at y=1.0 of the unit cube. To retain the simplicity of this example I will not consider face3,..,face6. Now I need to create a 3D matrix to representing the unit cube. I can start like this
cube3D_x(1,:,:)=face1_x
cube3D_y(1,:,:)=face1_y
cube3D_z(1,:,:)=face1_z
but then the second (and subsequent insertion must be handled with special care because
face1 has a side in common with face2 (the edge at y=1.0, z=0.0).
How to insert the second face in the cube ?
For more clarity here is a python script for better visualization of the problem:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
face1x=np.array( [ [0.0,0.4,0.6,1.0] , [0.0,0.4,0.6,1.0] , [0.0,0.4,0.6,1.0],[0.0,0.4,0.6,1.0] ])
face1y=np.array( [ [0.0, 0.0, 0.0, 0.0], [0.3,0.3,0.3,0.3], [0.7,0.7,0.7,0.7],[1.0,1.0,1.0,1.0]])
face1z=np.array( [ [0.0,0.0,0.0,0.0], [0.0,0.0,0.0,0.0], [0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0]] )
face2x=np.array( [ [0.0,0.4,0.6,1.0] , [0.0,0.4,0.6,1.0],[0.0,0.4,0.6,1.0] , [0.0,0.4,0.6,1.0],[0.0,0.4,0.6,1.0] ])
face2y=np.array( [ [0.0,0.0,0.0,0.0], [0.0,0.0,0.0,0.0], [0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0]] )
face2z=np.array( [ [0.0, 0.0, 0.0, 0.0], [0.3,0.3,0.3,0.3],[0.5,0.5,0.5,0.5] ,[0.7,0.7,0.7,0.7],[1.0,1.0,1.0,1.0]])
# because face2 is stored with arbitrary direction of indices, just simulate this randomness with some flipping and rotation
np.flip(face2x)
np.flip(face2y)
np.flip(face2z)
np.rot90(face2x)
np.rot90(face2y)
np.rot90(face2z)
# now plot the two faces
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_wireframe(face1x,face1y,face1z,color='b')
ax.plot_wireframe(face2x,face2y,face2z,color='r')
plt.show()
Also : https://en.wikipedia.org/wiki/Regular_grid I'm not interested in performance. Thank you very much.
----edit--- The same problem can be posed with lines instead of faces and faces instead of 3D volumes.
line1 = [1,2,3]
line2 = [5,4,3]
line3 = [5,6,7]
line4 = [9,8,7]
face= matrix(3,3)
One can start with
face(1,:)= line1
and he obtains
face = [1,2,3 ;
*,*,* ;
*,*,* ]
now if the line2 is inserted like this
face(:,3)=line2
the result will be
face = [1,2,5 ;
*,*,4 ;
*,*,3 ]
when the correct solution is
face(:,3)= reverse(line2)
(because point 3 is in common with line1 and line2 ) to obtain
face = [1,2,3 ;
*,*,4 ;
*,*,5 ]
Hope this makes the problem clearer.