lundi 3 mai 2021

3D cubes in matlab

This is my code in malab:

clear all
close all
colores = ['b','y','g','y','r','c','k'];

nCubos=6;
cubos=cell(1,nCubos);
cubos{1}(60:140, 70:150, 70:150) =0.6;
cubos{2}(107:177, 151:221, 90:160) =0.6;
cubos{3}(80:150, 160:230, 161:231) =0.6;
cubos{4}(153:183, 193:223, 161:181) =0.6;
cubos{5}(57:97, 160:200, 120:160) =0.6;
cubos{6}(130:180, 132:182, 161:211) =0.6;

cubos{3}=imrotate(cubos{3},40,'crop');

for p=1:nCubos
    color = colores(mod(p,length(colores))+1);
    disp(color)
    [x,y,z] = ind2sub(size(cubos{p}), find(cubos{p}));
    plot3(x,y,z,'color',color,'marker','.')
    pause(0.01)
    hold on;
    axis([0 256 0 256 0 256]);
end
hold off; 

and this is the output:

enter image description here

I would like to create randoms cubes like this every time I execute the program, with differents sizes and positions without overlapping, but with intersect in one face or vertice.

Thanks!!




Aucun commentaire:

Enregistrer un commentaire