Borrar filtros
Borrar filtros

Take slices of the cube

6 visualizaciones (últimos 30 días)
george korris
george korris el 2 de Abr. de 2022
Comentada: george korris el 3 de Abr. de 2022
Hi everyone the following code creates random cubes inside a big cube:
clc;
clear all;
%y z coordinates:
vert = [1 1 -1;
-1 1 -1;
-1 1 1;
1 1 1;
-1 -1 1;
1 -1 1;
1 -1 -1;
-1 -1 -1];
%These are the 6 faces of the cube, each is defined by connecting 4 of the
%available vertices:
fac = [1 2 3 4;
4 3 5 6;
6 7 8 5;
1 2 8 7;
6 7 1 4;
2 3 5 8];
% I defined a new cube whose length is 1 and centers at the origin.
vert2 = vert * .05;
fac2 = fac;
patch('Faces',fac,'Vertices',vert,'Facecolor', 'w'); % patch function for the first big cube.
axis([-1, 1, -1, 1, -1, 1]);
axis equal;
hold on;
rng(123); %// Set seed for reproducibility
num_squares = 100; %// Set total number of squares
%// New - to store the coordinates
coords = [];
%// For remembering the colours
colors = [];
%// For each square...
for idx = 1 : num_squares
%// Take the base cube and add an offset to each coordinate
%// Each coordinate will range from [-1,1]
vert_new = bsxfun(@plus, vert2, 2*rand(1,3)-1);
%// New - For the coordinates matrix
coords = cat(3, coords, vert_new);
%// Generate a random colour for each cube
color = rand(1,3);
%// New - Save the colour
colors = cat(1, colors, color);
%// Draw the cube
%patch('Faces', fac, 'Vertices', vert_new, 'FaceColor', color);
patch('Faces', fac, 'Vertices', vert_new);
axis off;
end
%// Post processing
material metal;
alpha('color');
alphamap('rampdown');
view(3);
and gives this :
does anyone know how can i plot slices of the cube ?
like this one:

Respuestas (1)

Image Analyst
Image Analyst el 2 de Abr. de 2022
How about the slice() function?
  7 comentarios
Image Analyst
Image Analyst el 3 de Abr. de 2022
I guess there would then be no black squares except along the outside perimeter of the image.
george korris
george korris el 3 de Abr. de 2022
But i have cubes randomly inside my big cube.

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by