2023年7月4日火曜日

20230705 長さ2の線路と いろいろ円周

aa



 


コレクション名 ”線路 円内”

を 作る



import bpy


# Create a new collection

collection_name = "線路 円内"

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


# Link the collection to the scene

scene = bpy.context.scene

scene.collection.children.link(collection)



blender python で


マークにする

半径0.2 の球体を 複数 作る

名前を連番で 作る


球体中心位置は


-1,0,0

0,0,0

+1,0,0


import bpy

from mathutils import Vector


def create_spheres():

    centers = [Vector((-1, 0, 0)), Vector((0, 0, 0)), Vector((1, 0, 0))]

    radius = 0.2


    for i, center in enumerate(centers):

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

        sphere = bpy.context.active_object

        sphere.name = f"Rail_{i+1}"


        # Customize the sphere's properties here

        # Example: Assign materials, set scale, etc.


    bpy.ops.object.mode_set(mode='OBJECT')


# Call the function to create the spheres

create_spheres()








blender python で

トーラスを複数 作る

連番で 名前を付ける


名前の付け方は 

トーラスの中心位置 x,y,zなら ”torus_x,y,z"

x,y,zは 小数点1桁まで 使う

 

トーラスのマイナー半径  0.02


トーラスの中心 

0,-√3,0

0,-2√3,0

0,-10,0



指定した

トーラス中心から

-1,0,0

までの距離を求めて

トーラスの半径にする


トーラスを描く



import bpy

import math


# パラメーター設定

minor_radius = 0.02

center_positions = [(0, -math.sqrt(3), 0), (0, -2*math.sqrt(3), 0), (0, -10, 0)]

passing_point = (-1, 0, 0)


# トーラスを作成し、連番の名前を付ける

for i, center in enumerate(center_positions):

    # 中心位置からの距離を計算して半径を求める

    distance = math.dist(center, passing_point)

    major_radius = distance


    # トーラスを作成

    bpy.ops.mesh.primitive_torus_add(

        align='WORLD',

        major_radius=major_radius,

        minor_radius=minor_radius,

        major_segments=48,

        minor_segments=12

    )

    torus = bpy.context.active_object


    # トーラスの位置と名前を設定

    torus.location = center

    torus_name = f"torus_{center[0]:.1f},{center[1]:.1f},{center[2]:.1f}"

    torus.name = torus_name




コレクション名 ”円周”

を 作る


import bpy


# Collection name

collection_name = "円周"


# Create the collection if it doesn't exist

if collection_name not in bpy.data.collections:

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

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

else:

    collection = bpy.data.collections[collection_name]


print(f"Collection '{collection_name}' created.")





球体を作る
球体の半径 0.2

名前は 連番で "円中心_y"

y軸位置の 小数点第1までの名にする


球体中心位置

0,-√3,0

0,-2√3,0

0,-10,0

0,2 - √3,0










コレクション名 ”円周 中心”

だけを 作る


import bpy


# Collection name

collection_name = "円周中心"


# Create the collection if it doesn't exist

if collection_name not in bpy.data.collections:

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

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

else:

    collection = bpy.data.collections[collection_name]


print(f"Collection '{collection_name}' created.")






import bpy
import math

# Parameters
sphere_radius = 0.2
center_positions = [(0, -math.sqrt(3), 0), (0, -2*math.sqrt(3), 0), (0, -10, 0), ]

# Create spheres at the center positions
for i, center in enumerate(center_positions):
    # Get the y-axis position with one decimal place
    y_position = round(center[1], 1)
    
    # Create sphere
    bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, location=center)
    sphere = bpy.context.active_object

    # Set sphere name
    sphere_name = f"円中心_{y_position}"
    sphere.name = sphere_name
    
print("Spheres created.")











コレクション名 ”ドーム”

だけを 作る



import bpy


# Collection name

collection_name = "ドーム"


# Create the collection if it doesn't exist

if collection_name not in bpy.data.collections:

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

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

else:

    collection = bpy.data.collections[collection_name]


