2023年7月29日土曜日

20230730a 単位円を貫く円柱

 


目次 blender 部品 2023 - zionad_mainのブログ

blender 中間部品 イメージ目次 2023

blender 使い方 目次 2023 - zionad_mainのブログ




円柱を作る

長さ 4

中心 000

半径 0.03


x軸

y軸

z軸

合計 3つの円柱を作る











import bpy


# Function to create a cylinder along the specified axis

def create_cylinder(axis, name):

    bpy.ops.mesh.primitive_cylinder_add(vertices=32, radius=0.03, depth=4, location=(0, 0, 0))

    cylinder = bpy.context.object

    if axis == "x":

        cylinder.rotation_euler = (1.5708, 0, 0)  # 90 degrees in radians around X axis

    elif axis == "y":

        cylinder.rotation_euler = (0, 1.5708, 0)  # 90 degrees in radians around Y axis

    cylinder.name = name


# Create cylinders along each axis

create_cylinder("y", "名称X軸円柱")

create_cylinder("x", "名称y軸円柱")

create_cylinder("z", "Z軸円柱")





20230730a 単位円の トーラス

aaaaa 



目次 blender 部品 2023 - zionad_mainのブログ

blender 中間部品 イメージ目次 2023

blender 使い方 目次 2023 - zionad_mainのブログ
















xy平面に描いたトーラスを zx平面と yz平面にも描いて



import bpy


# Function to create a torus in the specified plane

def create_torus(plane):

    bpy.ops.mesh.primitive_torus_add(align='WORLD', location=(0, 0, 0), rotation=(0, 0, 0),

                                     major_radius=1, minor_radius=0.04, major_segments=48, minor_segments=12)

    torus = bpy.context.object

    if plane == "xy":

        torus.rotation_euler = (0, 0, 0)

    elif plane == "zx":

        torus.rotation_euler = (1.5708, 0, 0)  # 90 degrees in radians around X axis

    elif plane == "yz":

        torus.rotation_euler = (0, 1.5708, 0)  # 90 degrees in radians around Y axis

    torus.name = f"Torus {plane.upper()} Plane"


# Create tori in each plane

create_torus("xy")

create_torus("yz")

create_torus("zx")



2023年7月28日金曜日

202230729c 3本の線路 

 







blender python


球体を作る

球体半径 0.05


Z=0の

y=0


X=-2 から X=+2 に

等間隔で 21個の球体を作る


球体の名前は


”rail Y=0" で 連番 




y=ー√3

y=-2にも 同様にして



import bpy

import math


def create_sphere(x_pos, y_pos, name):

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.05, location=(x_pos, y_pos, 0))

    sphere = bpy.context.object

    sphere.name = name


# 等間隔で21個の球体を作成

for i in range(21):

    x_pos = -2.0 + (i * 0.2)  # X座標を計算

    x_pos_rounded = round(x_pos, 1)  # 小数点以下1桁までに丸める

    name = f"rail Y=0 {x_pos_rounded}"  # 球体の名前を生成

    create_sphere(x_pos, 0, name)


# Y軸が"-√3"と"-2"の位置にも球体を作成

y_positions = [round(-math.sqrt(3), 1), -2]  # "-√3"の部分を小数点以下1桁までに丸める

for y_pos in y_positions:

    for i in range(21):

        x_pos = -2.0 + (i * 0.2)  # X座標を計算

        x_pos_rounded = round(x_pos, 1)  # 小数点以下1桁までに丸める

        name = f"rail Y={y_pos} {x_pos_rounded}"  # 球体の名前を生成

        create_sphere(x_pos, y_pos, name)






ああああ

202230729b 円中心の球体point mark 半径2の円

 





球体を作る

円中心に 半径0.1



import bpy


# 球体を作成する位置のリスト

positions = [

    (0, 0, 0),

    (0, -2, 0),

    (1, -3**0.5, 0),

    (-1, -3**0.5, 0)

]


