2023年4月8日土曜日

線路レール

 




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)









Y=-30 観察レール


import bpy

import math

from mathutils import Vector

from math import radians



# Set target location

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


# Set initial locations

initial_locations = [ Vector((0, -30, 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))




半径 √2の トーラス

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