print(f"Collection '{collection_name}' created.")









球体を作る
球体の半径 0.2

名前は 連番で "ドーム_y"

y軸位置の 小数点第1までの名にする



球体中心位置は 以下で 計算する



blender python で

円周を複数 作る

連番で 名前を付ける



名前の付け方は 

円周の中心位置 x,y,zなら ”円周_x,y,z"

x,y,zは 小数点1桁まで 使う

 


円周の中心 

0,-√3,0

0,-2√3,0

0,-10,0





指定した

トーラス中心から

-2,0,0

までの距離を求めて

円周の半径にする


それぞれの円周の
(x,y,z)で

yが 最大位置を

球体の中心にして
球体を描く




import bpy
import math

# Define the center positions for the circular paths
center_positions = [(0, -math.sqrt(3), 0),
                    (0, -2 * math.sqrt(3), 0),
                    (0, -10, 0)]

# Define the target position for each circular path
target_position = (-1, 0, 0)

# Calculate the radius for each circular path
radii = [math.sqrt((target_position[0] - center[0]) ** 2 + (target_position[1] - center[1]) ** 2 + (target_position[2] - center[2]) ** 2) for center in center_positions]

# Create spheres on each circular path
for i, center in enumerate(center_positions):
    # Generate the name for the sphere
    name = "Circle_{},{},{}".format(round(center[0], 1), round(center[1], 1), round(center[2], 1))

    # Set the sphere's center position
    bpy.ops.mesh.primitive_uv_sphere_add(radius=radii[i], location=center)

    # Rename the sphere object
    sphere = bpy.context.object
    sphere.name = name









コレクション名 ”正面”

だけを 作る



import bpy


# Collection name

collection_name = "正面"


# Create the collection if it doesn't exist

if collection_name not in bpy.data.collections:

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

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

else:

    collection = bpy.data.collections[collection_name]


print(f"Collection '{collection_name}' created.")








球体を作る
球体の半径 0.2

名前は 連番で "正面_y"

y軸位置の 小数点第1までの名にする


0,2-(√3),0
0,(√13)-(2√3),0
0,(√101)-10,0



import bpy
import math

# 球体の半径
半径 = 0.2

# 位置のリスト
位置リスト = [
    (0, 2 - math.sqrt(3), 0),
    (0, math.sqrt(13) - (2 * math.sqrt(3)), 0),
    (0, math.sqrt(101) - 10, 0)
]

# 連番でオブジェクトを作成する
for i, 位置 in enumerate(位置リスト):
    # 名前の作成
    名前 = "正面_y{:.1f}".format(位置[1])

    # 球体を作成
    bpy.ops.mesh.primitive_uv_sphere_add(radius=半径, location=位置)
    球体 = bpy.context.active_object

    # 名前を設定
    球体.name = 名前









円柱を作る
円柱の中心 000
円柱の半径 0.1
円柱の長さ 20

-10,0,0 から  +10.0,0 に
円柱の中心軸の 両端が位置する

円柱を y軸を回転軸で 90度回転

名前を付ける "線路レールの円柱”


import bpy
import math

# 円柱の中心
中心 = (0, 0, 0)

# 円柱の半径
半径 = 0.1

# 円柱の長さ
長さ = 20

# 円柱の両端の位置
始点 = (-10.0, 0, 0)
終点 = (10.0, 0, 0)

# 円柱を作成
bpy.ops.mesh.primitive_cylinder_add(
    radius=半径,
    depth=長さ,
    location=中心,
    end_fill_type='NOTHING'
)

# 作成された円柱オブジェクトを取得
円柱 = bpy.context.active_object

# 円柱の両端を設定
円柱.location = (0, 0, 0)
円柱.rotation_euler = (0, math.radians(90), 0)
円柱.scale = (1, 1, 1)
bpy.ops.object.origin_set(type='ORIGIN_CENTER')

# 両端の位置を設定
円柱.data.vertices[0].co = 始点
円柱.data.vertices[1].co = 終点



名前を付ける "線路レールの円柱”

