2023年5月11日木曜日

20230512 球体2つ  16 x 32 = 512

 





配布 blenderzionad


配布 20230512 球体表面ランダム 002 球体2つ.blend

https://drive.google.com/file/d/1SfV7Lc8CL5PY6Y53iCTjwgQCo7ZMIhO9/view?usp=share_link



2回 実行して 2つの球体 回転させただけ
















import bpy

import math


z_axis = (0, 0, 1)

z_rotation_speed = 0.2  # 1秒間に回転する角度

z_rotation_speed_rad = math.radians(z_rotation_speed)  # ラジアンに変換

z_rotation_duration = 360 / z_rotation_speed  # 1回転するのにかかる時間(秒)



import bpy

import random


# 球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, location=(0, 0, 0))


# マテリアルを作成

materials = []

for i in range(32):

    mat = bpy.data.materials.new(name=f"Material{i}")

    mat.diffuse_color = (random.random(), random.random(), random.random(), 1.0)

    materials.append(mat)


# マテリアルをランダムに割り当てる

obj = bpy.context.active_object

for face in obj.data.polygons:

    face.material_index = random.randint(0, 31)


# オブジェクトにマテリアルを割り当てる

for i in range(32):

    obj.data.materials.append(materials[i])



# アニメーションを作成

obj = bpy.context.active_object

animation_data = obj.animation_data_create()

animation = bpy.data.actions.new(name="RotationAction")

animation_data.action = animation


z_rotation_angle = 0

for i in range(10):

    z_rotation_angle += 360  # 1周分回転する

    z_rotation_time = i * z_rotation_duration  # 回転にかかる時間

    obj.rotation_mode = 'XYZ'

    obj.rotation_euler.z = math.radians(z_rotation_angle)

    obj.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time, index=2)

    obj.rotation_euler.z = math.radians(z_rotation_angle + z_rotation_speed)

    obj.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time + 1, index=2)





2023年5月10日水曜日

20230511 bbb 球体 回転 球体表面 3つの球体

保存すると回転 開始しない



import bpy

import math


zion_kaiten = 0.2  # 回転速度(秒あたりの度数)


# 大きな球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=1, location=(0, 0, 0))

sphere = bpy.context.object


# 大きな球体のマテリアルにアルファブレンドを設定

sphere.data.materials.append(bpy.data.materials.new(name="SphereMaterial"))

sphere.data.materials[0].use_nodes = True

nodes = sphere.data.materials[0].node_tree.nodes

nodes["Principled BSDF"].inputs["Alpha"].default_value = 0.1


# 小さな球体の頂点を作成し、色を設定

vertices = []

colors = [(0, 0, 1, 1), (1, 0, 0, 1), (0, 1, 0, 1)]  # 青、赤、緑


angle = 2 * math.pi / 3  # 120度をラジアンに変換


for i in range(3):

    x = math.cos(i * angle)

    y = math.sin(i * angle)

    z = 0

    

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=(x, y, z))

    vertex = bpy.context.object

    

    # 小さな球体の色を設定

    vertex.data.materials.append(bpy.data.materials.new(name="VertexMaterial"))

    vertex.data.materials[0].diffuse_color = colors[i]

    

    vertices.append(vertex)


# アニメーションのための設定

rotation_angle = 0

rotation_speed = math.radians(zion_kaiten)  # ラジアンに変換


def rotate_objects(scene):

    global rotation_angle


    # 大きな球体と小さな球体をアクティブにする

    bpy.context.view_layer.objects.active = sphere

    sphere.select_set(True)

    for vertex in vertices:

        bpy.context.view_layer.objects.active = vertex

        vertex.select_set(True)

    

    # オブジェクトをZ軸周りに回転する

    bpy.ops.transform.rotate(value=rotation_speed, orient_axis='Z')


    rotation_angle += math.degrees(rotation_speed)


# アニメーションを実行する

bpy.app.handlers.frame_change_pre.append(rotate_objects)


# トーラスを作成

bpy.ops.mesh.primitive_torus_add(

    align='WORLD',

    location=(0, 0, 0),

    rotation=(0, 0, 0),

    major_radius=1,

    minor_radius=0.05

)

torus = bpy.context.object


# トーラスのアニメーションのための設定

