2023年4月9日日曜日

半径 √2の トーラス

 


import bpy

import math


# 半径√2

major_radius = math.sqrt(2)


# マイナー半径0.2

minor_radius = 0.05


# トーラスを作成

bpy.ops.mesh.primitive_torus_add(major_radius=major_radius, minor_radius=minor_radius)





2023年4月8日土曜日

逆さ円錐できた

 import bpy


from mathutils import Vector


# 設定可能な変数


zion_object_name = "逆さ円錐 600上昇"  # 円錐オブジェクトの名前


radius = 60  # 円錐の半径


height = 60  # 円錐の高さ


distance_per_frame = 0.1  # 円錐の移動距離


animation_frames = 1000  # アニメーションの再生時間(フレーム数)


wait_frames = 40  # アニメーション再生完了後の待機時間(フレーム数)


start_z = -30  # 円錐の初期位置(Z座標)


# 円錐を作成する


def create_cone():


    bpy.ops.mesh.primitive_cone_add(radius1=0, radius2=radius, depth=height)


    cone = bpy.context.object


    cone.name = zion_object_name


    cone.location = Vector((0, 0, start_z))  # 初期位置を設定する


    return cone


cone = create_cone()


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


for i in range(animation_frames):


    frame = i + 1


    # キーフレームごとの円錐の位置を設定する


    zion_pos = Vector((0, 0, cone.location.z + distance_per_frame))


    cone.location = zion_pos


    # キーフレームを設定する


    cone.keyframe_insert(data_path="location", frame=frame)


# アニメーション再生後の待機時間を設定する


for i in range(wait_frames):


    frame = animation_frames + i + 1


    cone.keyframe_insert(data_path="location", frame=frame, index=-1)


Real ball 中央

 


import bpy

import math


zion_collection_name = "Real ball"


# コレクションを作成する

col = bpy.data.collections.new(zion_collection_name)

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







import bpy

import math

from mathutils import Vector


# Set target location

target_location = Vector((0, 0, 60))


# Set initial locations

initial_locations = [Vector((0, 0, 0)), Vector((0, 0, 120))]


# Set sphere radius and segments

sphere_radius = 2

sphere_segments = 32


# 初期位置との距離から速度を計算する

chousei_kijyun = 60

distances = [math.sqrt(sum([(a - b) ** 2 for a, b in zip(loc, target_location)])) for loc in initial_locations]

speeds = [0.1 * (chousei_kijyun/ distance)  if distance > 0 else 0 for distance in distances]


# Create sphere objects and set locations

for i, initial_location in enumerate(initial_locations):

    bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, segments=sphere_segments)

    sphere = bpy.context.object

    sphere.location = initial_location


    if i == 0:

        sphere.name = "Real ball x=0"

    else:

        sphere.name = "Real ball x=+60"


    # Set animation keyframes

    last_frame = 1000

    for frame in range(last_frame+1):

        distance = (target_location - sphere.location).length


        if distance > 0.01:

            direction = (target_location - sphere.location).normalized()

            sphere.location += direction * min(speeds[i], distance)

            sphere.keyframe_insert(data_path="location", frame=frame)


# Function to set the number of frames

def set_frame_range(start_frame, end_frame):

    bpy.context.scene.frame_start = start_frame

    bpy.context.scene.frame_end = end_frame


# Example: set the number of frames to 1000

set_frame_range(1, 1000)


Real ball 両端 2

 


import bpy

import math


zion_collection_name = "Real ball"


# コレクションを作成する

col = bpy.data.collections.new(zion_collection_name)

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







import bpy

import math

from mathutils import Vector


# Set target location

target_location = Vector((0, 0, 60))


# Set initial locations

initial_locations = [Vector((-60, 0, 0)), Vector((60, 0, 0))]


# Set sphere radius and segments

sphere_radius = 2

sphere_segments = 32


# 初期位置との距離から速度を計算する

chousei_kijyun = 60

distances = [math.sqrt(sum([(a - b) ** 2 for a, b in zip(loc, target_location)])) for loc in initial_locations]