さらに もう1つ 円柱を作る

# 円柱の両端の位置
始点 = (-10.0, 2-√3, 0)
終点 = (10.0,  2-√3, 0)
名前を付ける "線路レール 2ー√3の円柱”



import bpy
import math

# 円柱の中心
中心 = (0, 2-3**0.5, 0)

# 円柱の半径
半径 = 0.1

# 円柱の長さ
長さ = 20

# 円柱の両端の位置
始点 = (-10.0,  2-3**0.5, 0)
終点 = (10.0,  2-3**0.5, 0)

# 円柱を作成
bpy.ops.mesh.primitive_cylinder_add(
    radius=半径,
    depth=長さ,
    location=中心,
    end_fill_type='NOTHING'
)

# 作成された円柱オブジェクトを取得
円柱 = bpy.context.active_object

# 円柱の両端を設定
円柱.location = (0, 0, 0)
円柱.rotation_euler = (0, math.radians(90), 0)
円柱.scale = (1, 1, 1)
bpy.ops.object.origin_set(type='ORIGIN_CENTER')

# 両端の位置を設定
円柱.data.vertices[0].co = 始点
円柱.data.vertices[1].co = 終点




20230703 元 20230508

 


配布 20230703 a001 元20230508 skybox  003  moto 20230422 bbb半球 半径2 ビデオ会議 006

https://drive.google.com/file/d/15Gyz2Lf5XSIZFNFbBFpj25gaZhtPs_Bz/view?usp=drive_link



















aaaa


2023年6月22日木曜日

20230623 列車慣性系の3枚重ね





import bpy

import math


# 長方形のサイズ

width = 2.0

height = 1.0


# 長方形の中心座標

center = (0.0, 0.0, 0.0)


# 球体の半径と個数

sphere_radius = 0.02

sphere_count = 80


# コレクションの作成と名前付け

collection_names = ["t=0_train", "t=-1_train", "t=+1_train"]


for collection_name in collection_names:

    if collection_name not in bpy.data.collections:

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

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


# 球体を配置する関数

def create_spheres(collection_name, z_position):

    collection = bpy.data.collections[collection_name]


    # 球体の作成と配置

    for i in range(sphere_count):

        angle = 2 * math.pi * i / sphere_count

        x = center[0] + (width/2 + sphere_radius) * math.cos(angle)

        y = center[1] + (height/2 + sphere_radius) * math.sin(angle)

        z = z_position


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


        # 最後に作成された球体オブジェクトを選択状態にする

        obj = bpy.context.object

        obj.name = f"t{z_position}_Sphere_{i+1}"

        obj.select_set(True)

        bpy.context.view_layer.objects.active = obj


        # 不要なリンクを削除

        bpy.context.collection.objects.unlink(obj)


        # 球体を対応するコレクションに追加

        collection.objects.link(obj)


# 球体を配置する関数を呼び出し

create_spheres("t=0_train", 0.0)

create_spheres("t=-1_train", -1.0)

create_spheres("t=+1_train", 1.0)





2023年6月21日水曜日

20230622 光円錐

 




blendeer python でスクリプト書き出す








000を中心に 半径1のトーラス マイナー半径 0.02 を z=-1に描く

0、0、0.1を中心に 半径1-0.01のトーラス マイナー半径 0.02 を z=ー0.9に描く

0、0、0.2を中心に 半径1-0.02のトーラス マイナー半径 0.02 を z=ー0.8に描く


これを繰り返し z=0 まで トーラスを複数描く


import bpy

import math


center_x = 0.0

center_y = 0.0

minor_radius = 0.02

z = -1.0

z_increment = 0.1

num_toruses = 11


for i in range(num_toruses):

    major_radius = 1.0 - (i * 0.1)

    bpy.ops.mesh.primitive_torus_add(

        align='WORLD',

        location=(center_x, center_y, z),

        rotation=(0, 0, 0),

        major_radius=major_radius,

        minor_radius=minor_radius,

        major_segments=48,

        minor_segments=12

    )


    torus_obj = bpy.context.object

    bpy.context.view_layer.objects.active = torus_obj

    bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS', center='BOUNDS')


    z += z_increment






