Take slices of the cube

조회 수: 3 (최근 30일)
george korris
george korris 2022년 4월 2일
댓글: george korris 2022년 4월 3일
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:

답변 (1개)

Image Analyst
Image Analyst 2022년 4월 2일
How about the slice() function?
  댓글 수: 7
Image Analyst
Image Analyst 2022년 4월 3일
I guess there would then be no black squares except along the outside perimeter of the image.
george korris
george korris 2022년 4월 3일
But i have cubes randomly inside my big cube.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Scalar Volume Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by