torus_rotation_angle = 0

torus_rotation_speed = math.radians(zion_kaiten)  # ラジアンに変換


def rotate_torus(scene):

    global torus_rotation_angle


    bpy.context.view










#原型 色なし


import bpy

import math


zion_kaiten = 0.2  # Rotation speed in degrees per second


# Create the sphere

bpy.ops.mesh.primitive_uv_sphere_add(radius=1, location=(0, 0, 0))

sphere = bpy.context.object


# Create the vertices of the equilateral triangle

vertices = []

angle = 2 * math.pi / 3  # 120 degrees in radians


for i in range(3):

    x = math.cos(i * angle)

    y = math.sin(i * angle)

    z = 0

    

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=(x, y, z))

    vertex = bpy.context.object

    vertices.append(vertex)


# Set up rotation animation

rotation_angle = 0

rotation_speed = math.radians(zion_kaiten)  # Convert to radians per second


def rotate_z_axis(scene):

    global rotation_angle


    # Activate the sphere and the vertices

    bpy.context.view_layer.objects.active = sphere

    sphere.select_set(True)

    for vertex in vertices:

        bpy.context.view_layer.objects.active = vertex

        vertex.select_set(True)

    

    # Rotate the objects around the z-axis

    bpy.ops.transform.rotate(value=rotation_speed, orient_axis='Z')


    rotation_angle += math.degrees(rotation_speed)


# Run the animation

bpy.app.handlers.frame_change_pre.append(rotate_z_axis)









#aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa



import bpy
import math

zion_kaiten = 0.2  # Rotation speed in degrees per second

# Create the sphere
bpy.ops.mesh.primitive_uv_sphere_add(radius=1, location=(0, 0, 0))
sphere = bpy.context.object

# Set alpha blending for the large sphere
sphere.data.materials.append(bpy.data.materials.new(name="SphereMaterial"))
sphere.data.materials[0].use_nodes = True
nodes = sphere.data.materials[0].node_tree.nodes
nodes["Principled BSDF"].inputs["Alpha"].default_value = 0.1

# Create the vertices of the equilateral triangle and color the small spheres
vertices = []
colors = [(0, 0, 1, 1), (1, 0, 0, 1), (0, 1, 0, 1)]  # Blue, Red, Green

angle = 2 * math.pi / 3  # 120 degrees in radians

for i in range(3):
    x = math.cos(i * angle)
    y = math.sin(i * angle)
    z = 0
    
    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=(x, y, z))
    vertex = bpy.context.object
    
    # Set color for the small sphere
    vertex.data.materials.append(bpy.data.materials.new(name="VertexMaterial"))
    vertex.data.materials[0].diffuse_color = colors[i]
    
    vertices.append(vertex)

# Set up rotation animation
rotation_angle = 0
rotation_speed = math.radians(zion_kaiten)  # Convert to radians per second

def rotate_z_axis(scene):
    global rotation_angle

    # Activate the sphere and the vertices
    bpy.context.view_layer.objects.active = sphere
    sphere.select_set(True)
    for vertex in vertices:
        bpy.context.view_layer.objects.active = vertex
        vertex.select_set(True)
    
    # Rotate the objects around the z-axis
    bpy.ops.transform.rotate(value=rotation_speed, orient_axis='Z')

    rotation_angle += math.degrees(rotation_speed)

# Run the animation
bpy.app.handlers.frame_change_pre.append(rotate_z_axis)





あああああああああああああああああああああああああああああ





z=0 に 000を中心とする半径1のトーラス

マイナー半径0.05 を作成し 追加し


これも 大きい球体に追随させる








import bpy

import math


zion_kaiten = 0.2  # Rotation speed in degrees per second


# Create the sphere

bpy.ops.mesh.primitive_uv_sphere_add(radius=1, location=(0, 0, 0))

sphere = bpy.context.object


# Set alpha blending for the large sphere

sphere.data.materials.append(bpy.data.materials.new(name="SphereMaterial"))

sphere.data.materials[0].use_nodes = True

nodes = sphere.data.materials[0].node_tree.nodes

nodes["Principled BSDF"].inputs["Alpha"].default_value = 0.1


# Create the vertices of the equilateral triangle and color the small spheres

vertices = []

