2023年4月8日土曜日

逆さ円錐用 ボール位置 幻想速度

 

import bpy
import math


zion_collection_name = "幻想 速度"

# コレクションを作成する
col = bpy.data.collections.new(zion_collection_name)
bpy.context.scene.collection.children.link(col)







import bpy

import math

from mathutils import Vector


# 目標位置を指定する

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


# 初期位置のリスト

initial_locations = [

    Vector((30, 0, 0)),

    Vector((60, 0, 0)),

    Vector((0, 0, 0)),

    Vector((-30, 0, 0)),

    Vector((-60, 0, 0))

]


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

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]


# 球体の作成と初期位置の設定

bpy.ops.object.empty_add(type='PLAIN_AXES')

empty = bpy.context.object

for index, loc in enumerate(initial_locations):

    sphere = bpy.ops.mesh.primitive_uv_sphere_add(radius=3, location=loc)

    obj = bpy.context.object

    obj.name = f"Sphere {index+1}"

    obj.parent = empty


# アニメーションの作成

last_frame = 600

for frame in range(last_frame+1):

    for obj in empty.children:

        if obj.name.startswith("Sphere"):

            distance = (target_location - obj.location).length

            if distance > 0.01:

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

                obj.location += direction * min(speeds[int(obj.name[-1])-1], distance)

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







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

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