How do I generate n cubes to define a sphere?
8 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
John
2011-11-29
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
0 个评论
更多回答(3 个)
Walter Roberson
2011-11-30
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(:)];
0 个评论
iiulian marius
2020-11-23
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(:)];
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!