colors = [(0, 0, 1, 1), (1, 0, 0, 1), (0, 1, 0, 1)]  # Blue, Red, Green


angle = 2 * math.pi / 3  # 120 degrees in radians


for i in range(3):

    x = math.cos(i * angle)

    y = math.sin(i * angle)

    z = 0

    

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=(x, y, z))

    vertex = bpy.context.object

    

    # Set color for the small sphere

    vertex.data.materials.append(bpy.data.materials.new(name="VertexMaterial"))

    vertex.data.materials[0].diffuse_color = colors[i]

    

    vertices.append(vertex)


# Set up rotation animation for the spheres

rotation_angle = 0

rotation_speed = math.radians(zion_kaiten)  # Convert to radians per second


def rotate_z_axis(scene):

    global rotation_angle


    # Activate the sphere and the vertices

    bpy.context.view_layer.objects.active = sphere

    sphere.select_set(True)

    for vertex in vertices:

        bpy.context.view_layer.objects.active = vertex

        vertex.select_set(True)

    

    # Rotate the objects around the z-axis

    bpy.ops.transform.rotate(value=rotation_speed, orient_axis='Z')


    rotation_angle += math.degrees(rotation_speed)


# Run the animation for the spheres

bpy.app.handlers.frame_change_pre.append(rotate_z_axis)


# Create the torus

bpy.ops.mesh.primitive_torus_add(

    align='WORLD',

    location=(0, 0, 0),

    rotation=(0, 0, 0),

    major_radius=1,

    minor_radius=0.05

)

torus = bpy.context.object


# Set up rotation animation for the torus

def rotate_torus(scene):

    global rotation_angle


    # Activate the torus

    bpy.context.view_layer.objects.active = torus

    torus.select_set(True)

    

    # Rotate the torus around the z-axis

    bpy.ops.transform.rotate(value=rotation_speed, orient_axis='Z')


# Run the animation for the torus

bpy.app.handlers.frame_change_pre.append(rotate_torus)


っっっっっっっっっっっっっっっっっっっっっっっっっっっz


import bpy


# カメラの位置を変更する

bpy.data.objects['Camera'].location = (0, 0, 20)

# ライトの位置を変更する

bpy.data.objects['Light'].location = (0, 0, 30)




# 小さな球体 独立 z軸回転


import bpy

import math


zion_kaiten = 0.2  # Rotation speed in degrees per second


# Create the sphere

bpy.ops.mesh.primitive_uv_sphere_add(radius=1, location=(0, 0, 0))

sphere = bpy.context.object


# Set alpha blending for the large sphere

sphere.data.materials.append(bpy.data.materials.new(name="SphereMaterial"))

sphere.data.materials[0].use_nodes = True

nodes = sphere.data.materials[0].node_tree.nodes

nodes["Principled BSDF"].inputs["Alpha"].default_value = 0.1


# Create the vertices of the equilateral triangle and color the small spheres

vertices = []

colors = [(0, 0, 1, 1), (1, 0, 0, 1), (0, 1, 0, 1)]  # Blue, Red, Green


angle = 2 * math.pi / 3  # 120 degrees in radians


for i in range(3):

    x = math.cos(i * angle)

    y = math.sin(i * angle)

    z = 0

    

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=(x, y, z))

    vertex = bpy.context.object

    

    # Set color for the small sphere

    vertex.data.materials.append(bpy.data.materials.new(name="VertexMaterial"))

    vertex.data.materials[0].diffuse_color = colors[i]

    

    vertices.append(vertex)


# Set up rotation animation for the small spheres

rotation_angles = [0, 120, 240]

rotation_speed = math.radians(zion_kaiten)  # Convert to radians per second


def rotate_spheres(scene):

    global rotation_angles


    for i, vertex in enumerate(vertices):

        bpy.context.view_layer.objects.active = vertex

        vertex.select_set(True)

        

        bpy.ops.transform.rotate(value=rotation_speed, orient_axis='Z', center_override=(0, 0, 0))

        

        rotation_angles[i] += math.degrees(rotation_speed)


# Run the animation for the small spheres

bpy.app.handlers.frame_change_pre.append(rotate_spheres)


# Set up rotation animation for the torus

torus_rotation_angle = 0