今度は 

z=0から Z=1に トーラスを11個描く

半径が 0から 0.1ずつ大きくする


この11個のトーラスに future torus 0.0 から 1.0の連番で名前を付ける



import bpy

import math


center_x = 0.0

center_y = 0.0

minor_radius = 0.02

z = 0.0

z_increment = 1.0 / 10.0  # Zの増分を計算

num_toruses = 11


for i in range(num_toruses):

    major_radius = i * 0.1  # 半径を0から0.1ずつ増加させる

    bpy.ops.mesh.primitive_torus_add(

        align='WORLD',

        location=(center_x, center_y, z),

        rotation=(0, 0, 0),

        major_radius=major_radius,

        minor_radius=minor_radius,

        major_segments=48,

        minor_segments=12

    )


    torus_obj = bpy.context.object

    bpy.context.view_layer.objects.active = torus_obj

    bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS', center='BOUNDS')


    # トーラスに名前を付ける

    torus_obj.name = "FutureTorus" + str(round(major_radius, 1))


    z += z_increment








今度は 

z=0から Z=-1に トーラスを11個描く

半径が 0から 0.1ずつ大きくする

この11個のトーラスに past torus -0.0 から -1.0 の連番で名前を付ける




import bpy

import math


center_x = 0.0

center_y = 0.0

minor_radius = 0.02

z = 0.0

z_decrement = -1.0 / 10.0  # Zの減分を計算

num_toruses = 11


for i in range(num_toruses):

    major_radius = i * 0.1  # 半径を0から0.1ずつ増加させる

    bpy.ops.mesh.primitive_torus_add(

        align='WORLD',

        location=(center_x, center_y, z),

        rotation=(0, 0, 0),

        major_radius=major_radius,

        minor_radius=minor_radius,

        major_segments=48,

        minor_segments=12

    )


    torus_obj = bpy.context.object

    bpy.context.view_layer.objects.active = torus_obj

    bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS', center='BOUNDS')


    # トーラスに名前を付ける

    torus_obj.name = "PastTorus" + str(round(-major_radius, 1))


    z += z_decrement




コレクション名を 作る


Future torus

Past torus

+5 Future torus

+5 Past torus

-5 Future torus

-5 Past torus


6つ作る



import bpy


collection_names = ["Future torus", "Past torus", "+5 Future torus", "+5 Past torus", "-5 Future torus", "-5 Past torus"]


for collection_name in collection_names:

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

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




 x軸に +5 移動させて 名前を +5 PastTorus で連番に


以下を x軸に +5  移動させて 連番名を +5 Future torus にして

以下を x軸に ー5  移動させて 連番名を -5 Future torus にして


2023年6月20日火曜日

20230620 繰り返しの 頭の中の光線



blender python で


0,-10,0 と

0,10,0 を 両端とする


円柱を 太さ 0.1 で作る

 

BlenderのPythonを使用して、太さ0.1の円柱を座標(0, -10, 0)と(0, 10, 0)を両端として作成するには、以下のコードを使用します。



円柱が 描かれていない

円柱の中心は 0,0,0


円柱の中心が原点(0, 0, 0)であるように修正します。以下のコードを使用して、

BlenderのPythonで太さ0.1の円柱を中心(0, 0, 0)で作成



最初から やりなし 長さ 20の 円柱を 作る 

太さは 0.05


円柱の中心は 0,0,0

円柱の中心軸は y軸に 重なる


円柱の中心軸の両端は

0,-10,0 と

0,10,0


import bpy


# Set up the scene

bpy.context.scene.cursor.location = (0, 0, 0)

bpy.context.scene.cursor.rotation_euler = (0, 0, 0)


# Create a new mesh object

bpy.ops.mesh.primitive_cylinder_add(

    vertices=32,    # Number of vertices

    radius=0.05,     # Radius of the cylinder

    depth=20,       # Length of the cylinder

    location=(0, 0, 0),    # Center of the cylinder

    rotation=(1.5708, 0, 0)    # Rotate 90 degrees around the X-axis

)


