Spheres

Spheres generated by python script. Spheres do not intersects.



I wanted something for the particle system that force the object to not intersect.
can you programm something for the user?

I am currently busy with other things

First image close view…


Added to the spheres physics…


Nice! Does the script just work with spheres or could it be done with other objects?

Script works with sphere objects. It was the easiest way how to calculate intersection between objects. I need to add some changes to this script. Script is not finished…

The first you need to create five materials with name - M1, M2, M3, M4, M5

Here are code:

import math, random

x1 = []
y1 = []
z1 = []
r1 = []


#x1.append(random.random()* 2)
#y1.append(random.random())#* 2)
#z1.append(random.random()* 2)
#r1.append(random.uniform(0.01, 0.5))


x1.append(4)
y1.append(0.2)#* 2)
z1.append(1.8)
r1.append(0.1)


x = 2 #random.random() * 2
y = 0.5 #random.random()# * 2
z = 3.4 #random.random() * 2
r = 0.01 #random.uniform(0.01, 0.5)
 
a = 1


rand_list = ["M1","M2","M3","M4","M5"]


color = "M1"


add_sphere = bpy.ops.mesh.primitive_uv_sphere_add
add_sphere(segments=16, ring_count=16, size=(r), view_align=False, enter_editmode=False, location=(x,y,z), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
bpy.ops.object.shade_smooth()
bpy.context.object.name = "Sphere_" + "0" + "_0"
color = rand_list[random.randint(0,4)]
bpy.data.objects[bpy.context.object.name].active_material = bpy.data.materials[color]
#add_sphere(segments=16, ring_count=16, size=(0.9), view_align=False, enter_editmode=False, location=(x1[0],y1[0],z1[0]), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
###################################
# change spheres count - 2000
for i in range(0,2000,1):
    for j in range(0,len(x1),1):
        if x >= x1[j] and y >= y1[j] and z >= z1[j]:
            d = math.pow(x - x1[j], 2) + math.pow(y - y1[j], 2) + math.pow(z - z1[j], 2)
        if x < x1[j] and y >= y1[j] and z >= z1[j]:
            d = math.pow(x1[j] - x, 2) + math.pow(y - y1[j], 2) + math.pow(z - z1[j], 2)
        if x >= x1[j] and y < y1[j] and z >= z1[j]:
            d = math.pow(x - x1[j], 2) + math.pow(y1[j] - y, 2) + math.pow(z - z1[j], 2)
        if x >= x1[j] and y >= y1[j] and z < z1[j]:
            d = math.pow(x - x1[j], 2) + math.pow(y - y1[j], 2) + math.pow(z1[j] - z, 2)
        if x < x1[j] and y < y1[j] and z >= z1[j]:
            d = math.pow(x1[j] - x, 2) + math.pow(y1[j] - y, 2) + math.pow(z - z1[j], 2)
        if x >= x1[j] and y < y1[j] and z < z1[j]:
            d = math.pow(x - x1[j], 2) + math.pow(y1[j] - y, 2) + math.pow(z1[j] - z, 2)
        if x < x1[j] and y >= y1[j] and z < z1[j]:
            d = math.pow(x1[j] - x, 2) + math.pow(y - y1[j], 2) + math.pow(z1[j] - z, 2)
        if x < x1[j] and y < y1[j] and z < z1[j]:
            d = math.pow(x1[j] - x, 2) + math.pow(y1[j] - y, 2) + math.pow(z1[j] - z, 2)
        print(d)
        if math.pow(r + r1[j], 2) >= d:
            print("intersect")
            a = 0
        else:
            print("not intersect")
    if x - r >= 1 and x + r <= 5:
        if y - r >= 0 and y + r <= 1:
            if z - r >= 1 and z + r <= 5:
                if a == 1:
                    add_sphere(segments=16, ring_count=16, size=(r), view_align=False, enter_editmode=False, location=(x,y,z), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
                    bpy.ops.object.shade_smooth()
                    bpy.context.object.name = "Sphere_" + "{}".format(i) + "_{}".format(j)
                    color = rand_list[random.randint(0,4)]
                    #print("Color = " + color)
                    bpy.data.objects[bpy.context.object.name].active_material = bpy.data.materials[color]
                    x1.append(x)
                    y1.append(y)
                    z1.append(z)
                    r1.append(r)
#    if i <= 300:
#        r = random.uniform(0.45, 0.5)
#        r = 0.9
#    elif i > 300 and i <= 900:
#        r = random.uniform(0.2, 0.449)
#        r = 0.6
#    elif i > 900 and i <= 2000:
#        r = random.uniform(0.1, 0.199)
#        r = 0.3
#    elif i > 2000:
#        r = random.uniform(0.01, 0.099)
#        r = 0.1    
    a = 1
    x = random.random() * 5
    y = random.random() # * 5 
    z = random.random() * 5
    ###################################
    # change sphere radius
    r = random.uniform(0.01, 0.5)

Finish!!!


great!!
usefull. it is like circles definition - same solution for 3d spheres!
cool

Really enjoy the finished product

Thanks nikitron and Galileo90!

There are another way how to use this script…