torus_rotation_speed = math.radians(zion_kaiten)  # Convert to radians per second


def rotate_torus(scene):

    global torus_rotation_angle


    bpy.context.view_layer.objects.active = torus

    torus.select_set(True)


    bpy.ops.transform.rotate(value=torus_rotation_speed, orient_axis='Z', center_override=(0, 0, 0))


    torus_rotation_angle += math.degrees(torus_rotation_speed)


# Create the torus

bpy.ops.mesh.primitive_torus_add(

    align='WORLD',

    location=(0, 0, 0),

    rotation=(0, 0, 0),

    major_radius=1,

    minor_radius=0.05

)

torus = bpy.context.object


# Run the animation for the torus

bpy.app.handlers.frame_change_pre.append(rotate_torus)





20230511 球体表面502分割

 

import bpy

import math


z_axis = (0, 0, 1)

z_rotation_speed = 0.1  # 1秒間に回転する角度

z_rotation_speed_rad = math.radians(z_rotation_speed)  # ラジアンに変換

z_rotation_duration = 360 / z_rotation_speed  # 1回転するのにかかる時間(秒)



# 大きい球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, location=(0, 0, 0))

large_sphere = bpy.context.active_object


# 大きい球体にマテリアルを割り当てる

material = bpy.data.materials.new(name="Material0")

material.diffuse_color = (1.0, 1.0, 1.0, 1.0)  # 不透明

material.alpha = 0.1  # 透明度

large_sphere.data.materials.append(material)



# 小さい球体を作成

for i in range(3):

    x = math.cos(math.radians(120*i)) * 1

    y = math.sin(math.radians(120*i)) * 1

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, enter_editmode=False, location=(x, y, 0))


# マテリアルを作成
materials = []
for i in range(4):
    if i == 0:
        mat = bpy.data.materials.new(name="Red")
        mat.diffuse_color = (1.0, 0.0, 0.0, 1.0)
    elif i == 1:
        mat = bpy.data.materials.new(name="Green")
        mat.diffuse_color = (0.0, 1.0, 0.0, 1.0)
    elif i == 2:
        mat = bpy.data.materials.new(name="Blue")
        mat.diffuse_color = (0.0, 0.0, 1.0, 1.0)
    else:
        mat = bpy.data.materials.new(name="White")
        mat.diffuse_color = (0.7, 0.7, 0.7, 1.0)
    materials.append(mat)

# マテリアルをランダムに割り当てる
obj = bpy.context.active_object
for face in obj.data.polygons:
    if face.center[0] == 0:
        if face.material_index == 0:
            face.material_index = 1
        elif face.material_index == 1:
            face.material_index = 2
        elif face.material_index == 2:
            face.material_index = 3
        else:
            face.material_index = 0
    else:
        face.material_index = 3



# 作成した小さい球体を選択する

bpy.ops.object.select_all(action='DESELECT')

for obj in bpy.data.objects:

    if obj.name.startswith("SmallSphere"):

        obj.select_set(True)

        bpy.context.view_layer.objects.active = obj


# アニメーションを作成

animation_data = large_sphere.animation_data_create()

animation = bpy.data.actions.new(name="RotationAction")

animation_data.action = animation


z_rotation_angle = 0


for i in range(10):

    z_rotation_angle += 360  # 1周分回転する

    z_rotation_time = i * z_rotation_duration  # 回転にかかる時間


    large_sphere.rotation_mode = 'XYZ'

    large_sphere.rotation_euler.z = math.radians(z_rotation_angle)

    large_sphere.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time, index=2)

    large_sphere.rotation_euler.z = math.radians(z_rotation_angle + z_rotation_speed)

    large_sphere.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time + 1, index=2)


    for obj in bpy.context.selected_objects:

        if obj != large_sphere:

            obj.rotation_mode = 'XYZ'

            obj.rotation_euler.z = math.radians(z_rotation_angle)

            obj.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time, index=2)

            obj.rotation_euler.z = math.radians(z_rotation_angle + z_rotation_speed)

            obj.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time + 1, index=2)












import bpy

import math


z_axis = (0, 0, 1)

z_rotation_speed = 2  # 1秒間に回転する角度

z_rotation_speed_rad = math.radians(z_rotation_speed)  # ラジアンに変換

