How to plot a sphere using PLOTCUBE command?

1 visualización (últimos 30 días)
GreenEye
GreenEye el 10 de En. de 2021
Respondida: Rohit Pappu el 28 de En. de 2021
I need to make a sphere of cubes, think something like a sphere in Minecraft made from blocks. I'm thinking the function PLOTCUBE on file exchange is perfect for this. I'm not sure how to implement it thought. It would probably have to be a for loop. If anyone has any ideas, it would be much appeciated.

Respuestas (1)

Rohit Pappu
Rohit Pappu el 28 de En. de 2021
A possible solution is as follows
clf;
figure
hold on
tic
% Using spherical coordinates to plot the cubes
for r = linspace(0,1,20) % define the range for radius of sphere
for phi = linspace(0,pi,10) % define the range for phi angle
for theta =linspace(0,2*pi,50) % define the range for theta angle
origin = [(r)*cos(theta)*sin(phi), (r)*sin(theta)*sin(phi), (r)*cos(phi)];
edges = [0.03,0.03,0.03];
plotcube(edges,origin,0.8,[0.5 0.5 0.5]);
end
end
end
toc
hold off
Note - Since it's a nested for loop, it is computationally expensive

Categorías

Más información sobre 2-D and 3-D Plots 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