Commit 81167d01 authored by Rafael Peretti Pezzi's avatar Rafael Peretti Pezzi

Particle propagator class and its use in Blender animation

parent 6b4e2a3b
......@@ -15,16 +15,17 @@ import os
filename = os.path.join(os.path.basename(bpy.data.filepath), "particle.py")
exec(compile(open(filename).read(), filename, 'exec'))
t_video=20 # duração da animação em segundos
t_simulado=86400*365*5 # tempo próprio da simulação em segundos
t_video=10 # duração da animação em segundos
t_simulado=10
fps = 24 # quadros por segundo
N_quadros=t_video*fps # calculando numero de quadros totais
delta_t=t_simulado/N_quadros # tempo passado por quadro
# Particle radius
r_part = 0.05
r_part = 0.10
# Function that creates Blender Objects from input list of particles.
## Returns a list of blender objects
def create(particles):
bpy.context.scene.render.fps=fps
bpy.context.scene.frame_start = 0
......@@ -40,7 +41,7 @@ def create(particles):
blender_particles.append(this_particle)
return blender_particles
# Function that animates the scene using the particle propagator class
def animate(objects):
#Animate particles
for f in range(1, N_quadros):
......@@ -48,19 +49,25 @@ def animate(objects):
bpy.context.scene.frame_current = f
for i in range(0, len(objects)):
bpy.context.scene.objects.active=objects[i]
objects[i].location=(0.01*f,0.05*i,0.0000005*i*i*f*f) # Dummy positions
objects[i].location=(particles[i].Propagate(t))
objects[i].keyframe_insert(data_path='location')
#Remove cube
# Remove cube
bpy.data.objects.remove(bpy.data.objects['Cube'])
# Create particles
particles = createNparticles(30)
# Todo: Add lamp and camera in suitable positions
particles = createNparticlesProp(1000)
# Create blender objects
blender_particles = create(particles)
#Animate Scene
animate(blender_particles)
## Todo:
## - Lamp and cameras in suitable positions
## - Configure particle and background colors
## - Configure output format and enconding (FFmpeg & H.264 works fine)
## - Add option to keep particle trails
## - Add simple geometry of the ALICE detector
# -*- coding: utf-8 -*-
# Sample Particle class and function that creates N particles, returning a list of particles
import math
import random
# Basic particle class to store bascic information
class Particle:
def __init__(self, index, x = 0, y = 0, z = 0):
def __init__(self, index, x = 0, y = 0, z = 0, charge = 1, mass=1):
self.iDx=index
self.x=x
self.y=y
self.z=z
self.charge=charge
self.mass = mass
def PrintPosition(self):
print(str(self.x) + " ; " + str(self.y) + " ; " + str(self.z))
def GetPosition(self):
return self.x, self.y, self.z
def createNparticles(N_particles, x=0, y=0, z=0): # Create particles at given position and return them in a list
#Function that creates N particles and return them in a list
def createNparticles(N_particles, x = 0, y = 0, z = 0): # Create particles at given position and return them in a list
particles=[]
#loop sobre as partículas
#loop over particles
for i in range(0, N_particles):
part = Particle(i,x,y,z)
particles.append(part)
return particles;
# Derived class to computes the time evolution particle positions
class ParticlePropagator(Particle):
def SetMagneticField(self,B):
self.B = B
def SetMomentum(self,Px, Py, Pz):
self.Px = Px
self.Py = Py
self.Pz = Pz
def Propagate(self, time): # Todo: Add relativistic and magnetic field effects
Xprop = self.x + time*self.Px/self.mass
Yprop = self.y + time*self.Py/self.mass
Zprop = self.z + time*self.Pz/self.mass
return Xprop, Yprop, Zprop
# Function that creates N particle propagators
# Momentum values to be obtained from real data
def createNparticlesProp(N_particles, x = 0, y = 0, z = 0): # Create particles at given position and return them in a list
particles=[]
#loop over particles
for i in range(0, N_particles):
part = ParticlePropagator(i,x,y,z)
part.SetMagneticField(0.5)
part.SetMomentum(random.gauss(0,1),random.gauss(0,1),random.gauss(0,1))
particles.append(part)
return particles;
# -*- coding: utf-8 -*-
from particle import *
# Creates one particle propagator with default values
a = ParticlePropagator(0)
a.PrintPosition()
# Configure kinematics
a.SetMagneticField(0.5)
a.SetMomentum(-1.0, 2.0, 3.0)
#Print propagation
print(a.Propagate(1))
print(a.Propagate(2))
print(a.Propagate(3))
print(a.Propagate(3)[0]*2) #Acessing a single element of the result
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment