放射分布 縦と横は  xy とxzで

 




このコードでは、angle変数を計算して、正弦と余弦を使ってxおよびz座標を計算しています。ここで、sphere_radius * 2を使用して、球体の間隔を調整することができます。






https://drive.google.com/file/d/13RqAkuNesZ0MIGKfaStNJc2-hibaqlBi/view?usp=share_link






import bpy

# コレクションを作成

collection_name = "放射 xz分布  球体"

if collection_name not in bpy.data.collections:

    sphere_collection = bpy.data.collections.new(collection_name)

    bpy.context.scene.collection.children.link(sphere_collection)

else:

    sphere_collection = bpy.data.collections[collection_name]




import bpy

import math

import mathutils


# 格子点の方向数

grid_num = 12


# 球体の半径

sphere_radius = 1.0


# マテリアルを作成

mat = bpy.data.materials.new(name="SphereMaterial")

mat.diffuse_color = (0.40, 0.7, 0.5, 0.3)


# 格子点に球体を配置  3以上 3だと密

for i in range(grid_num):

    for j in range(grid_num):

        angle = 2 * math.pi * j / grid_num

        x = math.cos(angle) * i * sphere_radius * 6

        z = math.sin(angle) * i * sphere_radius * 6

        loc = mathutils.Vector((x, 0, z))

        bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, location=loc)

        obj = bpy.context.active_object

        obj.name = f"Sphere_{i}_{j}"

        obj.data.materials.append(mat)






# xy 平面用 放射



import bpy

# コレクションを作成

collection_name = "放射 xy分布  球体"

if collection_name not in bpy.data.collections:

    sphere_collection = bpy.data.collections.new(collection_name)

    bpy.context.scene.collection.children.link(sphere_collection)

else:

    sphere_collection = bpy.data.collections[collection_name]





import bpy

import math

import mathutils


# 格子点の方向数

grid_num = 12


# 球体の半径

sphere_radius = 1.0


# マテリアルを作成

mat = bpy.data.materials.new(name="SphereMaterial")

mat.diffuse_color = (0.40, 0.7, 0.5, 0.3)


# 格子点に球体を配置  3以上 3だと密

for i in range(grid_num):

    for j in range(grid_num):

        angle = 2 * math.pi * j / grid_num

        x = math.cos(angle) * i * sphere_radius * 6

        y = math.sin(angle) * i * sphere_radius * 6

        loc = mathutils.Vector((x, y, 0))

        bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, location=loc)

        obj = bpy.context.active_object

        obj.name = f"Sphere_{i}_{j}"

        obj.data.materials.append(mat)





このブログの人気の投稿

基本の   線路レール

原型 球体36 xy 横 正方形 60x60 平面分布

原型 球体36 xz 縦 正方形 60x60 平面分布