I would like to generate a 3D Grid, not for displaying, but to do computations on it, so no draw functions I guess.
I have a simple version of what I am thinking, however, it is terribly slow:
generateMesh[size_, width_, distance_] :=
Image3D@ParallelTable[
If[#1 && #2 || #1 && #3 || #2 && #3, 1, 0] & @@
(MemberQ[Range[0, width - 1], Mod[#, distance]] & /@
{x, y, z}),
{x, 0, size}, {y, 0, size}, {z, 0, size}]
The Image3D
is only to see if it is correct and not part of the speed issue. Even a call to e.g. generateMesh[200, 2, 20]
takes about 30s or more on a laptop. This seems quite a lot for such a simple task.
Does anyone know
- a way to improve performance?
- know if the above code contains any typical don'ts of Mathematica programming? I guess I am evaluating things over and over again, because I am not evaluating the function passed to
Table
, but I do not know how to avoid this.