speeds = [0.1 * (chousei_kijyun/ distance)  if distance > 0 else 0 for distance in distances]


# Create sphere objects and set locations

for i, initial_location in enumerate(initial_locations):

    bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, segments=sphere_segments)

    sphere = bpy.context.object

    sphere.location = initial_location


    if i == 0:

        sphere.name = "Real Left ball"

    else:

        sphere.name = "Real Right ball"


    # Set animation keyframes

    last_frame = 1000

    for frame in range(last_frame+1):

        distance = (target_location - sphere.location).length


        if distance > 0.01:

            direction = (target_location - sphere.location).normalized()

            sphere.location += direction * min(speeds[i], distance)

            sphere.keyframe_insert(data_path="location", frame=frame)


# Function to set the number of frames

def set_frame_range(start_frame, end_frame):

    bpy.context.scene.frame_start = start_frame

    bpy.context.scene.frame_end = end_frame


# Example: set the number of frames to 1000

set_frame_range(1, 1000)


幻 ball 2

 

import bpy

import math



zion_collection_name = "幻 60 ball"


# コレクションを作成する

col = bpy.data.collections.new(zion_collection_name)

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







import bpy

import math

from mathutils import Vector


# Set target location

target_location = Vector((0, 0, 60))


# Set initial locations

initial_locations = [Vector((-60, 0, 0)), Vector((60, 0, 0))]


# Set sphere radius and segments

sphere_radius = 2

sphere_segments = 32


# 初期位置との距離から速度を計算する

chousei_kijyun = 60

distances = [math.sqrt(sum([(a - b) ** 2 for a, b in zip(loc, target_location)])) for loc in initial_locations]

speeds = [0.1 * distance / chousei_kijyun if distance > 0 else 0 for distance in distances]


# Create sphere objects and set locations

for i, initial_location in enumerate(initial_locations):

    bpy.ops.mesh.primitive_uv_sphere_add(radius=sphere_radius, segments=sphere_segments)

    sphere = bpy.context.object

    sphere.location = initial_location


    if i == 0:

        sphere.name = "幻 ball x=-60"

    else:

        sphere.name = "幻 ball x=+60"


    # Set animation keyframes

    last_frame = 600

    for frame in range(last_frame+1):

        distance = (target_location - sphere.location).length


        if distance > 0.01:

            direction = (target_location - sphere.location).normalized()

            sphere.location += direction * min(speeds[i], distance)

            sphere.keyframe_insert(data_path="location", frame=frame)


# Function to set the number of frames

def set_frame_range(start_frame, end_frame):

    bpy.context.scene.frame_start = start_frame

    bpy.context.scene.frame_end = end_frame


# Example: set the number of frames to 1000

set_frame_range(1, 1000)


線路レール

 




import bpy

import math

from mathutils import Vector

from math import radians


zion_collection_name = "cylinder "


# Create the collection

col = bpy.data.collections.new(zion_collection_name)

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


# Set target location

target_location = Vector((0, 0, 60))


# Set initial locations

initial_locations = [ Vector((0, 0, 0))]


# Set cylinder properties

cylinder_radius = 1

cylinder_depth = 240


# Calculate speeds based on initial distances

chousei_kijyun = 60

distances = [math.sqrt(sum([(a - b) ** 2 for a, b in zip(loc, target_location)])) for loc in initial_locations]

speeds = [0.1 * distance / chousei_kijyun if distance > 0 else 0 for distance in distances]


# Create cylinder objects and set locations

for i, initial_location in enumerate(initial_locations):

    bpy.ops.mesh.primitive_cylinder_add(radius=cylinder_radius, depth=cylinder_depth)

    cylinder = bpy.context.object

    cylinder.location = initial_location

    cylinder.name = "線路 rail"


    # Rotate cylinder by 90 degrees around the y-axis

    cylinder.rotation_euler.rotate_axis('Y', radians(90))


    # Set animation keyframes

    last_frame = 600

    for frame in range(last_frame+1):

        distance = (target_location - cylinder.location).length

        if distance > 0.01:

            direction = (target_location - cylinder.location).normalized()

            cylinder.location += direction * min(speeds[i], distance)

            cylinder.keyframe_insert(data_path="location", frame=frame)