z_rotation_duration = 360 / z_rotation_speed  # 1回転するのにかかる時間(秒)


# 球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(location=(0, 0, 0))


# アニメーションを作成

obj = bpy.context.active_object

animation_data = obj.animation_data_create()

animation = bpy.data.actions.new(name="RotationAction")

animation_data.action = animation


z_rotation_angle = 0

for i in range(10):

    z_rotation_angle += 360  # 1周分回転する

    z_rotation_time = i * z_rotation_duration  # 回転にかかる時間

    obj.rotation_mode = 'XYZ'

    obj.rotation_euler.z = math.radians(z_rotation_angle)

    obj.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time, index=2)

    obj.rotation_euler.z = math.radians(z_rotation_angle + z_rotation_speed)

    obj.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time + 1, index=2)












色色





import bpy

import math


z_axis = (0, 0, 1)

z_rotation_speed = 0.2  # 1秒間に回転する角度

z_rotation_speed_rad = math.radians(z_rotation_speed)  # ラジアンに変換

z_rotation_duration = 360 / z_rotation_speed  # 1回転するのにかかる時間(秒)



import bpy

import random


# 球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=1, enter_editmode=False, location=(0, 0, 0))


# マテリアルを作成

materials = []

for i in range(32):

    mat = bpy.data.materials.new(name=f"Material{i}")

    mat.diffuse_color = (random.random(), random.random(), random.random(), 1.0)

    materials.append(mat)


# マテリアルをランダムに割り当てる

obj = bpy.context.active_object

for face in obj.data.polygons:

    face.material_index = random.randint(0, 31)


# オブジェクトにマテリアルを割り当てる

for i in range(32):

    obj.data.materials.append(materials[i])



# アニメーションを作成

obj = bpy.context.active_object

animation_data = obj.animation_data_create()

animation = bpy.data.actions.new(name="RotationAction")

animation_data.action = animation


z_rotation_angle = 0

for i in range(10):

    z_rotation_angle += 360  # 1周分回転する

    z_rotation_time = i * z_rotation_duration  # 回転にかかる時間

    obj.rotation_mode = 'XYZ'

    obj.rotation_euler.z = math.radians(z_rotation_angle)

    obj.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time, index=2)

    obj.rotation_euler.z = math.radians(z_rotation_angle + z_rotation_speed)

    obj.keyframe_insert(data_path="rotation_euler", frame=z_rotation_time + 1, index=2)














ああああああああああああああああああ





あああああああああああああああああああああああああああああああああ





2023年5月8日月曜日

20230508 mon 球体ポイント追加

 球体 ポイント



import bpy

import mathutils


# 半径0.1の球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1)


# オブジェクト名を設定

bpy.context.object.name = "root3_ball"


# 球体を各x座標に配置

for x in range(-10, 10):

    # 球体を複製して新しいオブジェクトを作成

    bpy.ops.object.duplicate(linked=False)

    new_obj = bpy.context.object

    

    # 新しいオブジェクトのオブジェクト名を設定

    new_obj.name = "x_ball_{0}".format(x)

    

    # 新しいオブジェクトを移動するベクトルを作成

    translate_vec = mathutils.Vector((x, (3**(0.5)), 0))

    

    # 新しいオブジェクトを移動

    new_obj.location = translate_vec




import bpy

import mathutils


# 半径0.1の球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1)


# オブジェクト名を設定

bpy.context.object.name = "root3_ball"


# 球体を各x座標に配置

for x in range(-10, 10):

    # 球体を複製して新しいオブジェクトを作成

    bpy.ops.object.duplicate(linked=False)

    new_obj = bpy.context.object

    

    # 新しいオブジェクトのオブジェクト名を設定

    new_obj.name = "x_ball_{0}".format(x)

    

    # 新しいオブジェクトを移動するベクトルを作成

    translate_vec = mathutils.Vector((x, -(3**(0.5)), 0))

    

    # 新しいオブジェクトを移動

    new_obj.location = translate_vec




2023年5月1日月曜日

20230502 ビデオ会議の やっと利用

 


20230422 sat ビデオ会議の構造 test版 半径√3へ 修正へ

4月 22, 2023

https://2023na2022.blogspot.com/2023/04/20230422-sat.html



