- #1
clope023
- 992
- 132
A radiation source at some point through the collimator of a detector.
Modeled as 100 spheres tracing out the image of a circle on a plane some distance above the original position of the source.
What I want to do is collect all the spheres that go through the top of a cylinder and then calculate the area of the circle that they create. Afterwords I would move the source to 5 different positions and trace the area of the circles created by the intersection of the different solid angle planes.
This is my vpython code so far:
from visual import *
from random import uniform
f = frame()
c1 = cylinder(frame = f, pos = (0,5,0), axis = (0,2,0), radius = 7, thickness = 0.2, color = color.cyan)
#c2 = cylinder(frame = f, pos = (0,5,0), axis = (0,0.1,0), radius = 2, thickness = 0.2, color = color.cyan)
ball_list = []
ball_list2 = []
ball_list3 = []
ball_list4 = []
ball_list5 = []
n = 100
ball_rad = 0.01
dt = 0.01
t = 0
maxpos = 2
maxvel = 2
def draw_point():
phi = random.uniform()*2*pi
r = random.uniform()-0.5
ct = 0.9 + 0.2*r
theta = arccos(ct)
rr = sin(theta)
x = rr*cos(phi)
y = ct
z = rr*sin(phi)
return (x,y,z)
for i in range(n):
ball = sphere(color=color.red, radius = ball_rad)
ball.trail = curve(color=color.yellow)
ball.pos = maxpos*vector(0,0,0)
ball.velocity = maxvel*vector(draw_point())
#ball2 = sphere(color=color.red, radius = ball_rad)
#ball2.trail = curve(color=color.orange)
#ball2.pos = vector(2,0,0)
#ball2.velocity = vector(draw_point())
#ball3 = sphere(color=color.red, radius = ball_rad)
#ball3.trail = curve(color=color.blue)
#ball3.pos = vector(-2,0,0)
#ball3.velocity = vector(draw_point())
#ball4 = sphere(color=color.red, radius = ball_rad)
#ball4.trail = curve(color=color.magenta)
#ball4.pos = vector(4,0,0)
#ball4.velocity = vector(draw_point())
#ball5 = sphere(color=color.red, radius = ball_rad)
#ball5.trail = curve(color=color.green)
#ball5.pos = vector(-4,0,0)
#ball5.velocity = vector(draw_point())
rate(100)
for t in range(1000):
ball.pos += ball.velocity*dt
#ball2.pos += ball2.velocity*dt
#ball3.pos += ball3.velocity*dt
#ball4.pos += ball4.velocity*dt
#ball5.pos += ball5.velocity*dt
ball.trail.append(pos=ball.pos)
#ball2.trail.append(pos=ball2.pos)
#ball3.trail.append(pos=ball3.pos)
#ball4.trail.append(pos=ball4.pos)
#ball5.trail.append(pos=ball5.pos)
if ball.y > c1.axis:
ball.velocity = 0*ball.velocity
Are there any suggestions to make this more streamlined? Any help is appreciated.
Modeled as 100 spheres tracing out the image of a circle on a plane some distance above the original position of the source.
What I want to do is collect all the spheres that go through the top of a cylinder and then calculate the area of the circle that they create. Afterwords I would move the source to 5 different positions and trace the area of the circles created by the intersection of the different solid angle planes.
This is my vpython code so far:
from visual import *
from random import uniform
f = frame()
c1 = cylinder(frame = f, pos = (0,5,0), axis = (0,2,0), radius = 7, thickness = 0.2, color = color.cyan)
#c2 = cylinder(frame = f, pos = (0,5,0), axis = (0,0.1,0), radius = 2, thickness = 0.2, color = color.cyan)
ball_list = []
ball_list2 = []
ball_list3 = []
ball_list4 = []
ball_list5 = []
n = 100
ball_rad = 0.01
dt = 0.01
t = 0
maxpos = 2
maxvel = 2
def draw_point():
phi = random.uniform()*2*pi
r = random.uniform()-0.5
ct = 0.9 + 0.2*r
theta = arccos(ct)
rr = sin(theta)
x = rr*cos(phi)
y = ct
z = rr*sin(phi)
return (x,y,z)
for i in range(n):
ball = sphere(color=color.red, radius = ball_rad)
ball.trail = curve(color=color.yellow)
ball.pos = maxpos*vector(0,0,0)
ball.velocity = maxvel*vector(draw_point())
#ball2 = sphere(color=color.red, radius = ball_rad)
#ball2.trail = curve(color=color.orange)
#ball2.pos = vector(2,0,0)
#ball2.velocity = vector(draw_point())
#ball3 = sphere(color=color.red, radius = ball_rad)
#ball3.trail = curve(color=color.blue)
#ball3.pos = vector(-2,0,0)
#ball3.velocity = vector(draw_point())
#ball4 = sphere(color=color.red, radius = ball_rad)
#ball4.trail = curve(color=color.magenta)
#ball4.pos = vector(4,0,0)
#ball4.velocity = vector(draw_point())
#ball5 = sphere(color=color.red, radius = ball_rad)
#ball5.trail = curve(color=color.green)
#ball5.pos = vector(-4,0,0)
#ball5.velocity = vector(draw_point())
rate(100)
for t in range(1000):
ball.pos += ball.velocity*dt
#ball2.pos += ball2.velocity*dt
#ball3.pos += ball3.velocity*dt
#ball4.pos += ball4.velocity*dt
#ball5.pos += ball5.velocity*dt
ball.trail.append(pos=ball.pos)
#ball2.trail.append(pos=ball2.pos)
#ball3.trail.append(pos=ball3.pos)
#ball4.trail.append(pos=ball4.pos)
#ball5.trail.append(pos=ball5.pos)
if ball.y > c1.axis:
ball.velocity = 0*ball.velocity
Are there any suggestions to make this more streamlined? Any help is appreciated.