# -*- coding: cp949 -*-
#작은 전류 요소에 의한 자기장
#저자:
#날짜: 2016-12-01
from visual import *
scene.height = scene.width = 800
L = 5.
scene.range = L
#상수
m_const = 1.e-7 #자기 상수
#작은 전류 요소
source_current = 1. #전류(암페어)
source_axis = vector(0, 0.01*L, 0) #dl 벡터
source_pos = vector(0,-10*L,0) #위치
curve(pos=[(0, -10*L, 0),(0, 10*L, 0)], color=color.green)#dl 방향 연장선
#관찰 위치
c_L=20*L
obs_radius = sphere(pos=scene.mouse.getclick().pos, radius= 0.01*L, color= color.red)#관찰 위치 반지름
d_theta = pi/3.
length = 2.*L #자기장을 그릴 전체 거리
obs_y = -10.*L #최초 관찰 위치 y 좌표
dy = c_L/(100*L)#관찰 위치 증가분
obs = [vector(0,-10*L,0)] #관찰 위치 리스트
obs1 = vector(0,-10*L,0)
while obs1.y < 10.*L:
rate(100)
obs1.y += dy
obs.append( vector(0,obs1.y,0) )
#자기장
scale_factor_m = 2.e-10 #자기장 화살표 스케일
m_field_origin = 0
i = 0
while i<=500:
obs_radius.pos = scene.mouse.getclick().pos
r = obs[i] - obs_radius.pos #전류에서 보는 관찰 점의 상대 위치
r_hat = r/mag(r) #상대위치의 단위 벡터
m_field = m_const*source_current*dy*obs_radius.pos.x/(mag(r)**3)#자기장
m_field_origin += m_field
i=i+1
print m_field
print "유한한 길이의 도선에 의한 자기장= ", m_field_origin
m_inf_field = 4.*pi*10**-7*source_current/(2.*pi*obs_radius.pos.x)
print "무한한 길이의 도선에 의한 자기장= ",m_inf_field
print "Done!!!"
In this source, If I click anywhere, the result(m_field_origin, m_inf_field) is printed. I run this source. when I click anywhere, the result is not printed two magnetic field. If I remove "obs_radius.pos = scene.mouse.getclick().pos" in 'while form', the result is printed two magnetic field. What is problem? I want to two magnetic field values whenever click anywhere.