2023年4月6日木曜日

完成 軸線 円柱 √3倍 √2倍 1倍

 


 # 円柱 000 30,30,30

 

import bpy
import mathutils
import math

# オブジェクトを作成する関数
def create_object(start, end, radius, name):
    # 座標変換を作成
    direction = end - start
    length = direction.length
    direction.normalize()
    mat_loc = mathutils.Matrix.Translation(start)

    # CylinderMeshに頂点、辺、面を追加
    mesh = bpy.data.meshes.new(name)
    obj = bpy.data.objects.new(name, mesh)

    n_segments = 32  # 円周の分割数
    angle_per_segment = 2 * math.pi / n_segments

    verts = []
    for i in range(n_segments):
        angle = i * angle_per_segment
        x = radius * math.cos(angle)
        y = radius * math.sin(angle)
        verts.append((x, y, 0))
        verts.append((x, y, length))

    edges = []
    faces = []
    for i in range(n_segments):
        j = (i + 1) % n_segments
        edges.append((i, i + n_segments))
        faces.append((i, j, j + n_segments, i + n_segments))

    # CylinderMeshに頂点、辺、面をセット
    mesh.from_pydata(verts, edges, faces)
    mesh.update()

    # オブジェクトの座標変換を適用
    z_axis = mathutils.Vector((0, 0, 1))
    rotation = z_axis.rotation_difference(direction).to_matrix()
    mat_rot = rotation.to_4x4()
    mat_scale = mathutils.Matrix.Scale(1, 4, (start - end).normalized())
    obj.matrix_world = mat_loc @ mat_rot @ mat_scale

    return obj

# オブジェクトを作成
start = mathutils.Vector((0, 0, 0))
end = mathutils.Vector((30, 30, 30))
radius = 0.2
name = "長さ root3 Cylinder"
cylinder = create_object(start, end, radius, name)

# オブジェクトをシーンに追加
scene = bpy.context.scene
scene.collection.objects.link(cylinder)

# ビューポートを更新
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)




 # 円柱 000 30,30,0

 

import bpy
import mathutils
import math

# オブジェクトを作成する関数
def create_object(start, end, radius, name):
    # 座標変換を作成
    direction = end - start
    length = direction.length
    direction.normalize()
    mat_loc = mathutils.Matrix.Translation(start)

    # CylinderMeshに頂点、辺、面を追加
    mesh = bpy.data.meshes.new(name)
    obj = bpy.data.objects.new(name, mesh)

    n_segments = 32  # 円周の分割数
    angle_per_segment = 2 * math.pi / n_segments

    verts = []
    for i in range(n_segments):
        angle = i * angle_per_segment
        x = radius * math.cos(angle)
        y = radius * math.sin(angle)
        verts.append((x, y, 0))
        verts.append((x, y, length))

    edges = []
    faces = []
    for i in range(n_segments):
        j = (i + 1) % n_segments
        edges.append((i, i + n_segments))
        faces.append((i, j, j + n_segments, i + n_segments))

    # CylinderMeshに頂点、辺、面をセット
    mesh.from_pydata(verts, edges, faces)
    mesh.update()

    # オブジェクトの座標変換を適用
    z_axis = mathutils.Vector((0, 0, 1))
    rotation = z_axis.rotation_difference(direction).to_matrix()
    mat_rot = rotation.to_4x4()
    mat_scale = mathutils.Matrix.Scale(1, 4, (start - end).normalized())
    obj.matrix_world = mat_loc @ mat_rot @ mat_scale

    return obj

# オブジェクトを作成
start = mathutils.Vector((0, 0, 0))
end = mathutils.Vector((30, 30, 0))
radius = 0.2
name = "長さ root2 Cylinder"
cylinder = create_object(start, end, radius, name)

# オブジェクトをシーンに追加
scene = bpy.context.scene
scene.collection.objects.link(cylinder)

# ビューポートを更新
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)





 # 円柱 000 30,0,0

 

import bpy
import mathutils
import math

# オブジェクトを作成する関数
def create_object(start, end, radius, name):
    # 座標変換を作成
    direction = end - start
    length = direction.length
    direction.normalize()
    mat_loc = mathutils.Matrix.Translation(start)

    # CylinderMeshに頂点、辺、面を追加
    mesh = bpy.data.meshes.new(name)
    obj = bpy.data.objects.new(name, mesh)

    n_segments = 32  # 円周の分割数
    angle_per_segment = 2 * math.pi / n_segments

    verts = []
    for i in range(n_segments):
        angle = i * angle_per_segment
        x = radius * math.cos(angle)
        y = radius * math.sin(angle)
        verts.append((x, y, 0))
        verts.append((x, y, length))

    edges = []
    faces = []
    for i in range(n_segments):
        j = (i + 1) % n_segments
        edges.append((i, i + n_segments))
        faces.append((i, j, j + n_segments, i + n_segments))

    # CylinderMeshに頂点、辺、面をセット
    mesh.from_pydata(verts, edges, faces)
    mesh.update()

    # オブジェクトの座標変換を適用
    z_axis = mathutils.Vector((0, 0, 1))
    rotation = z_axis.rotation_difference(direction).to_matrix()
    mat_rot = rotation.to_4x4()
    mat_scale = mathutils.Matrix.Scale(1, 4, (start - end).normalized())
    obj.matrix_world = mat_loc @ mat_rot @ mat_scale

    return obj

# オブジェクトを作成
start = mathutils.Vector((0, 0, 0))
end = mathutils.Vector((30, 0, 0))
radius = 0.2
name = "長さ root2 Cylinder"
cylinder = create_object(start, end, radius, name)

# オブジェクトをシーンに追加
scene = bpy.context.scene
scene.collection.objects.link(cylinder)

# ビューポートを更新
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)




改良中 y=-30 中心 円周への球体36個

できた y= -30 中心で z=0平面移動  import bpy import math zion_collection_name = "線路レール 観察者" # コレクションを作成する col = bpy.data.collections.new(zio...