# Set the number of frames

def set_frame_range(start_frame, end_frame):

    bpy.context.scene.frame_start = start_frame

    bpy.context.scene.frame_end = end_frame


# Example: set the number of frames to 1000

set_frame_range(1, 1000)






2つのトーラス

 

import bpy

import math

from mathutils import Vector


# Set target location

target_location = Vector((0, 0, 60))


# Set initial locations

initial_locations = [Vector((0, 0, 0)), Vector((0, 0, -30))]


# Set torus properties

torus_major_radius = 60

torus_minor_radius = 1


# 初期位置との距離から速度を計算する

chousei_kijyun = 60

distances = [math.sqrt(sum([(a - b) ** 2 for a, b in zip(loc, target_location)])) for loc in initial_locations]

speeds = [0.1 * distance / chousei_kijyun if distance > 0 else 0 for distance in distances]


# Create torus objects and set locations

for i, initial_location in enumerate(initial_locations):

    bpy.ops.mesh.primitive_torus_add(major_radius=torus_major_radius, minor_radius=torus_minor_radius)

    torus = bpy.context.object

    torus.location = initial_location


    torus = bpy.context.object

    if i == 0:

        torus.name = "torus 上面 z=0位置"

    else:

        torus.name = "torus 追いつく"


    # Set animation keyframes

    last_frame = 600

    for frame in range(last_frame+1):

        distance = (target_location - torus.location).length

        if distance > 0.01:

            direction = (target_location - torus.location).normalized()

            torus.location += direction * min(speeds[i], distance)

            torus.keyframe_insert(data_path="location", frame=frame)


# Function to set the number of frames

def set_frame_range(start_frame, end_frame):

    bpy.context.scene.frame_start = start_frame

    bpy.context.scene.frame_end = end_frame


# Example: set the number of frames to 1000

set_frame_range(1, 1000)



torus.name = "torus 追いつかない"



import bpy

import math


zion_collection_name = "torus "


# コレクションを作成する

col = bpy.data.collections.new(zion_collection_name)

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






import bpy

import math

from mathutils import Vector


# Set target location

target_location = Vector((0, 0, 30))


# Set initial locations

initial_locations = [ Vector((0, 0, -30))]


# Set torus properties

torus_major_radius = 60

torus_minor_radius = 1


# 初期位置との距離から速度を計算する

chousei_kijyun = 60

distances = [math.sqrt(sum([(a - b) ** 2 for a, b in zip(loc, target_location)])) for loc in initial_locations]

speeds = [0.1 * distance / chousei_kijyun if distance > 0 else 0 for distance in distances]


# Create torus objects and set locations

for i, initial_location in enumerate(initial_locations):

    bpy.ops.mesh.primitive_torus_add(major_radius=torus_major_radius, minor_radius=torus_minor_radius)

    torus = bpy.context.object

    torus.location = initial_location


    torus = bpy.context.object

    torus.name = "torus 追いつかない"


    # Set animation keyframes

    last_frame = 600

    for frame in range(last_frame+1):

        distance = (target_location - torus.location).length

        if distance > 0.01:

            direction = (target_location - torus.location).normalized()

            torus.location += direction * min(speeds[i], distance)

            torus.keyframe_insert(data_path="location", frame=frame)


# Function to set the number of frames

def set_frame_range(start_frame, end_frame):

    bpy.context.scene.frame_start = start_frame

    bpy.context.scene.frame_end = end_frame


# Example: set the number of frames to 1000

set_frame_range(1, 1000)



半径 √2の トーラス

  import bpy import math # 半径√2 major_radius = math.sqrt(2) # マイナー半径0.2 minor_radius = 0.05 # トーラスを作成 bpy.ops.mesh.primitive_torus_add(major...