# Rename the object

cylinder_obj = bpy.context.object

cylinder_obj.name = "Cylinder"





球体を 指定の場所に作る

球体の半径は 0.2


球体の位置は 

0,-1,0

0,1,0

0.5,-1,0

0.5,1.0

1,-1,0

1,1.0



球体の名前は

球(0,-1,0)


のように 名付ける





import bpy


# Define the positions of the spheres

positions = [

    (0, -1, 0),

    (0, 1, 0),

    (0.5, -1, 0),

    (0.5, 1.0, 0),

    (1, -1, 0),

    (1, 1.0, 0)

]


# Create spheres at the specified positions

for pos in positions:

    bpy.ops.mesh.primitive_uv_sphere_add(

        segments=32,    # Number of segments

        ring_count=16,  # Number of rings

        radius=0.2,     # Radius of the sphere

        location=pos    # Position of the sphere

    )

    # Rename each sphere based on its position

    sphere_obj = bpy.context.object

    sphere_obj.name = f"Sphere ({pos[0]},{pos[1]},{pos[2]})"




  (0, 0, 0),

    (0, 0, 1),

    (0, 0, 0.5)



(0, 0, 1),

    (0.5,0,  1),

    (1, 0, 1)





import bpy


# Create sphere at (0, -1, 0)

bpy.ops.mesh.primitive_uv_sphere_add(

    segments=32,    # Number of segments

    ring_count=16,  # Number of rings

    radius=0.2,     # Radius of the sphere

    location=(0, -1, 0)    # Position of the sphere

)


# Rename the sphere

sphere1_obj = bpy.context.object

sphere1_obj.name = "Sphere (0,-1,0)"


# Create sphere at (0, 1, 0)

bpy.ops.mesh.primitive_uv_sphere_add(

    segments=32,    # Number of segments

    ring_count=16,  # Number of rings

    radius=0.2,     # Radius of the sphere

    location=(0, 1, 0)    # Position of the sphere

)


# Rename the sphere

sphere2_obj = bpy.context.object

sphere2_obj.name = "Sphere (0,1,0)"






000 を 中心とする

1辺2の立方体を作る






2023年6月14日水曜日

20230615 thu 室内から窓面 窓面の外の線路 3つの時刻表示 



blender pythonで 


000を 半球の中心にして

半径1 で 描く





import bpy


# Create a new sphere mesh

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


# Select the sphere object

sphere_obj = bpy.context.object

sphere_obj.select_set(True)

bpy.context.view_layer.objects.active = sphere_obj


# Enter Edit Mode for the sphere

bpy.ops.object.mode_set(mode='EDIT')


# Deselect all vertices

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


# Select the vertices in the upper half of the sphere

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

bpy.ops.mesh.select_circle(x_axis=True, radius=1, location=(0, 0, 0), normal=(0, 0, -1), use_extend=False)


# Delete the selected vertices

bpy.ops.mesh.delete(type='VERT')


# Exit Edit Mode for the sphere

bpy.ops.object.mode_set(mode='OBJECT')


# Set the origin to the center of the modified sphere

bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS')







blender pythonで 


000を 立方体の中心にして

辺の長さ 2



2023年6月3日土曜日

20230604 sun 球体と 3つの線路

 







blender python で スクリプト全体を コードを「code block」の形式で示す


半径1の球体

中心 0,0,0


半径√2の球体

中心 0,0,0


半径√3の球体

中心 0,0,0



大きい球体から


透明 青

透明 ミドリ

透明 赤 


オブヘクト名を 付ける

sphere √3B

sphere √2G

sphere 1 R


RGBA で 色を設定する


マテリアル プロパティ

alpha 15%

blend mode を alpha blend 選択 



コレクション 名を 球体√  を作る

オブジェクトを入れるが リンクを作らない


オブジェクトをリンクなしで

コレクションに移動