Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Programming assistance needed. Hello, I\'m struggling to get some items i

ID: 3763923 • Letter: P

Question

Python Programming assistance needed.

Hello, I'm struggling to get some items in an array to do what I want. Basically I have some arrow objects hitting a wall and based on a random chance the arrow will either stick in the wall or pass through it ( This is actually an attempt to model photons passing through iron). My problem is that I cant seem to get any arrows to stick in the wall, they just pass through so I switched from a For loop to a while loop and now i'm not getting anything going here. Any help would be greatly appreciated. Thank you.

from __future__ import division, print_function
from visual import *
from time import clock
from visual.graph import *
from random import random

import random

##

#Constants that if tinkered with will break the program.
a=0.00001
b=1
dt=.01
t=1
i=1

#Constants
# I is for Intensity of Light
I=32

#Natoms is for the number of atoms in a specified barrier
Natoms=5
PropC=1
Npe=0
C= vector(2,0,0)

#Create barrier parameters
Height =4
Width =2
Depth =3

scene = display(width=600, height=600)


Photons = []
Natoms =[]
poslist = []
vlist= []
v = []

wall = box(pos=(1,2,1.5), length= Width, height= Height, width= Depth, color = color.blue)

#Loops and things


for i in range (I):
x= -5
j=random.randint(0,100)
yj= j/100
y= Height* yj
k=random.randint(0,100)
zk=k/100
z= Depth*zk
Photons = Photons + [arrow(pos=(x,y,z), color= color.yellow, make_trail=True)]
poslist.append((x,y,z))
vlist.append(vector(.2,0,0))
  


pos = array(poslist)


while t < 5:
rate(1e2)
  
pos=pos+C*dt


while i <= I
Photons[i].pos = pos[i]
i=i+1
if Photons[i].pos.x >= wall.pos.x:
v = random.randint(1,10)
if v > 4:
Photons.remove[Photons[i]]
i=i+1

  
#print(poslist)


t=t+dt
  


  
# Natoms = I*Natoms*PropC
  
  

Explanation / Answer

while i <= I
Photons[i].pos = pos[i]
i=i+1
if Photons[i].pos.x >= wall.pos.x:
v = random.randint(1,10)
if v > 4:
Photons.remove[Photons[i]]
i=i+1   

There might be a possibility , Photons[i].pos.x < wall.pos.x means no photon is reaching the wall. so i did not see you handle such conditions.