problem`s causes..

19 views
Skip to first unread message

별과바람

unread,
Dec 7, 2016, 3:00:16 AM12/7/16
to VPython-users
# -*- coding: cp949 -*-
#움직이는 점전하의 자기장
#한 순간의 자기장 분포
#저자: 
#날짜: 2016-12-01

from visual import *
scene.height = scene.width = 800
L = 5.e-9
scene.range = L

#상수
m_const = 1.e-7 #자기 상수

#전하
source = sphere(radius=0.08*L, color=color.red, opacity=0.6)
source.q = 1.6e-19#전하량
source.pos = vector(0, 0, 0)#위치
source.v = vector(0, 1.e-8, 0) #y 방향 속도
scale_factor_v = 2.e-12 #속도 화살표 스케일
arrow(pos=source.pos, color=color.green, axis=scale_factor_v*source.v)#속도 화살표
curve(pos=[(0, -10*L, 0),(0, 10*L, 0)], color=color.green)#전하의 궤적
source1 = vector(0,0,0)

scene.waitfor('click')     # wait for a click

#관찰 위치
obs_radius = 0.4*L #관찰 위치 반지름
dt=0.01
d_theta = pi/3 #각도 증가분
length = 2*L #자기장을 그릴 전체 거리
obs_y = source.pos.y - length/4 #가장 아래 관찰 위치 y 좌표
dy = length/4 #관찰 위치 증가분
obs = [] #관찰 위치 리스트
obs1 = [vector(0,0,0),vector(0,0,0),vector(0,0,0),vector(0,0,0),vector(0,0,0),vector(0,0,0),vector(0,0,0)+dt*source.v,vector(0,0,0)+dt*source.v,vector(0,0,0)+dt*source.v,vector(0,0,0)+dt*source.v,vector(0,0,0)+dt*source.v,vector(0,0,0)+dt*source.v,vector(0,0,0)+2*dt*source.v,vector(0,0,0)+2*dt*source.v,vector(0,0,0)+2*dt*source.v,vector(0,0,0)+2*dt*source.v,vector(0,0,0)+2*dt*source.v,vector(0,0,0)+2*dt*source.v] #전하의 위치 리스트
scene.waitfor('click')     # wait for a click
while obs_y < length/2:
    rate(10)
    theta = 0
    while theta < 2*pi:
        rate(100)
        r0 = vector(obs_radius*cos(theta), obs_y, obs_radius*sin(theta))
        obs.append(r0)
        theta += d_theta
    obs_y += dy




#자기장  
scale_factor_m = 5.e7
#자기장 화살표 스케일
i=0
while i<=17 :
    rate(10)
    if i == 17:
        source.pos += dt*source.v
        i = 0
    r = obs[i] - source.pos #전하에서 보는 관찰 점의 상대 위치
    r_hat = r/mag(r) #상대위치의 단위 벡터 
    m_field = m_const*source.q*cross(source.v,r_hat)/mag(r)**2 #자기장
    arrow(pos=obs[i], color=color.orange, axis=scale_factor_m*m_field)#자기장 화살표
    i += 1
    if source.pos == source.pos+2*dt*source.v:
        break
print "Done!!!"

I made program that print "change of magnetic field due to charge movement". Arrow show "Change of magnetic field due to charge movement". When I run program , arrow is overlap. 
1. Why is this problem happening?
2. How can I remove this problem?..

I would appreciate your teaching..

Bruce Sherwood

unread,
Dec 7, 2016, 7:59:54 PM12/7/16
to VPython-users
It appears that you create a new arrow at the location obs[i] instead of changing an arrow originally created at that location. Again, study the video "Lists, Part 2" at vpython.org.
Reply all
Reply to author
Forward
0 new messages