Generate a random parallelepedes

Is there a way to generate random parallepepeds with dimensions x, y, z, based on the script exists in the link: Generate random ellipsoids, which allows to generate random spheres. The purpose of my work is to make a study of a composite material which contains parallepeped reinforcements.

The problem of the script of generating spheres is that when parallelepede or cubes are used, the problem of overlapping between these particles will appear, since here we must check the condition between the two parallepeped bases which is different with the case of spheres.

The dimensions are displayed on the image such as the distance between the vertices of the two bases and the distance between the centers.
Thank you very much for your help.

Hi !

In fact your problem is a problem of “collisions check” (Quite classical in game dev, even if it’s not that simple, specially when you come to 3D)

The “collision check” function for two spheres is quite simple, and for parallelepedes it’s a little bit harder. It you manage to code a collision function for you parallelepedes, your problem is solved, am I right ? :slight_smile:

If so, you can manage to find it on the web. I would advice you to seach for a 3D “edge to plane” collision check (which is quite simple)
As soon as you have it, you just need to set a loop, to check each edge to face collision between the two parallelepipedes (Because if two parallelepipedes are colliding, some edge must collide with some face)
[EDIT] Also, in some (unlikely) cases, a little parrallelepipede could be inside a bigger one, without any edge to face collision. You need to add an extra collision check which would be a “point inside parrallelepipede” check. A loop which would ensure that no point of one parrallelepipede is inside another one :wink: [/EDIT]

This kind of loops are not very fast in Python, and with a lot of meshes it could become quite expensive in term of computation, but if real time is not your goal, in your case in would be a matter of some milliseconds, or at worst hundreds of milliseconds…

See you :slight_smile: ++

According to your questions, I can tell you that it is difficult for me, more, I am not a specialist to program with this code. I need to generate several cases of volume fraction and number of parallelepipeds in a cube. Also I have a python script that works with the Abaqus software (numerical simulation tool), but I do not have the idea to convert it so that it works with Blender.

I tried with the cube model, I modified some parameters as follows:

random scale

min_scale = 0.006
max_scale = 0.006
depth = 0.08

scale_factor … scale down to help fit

scale_factor = 1
domain = 1
only_cubes = True
tries_per_cube = 256

The problem is in the dimension of the cube that does not change or turn.
How to adjust the dimensions of the cube and the distance between two cubes, knowing that the cubes are cuboids.