20230422 bbb 半径2に修正

4月 22, 2023

https://2023na2022.blogspot.com/2023/04/20230422-bbb.html





こっちは 

ミンコフスキー大先生の時空図 対応版

赤い 過去光円錐 底面 半径 √3
明るい Green の 過去光円錐 底面 半径 2




配布ファイル blenderzionad


配布 20230502 過去光円錐底面 001  元 20230422  正三角形 6つで正六角形 001 遠近法モード
https://drive.google.com/file/d/1El4iOV_qh7G-0Vhj4u_rdx3LCXP4ac5E/view?usp=share_link





# kaizou正方形 √2変更 000 中心 円錐頂点 square_object.location = (0, - math.sqrt(2), 0)


import bpy

import math


# Side length of square

a = 2 * math.sqrt(2)


# Create mesh data and object

mesh_data = bpy.data.meshes.new("Square")

square_object = bpy.data.objects.new("Square", mesh_data)


# Create vertices of square

vertices = [(a/2, 0, a/2), (-a/2, 0, a/2), (-a/2, 0, -a/2), (a/2, 0, -a/2)]


# Create faces of square

faces = [(0, 1, 2, 3)]


# Assign vertices and faces to mesh data

mesh_data.from_pydata(vertices, [], faces)

mesh_data.update()


# Move square to center

square_object.location = (0, - math.sqrt(2)


, 0)


# Link square to scene

bpy.context.scene.collection.objects.link(square_object)




aaaaaaaaaaaaaaaaaaaaaaa



# obj_name = "half_sphere"




import bpy


import bmesh


from mathutils import Vector, Matrix


import math




zion_name ="半球 r=2 segmentes"






# 半径2の球体を作成 segments=180, ring_count=180


bpy.ops.mesh.primitive_uv_sphere_add(radius=2.0, enter_editmode=False, location=(0,0,0), segments=180, ring_count=180)




# オブジェクトを取得


obj = bpy.context.object




# オブジェクトのメッシュを取得し、bmeshを作成


me = obj.data


bm = bmesh.new()


bm.from_mesh(me)




# 円周の方程式 y^2 + z^2 = 2 の y > 0 の部分の面を削除


for f in bm.faces:


    if all([v.co.y > 0 for v in f.verts]):


        bm.faces.remove(f)




# bmeshをメッシュに適用してオブジェクトを更新


bm.to_mesh(me)


me.update()




# オブジェクト名を設定


obj.name = zion_name




# オブジェクトの位置を変更


obj.location = (0, 0, 0)







2023年4月26日水曜日

20230427 thu 雷

 


import bpy

import math


# 定義調整

zion_torus_minor = 0.1


# 中心座標

zion_location_000 = (0,0,0)

zion_location_1 = (1,0,0)

zion_location_sqrt2 = (math.sqrt(2),0,0)

zion_location_sqrt3 = (math.sqrt(3),0,0)


# 球体の半径

zion_sphere_000_radius = 0.05

zion_sphere_1_radius = 0.1

zion_sphere_sqrt2_radius = 0.15

zion_sphere_sqrt3_radius = 0.2


# トーラスの半径

radius_1 = 1

radius_sqrt2 = math.sqrt(2)

radius_sqrt3 = math.sqrt(3)


# トーラスの作成

bpy.ops.mesh.primitive_torus_add(

    minor_radius=zion_torus_minor,

    major_radius=radius_1,

    location=zion_location_000

)


# オブジェクト名を設定

bpy.context.object.name = "Torus_1"


# トーラスの作成

bpy.ops.mesh.primitive_torus_add(

    minor_radius=zion_torus_minor,

    major_radius=radius_1,

    location=zion_location_1

)


# オブジェクト名を設定

bpy.context.object.name = "Torus_1"


# トーラスの作成

bpy.ops.mesh.primitive_torus_add(

    minor_radius=zion_torus_minor,

    major_radius=radius_sqrt2,

    location=zion_location_sqrt2

)


# オブジェクト名を設定

bpy.context.object.name = "Torus_sqrt2"


# トーラスの作成

bpy.ops.mesh.primitive_torus_add(

    minor_radius=zion_torus_minor,

    major_radius=radius_sqrt3,

    location=zion_location_sqrt3

)


# オブジェクト名を設定

bpy.context.object.name = "Torus_sqrt3"


# トーラスの中心に球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(

    radius=zion_sphere_000_radius,

    location=zion_location_000

)

bpy.context.object.name = "Sphere_000"


# 1の位置に球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(

    radius=zion_sphere_1_radius,

    location=zion_location_1

)

bpy.context.object.name = "Sphere_1"


# sqrt(2)の位置に球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(

    radius=zion_sphere_sqrt2_radius,

    location=zion_location_sqrt2

)

bpy.context.object.name = "Sphere_sqrt2"


# sqrt(3)の位置に球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(

    radius=zion_sphere_sqrt3_radius,

    location=zion_location_sqrt3

)

bpy.context.object.name = "Sphere_sqrt3"





20230426ddd 球体表面 3点で 三角形

 三角形





球体中心 三角形 重心 


import bpy

import mathutils

import math

import random


# 大きな球体の半径と位置

big_sphere_radius = 2.0

big_sphere_location = (0, 0, 0)


# 大きな球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=big_sphere_radius, location=big_sphere_location, enter_editmode=False)

big_sphere = bpy.context.object


# ランダムな3点を選択し、それぞれに半径0.1の球体を作成

point_locs = []

for i in range(3):

    # ランダムな点を選択

    theta = random.uniform(0, 2 * math.pi)

    phi = random.uniform(0, math.pi)

    x = big_sphere_radius * math.sin(phi) * math.cos(theta) + big_sphere_location[0]

    y = big_sphere_radius * math.sin(phi) * math.sin(theta) + big_sphere_location[1]

    z = big_sphere_radius * math.cos(phi) + big_sphere_location[2]

    point_loc = (x, y, z)

    point_locs.append(point_loc)


    # 選択された点を中心に半径0.1の球体を作成

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=point_loc, enter_editmode=False)

    ball = bpy.context.object


    # 大きな球体の法線方向とランダムなベクトルを計算して、球体を回転させる

    normal = ball.location - big_sphere.location

    axis = mathutils.Vector((random.uniform(-1, 1), random.uniform(-1, 1), random.uniform(-1, 1))).cross(normal)

    angle = normal.angle(mathutils.Vector((0, 0, 1)))

    ball.rotation_euler = axis.to_track_quat('-Z', 'Y').to_euler()

    ball.rotation_euler.rotate_axis('Z', angle)


    # 球体を大きな球体の子オブジェクトに設定する

    ball.parent = big_sphere


# 三角形を作成

tri_verts = [mathutils.Vector(p) for p in point_locs]

tri_faces = [(0, 1, 2)]

tri_mesh = bpy.data.meshes.new('triangle_mesh')

tri_obj = bpy.data.objects.new('triangle_object', tri_mesh)

bpy.context.scene.collection.objects.link(tri_obj)

tri_mesh.from_pydata(tri_verts, [], tri_faces)


# 三角形の法線方向を計算して、球体を移動させる

tri_normal = tri_obj.matrix_world.to_3x3() @ tri_mesh.polygons[0].normal

move_vec = tri_normal.normalized() * 0.05

for ball in big_sphere.children:

    ball.location += move_vec


# 三角形の重心を計算する

tri_center = mathutils.Vector((0, 0, 0))

for p in point_locs:

    tri_center += mathutils.Vector(p)

tri_center /= 3


# 三角形の重心を中心に半径3の球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=3, location=tri_center, enter_editmode=False)





三角形と 円 バラバラ 角度タイプ





import bpy

import mathutils

import math

import random


# 大きな球体の半径と位置

big_sphere_radius = 2.0

big_sphere_location = (0, 0, 0)


# 大きな球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=big_sphere_radius, location=big_sphere_location, enter_editmode=False)

big_sphere = bpy.context.object


# ランダムな3点を選択し、それぞれに半径0.1の球体を作成

point_locs = []

