How do I generate n cubes to define a sphere?

8 visualizaciones (últimos 30 días)
Chad
Chad el 29 de Nov. de 2011
Respondida: iiulian marius el 23 de Nov. de 2020
I would like to generate cubes in a sphere. For example I would like to start simple where I can generate a central cube with 26 surrounding cubes that fit in a sphere defined by the size of the cubes. I am not concerned about filling the sphere completely. This would be my first attempt where I have to find the center of the surrounding cubes with respect to the center cube. Once I get my program working where I perform a calculation on the surrounding 26 cubes I would like to extend it to many cubes where I can record the center of each cube. So my program will subtend n cubes surrounding a central cube.
I would like to plot the 27 cubes and record the central (x,y,z) of each cube. I have tried using some examples but they are far move involved than I need. I appreciate the help.
Chad

Respuesta aceptada

John
John el 29 de Nov. de 2011
To create the cubes and visualize them I would start with something like the following:
It has proven useful in the past but requires the use of patches, if you are not familiar with them I suggest looking in the help

Más respuestas (3)

Walter Roberson
Walter Roberson el 30 de Nov. de 2011
The largest cube that will fit in a sphere with radius R will have diagonal 2*R and thus would have outer edges of length 2*R/sqrt(3) . If we assign the center of the sphere to be coordinates (0,0,0) and orient the cube to be perpendicular to the coordinate axes, then the outer cube would extend from -R/sqrt(3) to +R/sqrt(3) in each of the three coordinates.
Divide that (-R/sqrt(3) to +R/sqrt(3)) equally in to 3 planes in each direction to get the total of 27 cubes. That gives bounding planes at -R/sqrt(3), -R/3/sqrt(3), +R/3/sqrt(3) and +R/sqrt(3) and corresponding edge midpoints of -R/2/sqrt(3), 0, and +R/2/sqrt(3), and the complete list of centers then becomes
cc = [-R/2/sqrt(3), 0, +R/2/sqrt(3)];
[Xc, Yc, Zc] = ndgrid(cc, cc, cc);
centers = [Xc(:), Yc(:), Zc(:)];
and for vertices,
ev = [-R/sqrt(3), -R/3/sqrt(3), +R/3/sqrt(3), +R/sqrt(3)];
[Xv, Yv, Zv] = ndgrid(ev, ev, ev);
vertices = [Xv(:), Yv(:), Zv(:)];

Chad
Chad el 30 de Nov. de 2011
Hi Walter..I think is what I am looking for. Is there a clever way to plot the cubes?

iiulian marius
iiulian marius el 23 de Nov. de 2020
ev = [-R/sqrt(3), -R/3/sqrt(3), +R/3/sqrt(3), +R/sqrt(3)];
[Xv, Yv, Zv] = ndgrid(ev, ev, ev);
vertices = [Xv(:), Yv(:), Zv(:)];
ev = [-R/sqrt(3), -R/3/sqrt(3), +R/3/sqrt(3), +R/sqrt(3)];
[Xv, Yv, Zv] = ndgrid(ev, ev, ev);
vertices = [Xv(:), Yv(:), Zv(:)];

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by