# ここからBlenderの処理


# シーンに追加

scene = bpy.context.scene


# 球体を作成

for i, position in enumerate(positions, start=1):

    bpy.ops.mesh.primitive_uv_sphere_add(radius=0.1, location=position)


    # 球体の名前を設定

    sphere = bpy.context.active_object

    sphere.name = f"Sphere_(x={position[0]:.1f}, y={position[1]:.1f}, z={position[2]:.1f})_{i}番"





202230729a 半径2の円  と 今回のコレクショ名



 






blender python


円を作る

円の半径2


円の中心は

0,0,0

0,-2,0

1,-√3,0

-1,-√3,0







centers = [

(0, 0, 0), 

(0, 2, 0), 

(1, -math.sqrt(3), 0), 

(-1, -math.sqrt(3), 0)

]








# 今回のコレクション名 作成





import bpy

# List of collection names
collection_names = [
    "円板",
    "高さ違い 円板",
    "球体 point marks",
    "rail Y=0",
    "rail Y=-√3",
    "rail Y=-2"
]

# Function to create a new collection if it doesn't exist
def create_collection_if_not_exists(name):
    if name not in bpy.data.collections:
        collection = bpy.data.collections.new(name)
        bpy.context.scene.collection.children.link(collection)

# Create collections
for name in collection_names:
    create_collection_if_not_exists(name)












import bpy

import math

import bmesh


# 円の半径

radius = 2.0


# 4つの円の位置

positions = [

    (0, 0, 0),

    (0, -2, 0),

    (1, -math.sqrt(3), 0),

    (-1, -math.sqrt(3), 0)

]


# 4つの色を用意(より薄い青)

colors = [

    (0.4, 0.8, 1.0, 1.0),

    (0.3, 0.6, 1.0, 1.0),

    (0.2, 0.4, 1.0, 1.0),

    (1.0, 0.4, 0.3, 1.0)

]


# 4つの円を作成し、位置と名前と色を設定

for i, (position, color) in enumerate(zip(positions, colors)):

    x, y, z = position

    name = f"Circle_(x={x:.1f}, y={y:.1f}, z={z:.1f})"

    

    # 新しいメッシュを作成

    mesh = bpy.data.meshes.new(f"{name}_Mesh")

    obj = bpy.data.objects.new(name, mesh)


    # シーンに追加

    scene = bpy.context.scene

    scene.collection.objects.link(obj)


    # メッシュを作成

    bm = bmesh.new()

    bmesh.ops.create_circle(bm, cap_ends=True, cap_tris=False, segments=64, radius=radius)

    bm.to_mesh(mesh)

    bm.free()


    # オブジェクトの位置を設定

    obj.location = position


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

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

    mat.use_nodes = False  # ノードを使用しない

    mat.diffuse_color = color

    obj.data.materials.append(mat)



2023年7月26日水曜日

20230726 eee 環境写真 投影用 半球ドーム








bllender python 


半球ドームを作る

中心は 000

半径は10




import bpy


# 中心と半径を指定して球体を作成

center = (0, 0, 0)

radius = 10


# 球体を作成

bpy.ops.mesh.primitive_uv_sphere_add(radius=radius, location=center, segments=32, ring_count=16)

obj = bpy.context.active_object


# マテリアルを作成して追加

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

obj.data.materials.append(mat)






2023年7月25日火曜日

20230727 ddd 平面を貼る

 


import bpy


# Parameters for the square

size = 10

y_pos = 10








# Create the square

vertices = [

    (-size/2, y_pos, -size/2),

    (-size/2, y_pos, size/2),

    (size/2, y_pos, size/2),

    (size/2, y_pos, -size/2)

]

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


# Create the mesh

mesh = bpy.data.meshes.new(name="SquareMesh")

mesh.from_pydata(vertices, [], faces)


# Create the object and link it to the scene

obj = bpy.data.objects.new("Square", mesh)

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





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