Assume a list of {x,y,z}
coordinates. The coordinates are arranged in a regular fashion through a fixed raster size (called raster
in the code below). For simplicity I visualized the list by applying Cuboid
while {x,y,z}
is now represented by the center of the cuboid. I found that a quarter of a sphere is a perfect shape to test and applied some boundary conditions to the list to fulfill that purpose. This quarter-sphere now consists of single cuboids with unit dimension (figure under the code below).
For my purpose, the surface of this quarter-sphere is fairly rough. To solve this problem, one could decrease the raster
, but only at the expense of an increase in the total number of cuboids (raster = 1
-> $\approx 10^3$ cuboids, raster = .2
-> $\approx 10^5$ cuboids), which causes higher loading times, less handling ability, and so on.
However, allowing cuboids with non-unity dimension (here defined by cubeDim
) could fix this problem; this would be equivalent to merging several of the smaller cuboids to a single cuboid with larger dimension.
Unfortunately, I do not have a clue how to do that with the results of my code below.
range = 15;
radiusMax = 10;
radiusMin = 6;
raster = 2;
(* -- define sphere volume -- *)
sphereVolume[x_, y_, z_] :=
radiusMin <= Sqrt[x^2 + y^2 + z^2] <= radiusMax;
(* -- table one's (sphereVolume) and zero's (outside of sphereVolume) -- *)
data = Table[
If[sphereVolume[x, y, z], 1, 0], {x, 0, range, raster}, {y, 0,
range, raster}, {z, -range, range, raster}];
(* -- get position of one's, serving as position for cube center (for visualization) -- *)
cubeCenter = Position[data, 1];
cubeDim = 1;
(* -- list of all cubes -- *)
cubeList =
Table[Cuboid[{cubeCenter[[a]] - cubeDim/2,
cubeCenter[[a]] + cubeDim/2}], {a, 1, Length@cubeCenter}];
Graphics3D[cubeList, Boxed -> False]
My Question :
How to enforce Mathematica to find a solution merging some of the cubes? It isn't necessary to find the ultimate best solution, but drastically reducing the number of elements (cuboids) will greatly help me.
Remember that the cubes just serve for visualization. In the end, I want to make a split from {x, y, z}
coordinates (with unit distances) to {x, y, z}
coordinates (representing the center of a cuboid) now linked to the dimension of the particular non-uniform cube.
I hope my question is clear. Just give me a hint, if something is unclear. In addition, if you have a better suggestion for the question title, suggestions are appreciated.
Edit:
I realized the need to be more precise regarding my problem starting point, as two answers (some kind of similar in their approach) have been uploaded. In my example above (the quarter-sphere) I first defined an analytical function. Then I transferred the analytical function into a numerical list by applying Table
. This list or array (if you so will), has to be the starting point.
There is no option for me, to shift this transfer, as the numerical list will undergo a convolution, which is only numerically solvable.
Therefore, could you please be especially focusing on the point that I have to start with either an array of zero’s and one’s or a list of {x, y, z}
-coordinates with a fixed distance dx
, dy
, dz
(being the unrefined meshgrid somehow). Thanks!!
DiscretizeRegion[ ImplicitRegion[{1 <= x^2 + y^2 + z^2 <= 2, x >= 0, y >= 0}, {x, y, z}], MaxCellMeasure -> 10]
, which gives you this. If you want more control, you may want to look atToElementMesh
in theNDSolve`FEM`
package. Unfortunately, I have been unable to force either method to use cubic elements (i.e.HexahedronElement
). $\endgroup$HexahedronElement
is only used for rectangular meshes. $\endgroup$