外心
https://manabitimes.jp/math/628
import bpy
import math
# 大きい球体の半径
zion_big_sphere_radius = 6.0
# 小さい球体の半径
zion_small_sphere_radius = 0.1
# 大きい球体の回転数
frame_count = 600
# 小さい球体の数
zion_small_sphere_count = 360
# 小さい球体の名前
zion_small_sphere_name = "SmallSphere"
# 大きい球体の回転方向(時計回り)
zion_big_sphere_rotation_direction = -1
# 大きい球体を作成
bpy.ops.mesh.primitive_uv_sphere_add(radius=zion_big_sphere_radius, location=(0, 0, 0))
zion_big_sphere = bpy.context.object
zion_big_sphere.name = "BigSphere"
# 小さい球体を作成
for i in range(zion_small_sphere_count):
theta = i * math.pi / 180
phi = i * math.pi / 180
x = zion_big_sphere_radius * math.sin(theta) * math.cos(phi)
y = zion_big_sphere_radius * math.sin(theta) * math.sin(phi)
z = zion_big_sphere_radius * math.cos(theta)
bpy.ops.mesh.primitive_uv_sphere_add(radius=zion_small_sphere_radius, location=(x, y, z))
small_sphere = bpy.context.object
small_sphere.name = zion_small_sphere_name + "." + str(i)
# アニメーションのキーフレームを生成する
for i in range(frame_count):
# 大きい球体を回転させる
zion_big_sphere = bpy.data.objects.get("BigSphere")
if zion_big_sphere:
zion_big_sphere.rotation_euler[2] += zion_big_sphere_rotation_direction * 2 * math.pi / frame_count
zion_big_sphere.keyframe_insert(data_path="rotation_euler", frame=i)
# 小さい球体も同じ回転を加える
for j in range(zion_small_sphere_count):
small_sphere_name = zion_small_sphere_name + "." + str(j)
small_sphere = bpy.data.objects.get(small_sphere_name)
if small_sphere:
small_sphere.rotation_euler[2] += zion_big_sphere_rotation_direction * 2 * math.pi / frame_count
small_sphere.keyframe_insert(data_path="rotation_euler", frame=i)
# 小さい球体の回転速度を大きい球体に合わせる
small_sphere.rotation_euler[2] -= j * 2 * math.pi / zion_small_sphere_count
small_sphere.keyframe_insert(data_path="rotation_euler", frame=i)
# ランダム配置 球体表面に36個 球体
import bpy
import math
import random
# 大きい球体の情報
zion_big_sphere_name = "Center Sphere" # 大きい球体の名前
zion_big_sphere_radius = 2.0 # 大きい球体の半径
zion_big_sphere_location = (0, 0, 0) # 大きい球体の位置
zion_big_sphere_rotation_speed = 600 # 1回転するのに要するフレーム数
zion_big_sphere_rotation_direction = 1 # 回転方向(1: 反時計回り、-1: 時計回り)
# 小さい球体の情報
zion_small_sphere_name = "Small Sphere" # 小さい球体の名前
zion_small_sphere_count = 36 # 小さい球体の数
zion_small_sphere_radius = 0.1 # 小さい球体の半径
# 大きい球体を作成
bpy.ops.mesh.primitive_uv_sphere_add(radius=zion_big_sphere_radius, location=zion_big_sphere_location)
# 大きい球体を変数に格納
zion_big_sphere = bpy.context.object
zion_big_sphere.name = zion_big_sphere_name
# 小さい球体を作成
for i in range(zion_small_sphere_count):
# 球面座標を計算
theta = random.uniform(0, 2 * math.pi)
phi = random.uniform(0, math.pi)
x = zion_big_sphere_radius * math.sin(phi) * math.cos(theta)
y = zion_big_sphere_radius * math.sin(phi) * math.sin(theta)
z = zion_big_sphere_radius * math.cos(phi)
location = (x, y, z)
# 小さい球体を作成
bpy.ops.mesh.primitive_uv_sphere_add(radius=zion_small_sphere_radius, location=location)
# 小さい球体を大きい球体の子オブジェクトにする
zion_small_sphere = bpy.context.object
zion_small_sphere.name = zion_small_sphere_name + "." + str(i)
zion_small_sphere.parent = zion_big_sphere
# アニメーションを作成
frame_count = zion_big_sphere_rotation_speed
for i in range(frame_count):
# 大きい球体を回転させる
zion_big_sphere.rotation_euler.rotate_axis("Z", zion_big_sphere_rotation_direction * 2 * math.pi / frame_count)
# 小さい球体を大きい球体の表面に沿って移動させる
for j in range(zion_small_sphere_count):
small_sphere_name = zion_small_sphere_name + "." + str(j)
small_sphere = bpy.data.objects[small_sphere_name]
sphere_phi = math.acos(small_sphere.location[2] / zion_big_sphere_radius)
sphere_theta = math.atan2(small_sphere.location[1], small_sphere.location[0]) + zion