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





2023年4月25日火曜日

20230426 円柱 三角形 ランダム 球体表面










外心

https://manabitimes.jp/math/628



20230426ccc 球体表面に 12個の球体













import math
import random
import bpy

big_sphere_radius = 3.0
big_sphere_location = (0, 0, 0)
big_sphere_name = "Big Sphere"

random_ball_count = 2
random_ball_radius = 0.1
random_ball_name = "random_ball"

segment_ball_count = 9
segment_ball_radius = 0.05
segment_ball_name = "senbun_ball"

# 大きな球体を作成
bpy.ops.mesh.primitive_uv_sphere_add(radius=big_sphere_radius, location=big_sphere_location, enter_editmode=False)
bpy.context.object.name = big_sphere_name

# ランダムな小さな球体を作成
for i in range(random_ball_count):
    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]
    loc = (x, y, z)
    bpy.ops.mesh.primitive_uv_sphere_add(radius=random_ball_radius, location=loc, enter_editmode=False)
    bpy.context.object.name = f"{random_ball_name}{i}"

# ランダムに2つの球体を選び、選択状態にする
random_balls = [obj for obj in bpy.data.objects if obj.name.startswith(random_ball_name)]
selected_spheres = random.sample(random_balls, 2)

# 選択した球体をショッキングピンク色にする
pink_material = bpy.data.materials.new(name="Pink")
pink_material.diffuse_color = (1, 0, 1, 1)
for obj in selected_spheres:
    obj.active_material = pink_material

# 選ばれた2つの球体の間に、9つの小さな球体を作成
x1, y1, z1 = selected_spheres[0].location
x2, y2, z2 = selected_spheres[1].location

for i in range(segment_ball_count):
    t = (i + 1) / (segment_ball_count + 1)
    x = (1 - t) * x1 + t * x2
    y = (1 - t) * y1 + t * y2
    z = (1 - t) * z1 + t * z2
    loc = (x, y, z)
    bpy.ops.mesh.primitive_uv_sphere_add(radius=segment_ball_radius, location=loc, enter_editmode=False)
    bpy.context.object.name = f"{segment_ball_name}{i}"
    bpy.context.object.active_material = bpy.data.materials.new(f"Material_{i}")
    bpy.context.object.active_material.diffuse_color = (1, 0, 0, 1)  # 赤色

# 球体の選択を解除
bpy.ops.object.select_all(action='DESELECT')

# 大きな球体を選択して、水色で透明度0.1の色を付ける
big_sphere = bpy.data.objects[big_sphere_name]
big_sphere.select_set(True)
blue_material = bpy.data.materials.new(name="Blue")
blue_material.diffuse_color = (0, 0.5, 1, 0.05)
for obj in bpy.data.objects:
    if obj.type == 'MESH' and obj.name == big_sphere_name:
        obj.active_material = blue_material

# 球体の選択を解除
bpy.ops.object.select_all(action='DESELECT')





20230426bbb 球体表面に 36個の球体 

 







import bpy

import math


# 大きい球体の半径

zion_big_sphere_radius = 6.0


# 小さい球体の半径

zion_small_sphere_radius = 0.1


# 大きい球体の回転数

frame_count = 600


# 小さい球体の数

zion_small_sphere_count = 360


# 小さい球体の名前

zion_small_sphere_name = "SmallSphere"


# 大きい球体の回転方向(時計回り)

zion_big_sphere_rotation_direction = -1


# 大きい球体を作成

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

zion_big_sphere = bpy.context.object

zion_big_sphere.name = "BigSphere"


# 小さい球体を作成

for i in range(zion_small_sphere_count):

    theta = i * math.pi / 180

    phi = i * math.pi / 180

    x = zion_big_sphere_radius * math.sin(theta) * math.cos(phi)

    y = zion_big_sphere_radius * math.sin(theta) * math.sin(phi)

    z = zion_big_sphere_radius * math.cos(theta) 


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

    small_sphere = bpy.context.object

    small_sphere.name = zion_small_sphere_name + "." + str(i)


# アニメーションのキーフレームを生成する

for i in range(frame_count):

    # 大きい球体を回転させる

    zion_big_sphere = bpy.data.objects.get("BigSphere")

    if zion_big_sphere:

        zion_big_sphere.rotation_euler[2] += zion_big_sphere_rotation_direction * 2 * math.pi / frame_count

        zion_big_sphere.keyframe_insert(data_path="rotation_euler", frame=i)


        # 小さい球体も同じ回転を加える

        for j in range(zion_small_sphere_count):

            small_sphere_name = zion_small_sphere_name + "." + str(j)

            small_sphere = bpy.data.objects.get(small_sphere_name)

            if small_sphere:

                small_sphere.rotation_euler[2] += zion_big_sphere_rotation_direction * 2 * math.pi / frame_count

                small_sphere.keyframe_insert(data_path="rotation_euler", frame=i)


                # 小さい球体の回転速度を大きい球体に合わせる

                small_sphere.rotation_euler[2] -= j * 2 * math.pi / zion_small_sphere_count

                small_sphere.keyframe_insert(data_path="rotation_euler", frame=i)



20230426aaa 球体表面に 36個の球体  





# ランダム配置 球体表面に36個 球体



import bpy

import math

import random


# 大きい球体の情報

zion_big_sphere_name = "Center Sphere"  # 大きい球体の名前

zion_big_sphere_radius = 2.0  # 大きい球体の半径

zion_big_sphere_location = (0, 0, 0)  # 大きい球体の位置

zion_big_sphere_rotation_speed = 600  # 1回転するのに要するフレーム数

zion_big_sphere_rotation_direction = 1  # 回転方向(1: 反時計回り、-1: 時計回り)


# 小さい球体の情報

zion_small_sphere_name = "Small Sphere"  # 小さい球体の名前

zion_small_sphere_count = 36  # 小さい球体の数

zion_small_sphere_radius = 0.1  # 小さい球体の半径


# 大きい球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=zion_big_sphere_radius, location=zion_big_sphere_location)


# 大きい球体を変数に格納

zion_big_sphere = bpy.context.object

zion_big_sphere.name = zion_big_sphere_name


# 小さい球体を作成

for i in range(zion_small_sphere_count):

    # 球面座標を計算

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

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

    x = zion_big_sphere_radius * math.sin(phi) * math.cos(theta)

    y = zion_big_sphere_radius * math.sin(phi) * math.sin(theta)

    z = zion_big_sphere_radius * math.cos(phi)

    location = (x, y, z)


    # 小さい球体を作成

    bpy.ops.mesh.primitive_uv_sphere_add(radius=zion_small_sphere_radius, location=location)


    # 小さい球体を大きい球体の子オブジェクトにする

    zion_small_sphere = bpy.context.object

    zion_small_sphere.name = zion_small_sphere_name + "." + str(i)

    zion_small_sphere.parent = zion_big_sphere


# アニメーションを作成

frame_count = zion_big_sphere_rotation_speed

for i in range(frame_count):

    # 大きい球体を回転させる

    zion_big_sphere.rotation_euler.rotate_axis("Z", zion_big_sphere_rotation_direction * 2 * math.pi / frame_count)


    # 小さい球体を大きい球体の表面に沿って移動させる

    for j in range(zion_small_sphere_count):

        small_sphere_name = zion_small_sphere_name + "." + str(j)

        small_sphere = bpy.data.objects[small_sphere_name]

        sphere_phi = math.acos(small_sphere.location[2] / zion_big_sphere_radius)

        sphere_theta = math.atan2(small_sphere.location[1], small_sphere.location[0]) + zion