
%% // generate all the coordinates of each cube firstĭstep = MainCubeSide / nCubeOnSide %// step size for small cube vertices
#FOR MATLAB PATCH#
HMainCube = patch(MainCube) %// patch function for the first big cube. MainCube.Vertices = vert *(2/MainCubeSide) %// because the cube as defined above has already a side=2 NCubesTotal = nCubeOnSide^3 %// total number of small cube NCubeOnSide = 5 %// number of small cube in one "row/column" of the main cube MainCubeSide = 2 %// dimension of the side of the main cube %These are the 6 faces of the cube, each is defined by connecting 4 of the available vertices:įac = %These are the different 8 vertices of the cube, each is defined by its 3 x y z coordinates:
#FOR MATLAB CODE#
The main difference with the old code is that this time the step change of each coordinate set is controlled (function of x,y,z coordinates of the small cube) instead of being random. Same principle, we build a big cube, then a small one in the corner, then we repeat the small cube building with a small offset until we are full. I hope this is clear, I would appreciate any help in constructing this neighborhood matrix.

This is just an explanation to clarify the idea, it doesn't need to be implemented the same way. Where offset may be seen as the distance between the center of a cube and any of its faces. X axis neighbor to the left of C (.5 -offset. X axis neighbor to the right of C (.5 +offset. Then, this cube will have 6 neighbor cubes (positioned directly beside it) with 2 neighbors per axis. Let the cube position be (.5.5.5) which we may think of as the center of the cube. Consider having a cube C anywhere inside the big cube.
#FOR MATLAB HOW TO#
Patch('Faces', fac, 'Vertices', vert_new, 'FaceColor', color,'EdgeColor', 'none') īut I'm getting a result like the one in the following picture,Ĭan anyone please tell me how to solve this problem and build the 3D matrix (or any other easier way to represent the neighbors of every cube )?ĮDIT: To elaborate more on the small cube neighbor issue. %// Generate a random colour for each cube %// Take the base cube and add an offset to each coordinate Num_squares = 1000 %// Set total number of squares Rng(123) %// Set seed for reproducibility Patch('Faces', fac2, 'Vertices', vert2, 'FaceColor', 'r', 'EdgeColor', 'none') Patch('Faces',fac,'Vertices',vert,'Facecolor', 'w') % patch function for the first big cube. % I defined a new cube whose length is 1 and centers at the origin.

%These are the 6 faces of the cube, each is defined by connecting 4 of the %These are the different 8 vertices of the cube, each is defined by its 3 x
#FOR MATLAB TRIAL#
This is my trial (I added the if else in the for loop), clf

I've tried to adjust the code in the linked question to fill the cube in an organized way. I want to make two modifications to the code,ġ- fill the big cube with small cubes in an organized way not randomly.Ģ- adjust the 3D matrix to represent how the small cubes are neighbors to each other. Please take a look at the question link that I provided to see the code. I've obtained a code by rayryeng ( Building a hollow cube and filing it with small cubes in MATLAB) to fill many small cubes randomly inside the big one and build a 3D matrix, where every slice of the matrix (depth) represents one of the small cubes and the rows and columns of every slice (8 rows and 3 columns) represent the x y z coordinates of the vertices of every small cube. Is there an easier way to identify the neighbors? Also, if there is a direct neighbor at another depth layer (same x, y coordinates but different z coordinate, eg, the front and back neighbors) it should be indicated. I think to be able to access every small cube and move to near ones we need to represent the small cubes in a matrix (maybe 3D), where if a small cube has a neighbor cube x to its right, then in the matrix, x will appear in the column next to the current column of the small cube.
#FOR MATLAB SERIES#
I think we have 6 neighbors, because we have 6 different faces of the cube.īy knowing the nearest cube at every direction, a path through the cubes can be defined as a series of steps (eg, right, left, left, top, right, front). Then I want to find a way to access these cubes and make paths through them, i.e if cube x is currently accessed, there should be a way to know what is its right, left, top, bottom, front, and back closest neighbors (closest neighbors= the cubes directly beside the current cube). I have built a hollow cube in MATLAB, I want to completely fill its volume with small cubes.
