私は、VPython 2.7.9の棒のような非球形のオブジェクトを周回するボールをモデル化するコードを設計したいという問題を抱えています。VPython 2.7.9でロッドを周回するボールの位置を更新する正しいループを設計するにはどうすればよいですか?
この質問に答えるには、空間内の不規則なオブジェクト(球ではないオブジェクト)の場合、それらを塊に切り、個々に自分の塊を持つと考える必要があることを知ることが重要です。
この問題では、ロッドの質量は全体に均等に分布し、鉄でできています。ロッドの長さは20m、半径は0.1mです。その周りを周回する粒子は、それが所有する質量に応じてロッドを周回するという重要なことを望むあらゆる質量のものです。
私が働いていないコードを設計したが、私は、問題(それを実行するために使用さVIDLE)のスポットカント:
from __future__ import division
from visual import *
from visual.graph import *
#Initializing
G = 6.67e-11 #Universal constant of gravitation
#Rod
L = 20 #Lenght of rod
rod_radius = 0.1
rod_pos = vector(-10,0,0)
rod_axis = vector(L,0,0)
rod_density = 7700
rod_volume = L*pi*(rod_radius**2)
rod_mass = rod_density*rod_volume
n = 1000 #Chunks the rod is cut into
#Chunks
chunk_lenght = L/n
chunk_volume = chunk_lenght*pi*(rod_radius**2)
chunk_mass = rod_density*chunk_volume
chunk_pos_x = -10 #initial position of the first chunk
#Particle
particle_pos = vector(0,5,0)
particle_mass = 1
r = particle_pos - vector(0,0,0)
particle_vel = sqrt(G*chunk_mass/mag(r))*norm(r) #velocity of the particle
particle_mom = particle_mass*particle_vel #momentum of the particle
particle_radius = 0.5
#Objects
rod = cylinder(pos=rod_pos, axis=rod_axis, radius=rod_radius,
color=color.white)
particle = sphere(pos=particle_pos, radius=particle_radius, color=color.red,
make_trail = True)
#Define Variables
T = (2*pi*mag(r))/mag(particle_vel) #Period of a revolution
time = 0
dt = T/500
chunk_pos_list = [] #initializing list of positions of each chunk
r_list = [] #initializing list of distances from chunk to particle
M = 0
N = 0
#Main loop
while not(-10<=r.x <= 10 and -0.1<=r.y<=0.1 and -0.1<=r.z<=0.1):
rate(1000)
#Loop to generate list of the position of the chunks in the rod
while chunk_pos_x <= 10:
chunk_pos = vector(chunk_pos_x,0,0)
chunk_pos_list.append(chunk_pos)
chunk_pos_x = chunk_pos_x + chunk_lenght
#Loop to generate list of initial distance "r" of the particle from each
chunk of the rod
while M<=n:
r = chunk_pos_list[M]-particle.pos
r_list.append(r)
M = M + 1
#Loop to generate update in position of the particle
while N<=n+1:
Force_G = ((-
G*particle_mass*chunk_mass)/mag2(r_list[N]))*norm(r_list[N])
particle_mom = particle_mom + Force_G*dt
particle_vel = particle_mom/particle_mass
particle.pos = particle.pos + particle_vel*dt
time = time + dt
N = N + 1
if N=n:
N=0