for i in range(3):

    # ランダムな点を選択

    theta = random.uniform(0, 2 * math.pi)

    phi = random.uniform(0, math.pi)

    x = big_sphere_radius * math.sin(phi) * math.cos(theta) + big_sphere_location[0]

    y = big_sphere_radius * math.sin(phi) * math.sin(theta) + big_sphere_location[1]

    z = big_sphere_radius * math.cos(phi) + big_sphere_location[2]

    point_loc = (x, y, z)

    point_locs.append(point_loc)


    # 選択された点を中心に半径0.1の球体を作成

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=point_loc, enter_editmode=False)

    ball = bpy.context.object


    # 大きな球体の法線方向とランダムなベクトルを計算して、球体を回転させる

    normal = ball.location - big_sphere.location

    axis = mathutils.Vector((random.uniform(-1, 1), random.uniform(-1, 1), random.uniform(-1, 1))).cross(normal)

    angle = normal.angle(mathutils.Vector((0, 0, 1)))

    ball.rotation_euler = axis.to_track_quat('-Z', 'Y').to_euler()

    ball.rotation_euler.rotate_axis('Z', angle)


    # 球体を大きな球体の子オブジェクトに設定する

    ball.parent = big_sphere


# 三角形を作成

tri_verts = [mathutils.Vector(p) for p in point_locs]

tri_faces = [(0, 1, 2)]

tri_mesh = bpy.data.meshes.new('triangle_mesh')

tri_obj = bpy.data.objects.new('triangle_object', tri_mesh)

bpy.context.scene.collection.objects.link(tri_obj)

tri_mesh.from_pydata(tri_verts, [], tri_faces)


# 三角形の重心を計算して、半径3の円を作成

tri_centroid = (tri_verts[0] + tri_verts[1] + tri_verts[2]) / 3

bpy.ops.curve.primitive_bezier_circle_add(radius=3, enter_editmode=False, location=tri_centroid)

circle = bpy.context.object


# 三角形の法線方向を計算して、球体を移動させる

tri_normal = tri_obj.matrix_world.to_3x3() @ tri_mesh.polygons[0].normal

move_vec = tri_normal.normalized() * 0.05

for ball in big_sphere.children:

    ball.location += move_vec








import bpy

import mathutils

import math

import random


# 大きな球体の半径と位置

big_sphere_radius = 2.0

big_sphere_location = (0, 0, 0)


# 大きな球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=big_sphere_radius, location=big_sphere_location, enter_editmode=False)

big_sphere = bpy.context.object


# ランダムな3点を選択し、それぞれに半径0.1の球体を作成

point_locs = []

for i in range(3):

    # ランダムな点を選択

    theta = random.uniform(0, 2 * math.pi)

    phi = random.uniform(0, math.pi)

    x = big_sphere_radius * math.sin(phi) * math.cos(theta) + big_sphere_location[0]

    y = big_sphere_radius * math.sin(phi) * math.sin(theta) + big_sphere_location[1]

    z = big_sphere_radius * math.cos(phi) + big_sphere_location[2]

    point_loc = (x, y, z)

    point_locs.append(point_loc)


    # 選択された点を中心に半径0.1の球体を作成

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=point_loc, enter_editmode=False)

    ball = bpy.context.object


    # 大きな球体の法線方向とランダムなベクトルを計算して、球体を回転させる

    normal = ball.location - big_sphere.location

    axis = mathutils.Vector((random.uniform(-1, 1), random.uniform(-1, 1), random.uniform(-1, 1))).cross(normal)

    angle = normal.angle(mathutils.Vector((0, 0, 1)))

    ball.rotation_euler = axis.to_track_quat('-Z', 'Y').to_euler()

    ball.rotation_euler.rotate_axis('Z', angle)


    # 球体を大きな球体の子オブジェクトに設定する

    ball.parent = big_sphere


# 三角形を作成

tri_verts = [mathutils.Vector(p) for p in point_locs]

tri_faces = [(0, 1, 2)]

tri_mesh = bpy.data.meshes.new('triangle_mesh')

tri_obj = bpy.data.objects.new('triangle_object', tri_mesh)

bpy.context.scene.collection.objects.link(tri_obj)

tri_mesh.from_pydata(tri_verts, [], tri_faces)


# 三角形の法線方向を計算して、球体を移動させる

tri_normal = tri_obj.matrix_world.to_3x3() @ tri_mesh.polygons[0].normal

move_vec = tri_normal.normalized() * 0.05

for ball in big_sphere.children:

    ball.location += move_vec