Try   HackMD

帶電粒子在磁場中的運動

作者:王一哲
日期:2018/5/12


帶電粒子在均勻磁場中所受磁力為

FB=q(v×B)  FB=qvBsinθ

其中

q 為粒子電量、
v0
為粒子速度、
B
為外加磁場。可能的運動方式有3種:

  1. θ=0
    180
    FB=0
    ,等速度直線運動
  2. θ=90
    FB=qvB
    ,等速率圓周運動
  3. 其它角度:螺線運動,一邊繞圓圈一邊前進

這次的目標就是畫出這3種運動狀態,而且動畫視窗的視角會自動隨著速度與磁場的夾角轉至方便觀察的方向。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
螺線運動示意圖

程式 22-1.帶電粒子在磁場中的運動 (取得程式碼) (GlowScript 網站動畫連結

""" VPython教學: 22-1.帶電粒子在磁場中的運動 Ver. 1: 2018/4/8 Ver. 2: 2019/9/16 作者: 王一哲 """ from vpython import * """ 1. 參數設定, 設定變數及初始值 (1) 速度只有 x 方向分量, 沿著 x 軸等速度運動: theta = 0, phi = 0 (2) 速度沒有 x 方向分量, 在 yz 平面上做等速圓周運動: theta = 90, phi = 0 (3) 速度沒有 x 方向分量, 在 yz 平面上做等速圓周運動: theta = 0, phi = 90 (4) 速度與 x 軸夾角 != 0 or 180, 螺線運動, e.g. theta = 80, phi = 80 (5) 速度與 x 軸夾角 != 0 or 180, 螺線運動, e.g. theta = 100, phi = 80 """ size, m, q = 0.005, 1E-10, 1E-9 # 粒子半徑, 質量, 電量 theta = radians(80) # 粒子初速度與 xy 平面夾角 phi = radians(80) # 粒子初速度在 xy 平面投影與 x 軸夾角 v0 = 10*vec(cos(theta)*cos(phi), cos(theta)*sin(phi), sin(theta)) # 粒子初速度 L = 0.4 # 坐標軸長度 B_field = vec(10, 0, 0) # 磁場 t, dt = 0, 1E-5 # 時間, 時間間隔 """ 2. 畫面設定 """ # 產生動畫視窗, 依照 theta 和 phi 旋轉視角 scene = canvas(title="Charged Particle in Magnetic Field", width=800, height=600, x=0, y=0, center=vec(0, 0, 0), range=0.6*L, background=color.black) if(theta == pi/2 or phi == pi/2): scene.camera.pos = vec(L, L/4, L/4) scene.camera.axis = vec(-L, -L/4, -L/4) else: scene.camera.pos = vec(L/4, L/4, L) scene.camera.axis = vec(-L/4, -L/4, -L) # 產生帶電粒子 charge = sphere(pos=vec(0, 0, 0), radius=2*size, v=v0, color=color.red, m=m, make_trail=True, retain = 1000) # 產生坐標軸及標籤 arrow_x = arrow(pos=vec(-L/2, 0, 0), axis=vec(L, 0, 0), shaftwidth=0.6*size, color=color.yellow) label_x = label(pos=vec(L/2, 0, 0), text="x", xoffset=25, color=color.yellow, font="sans") arrow_y = arrow(pos=vec(0, -L/2, 0), axis=vec(0, L, 0), shaftwidth=0.6*size, color=color.yellow) label_y = label(pos=vec(0, L/2, 0), text="y", yoffset=25, color=color.yellow, font="sans") arrow_z = arrow(pos=vec(0, 0, -L/2), axis=vec(0, 0, L), shaftwidth=0.6*size, color=color.yellow) label_z = label(pos=vec(0, 0, L/2), text="z", xoffset=-25, yoffset=-25, color=color.yellow, font="sans") # 產生表示磁場的箭頭及標籤 arrow_B = arrow(pos=vec(-L/2, 0, 0), axis=B_field.norm()*0.1, shaftwidth=size, color=color.green) label_B = label(pos=vec(-L/2, 0, 0), text="B", xoffset=25, yoffset=25, color=color.green, font="sans") # 產生表示速度、加速度的箭頭 arrow_v = arrow(pos=charge.pos, shaftwidth=0.5*size, color=color.blue) arrow_a = arrow(pos=charge.pos, shaftwidth=0.5*size, color=color.magenta) """ 3. 物體運動部分 """ while(abs(charge.pos.x) < 0.6*L and abs(charge.pos.y) < 0.6*L and abs(charge.pos.z) < 0.6*L): rate(500) # 計算帶電粒子所受合力, 更新帶電粒子加速度、速度、位置 F = q*cross(charge.v, B_field) charge.a = F/charge.m charge.v += charge.a*dt charge.pos += charge.v*dt # 更新表示速度、加速度的箭頭, 只畫出方向以避免動畫自動縮小 arrow_v.pos = charge.pos arrow_a.pos = charge.pos arrow_v.axis = charge.v.norm()*0.1 arrow_a.axis = charge.a.norm()*0.1 # 更新時間 t += dt

參數設定

在此設定變數為size、m、theta、phi、v0、q、L、B_field、t、dt,用途已寫在該行的註解當中。為了使動畫較為順暢,刻意將粒子的電量、質量調大很多。


畫面設定

  1. 產生動畫視窗,依照 theta 和 phi 旋轉視角,條件設定為 theta == pi/2 or phi == pi/2,若條件成立則由 (L, L/4, L/4) 朝原點觀察,若條件不成立則由 (L/4, L/4, L) 朝原點觀察。
  2. 產生帶電粒子並設定初速度。
  3. 產生坐標軸及標籤。
  4. 產生表示磁場的箭頭及標籤。
  5. 產生表示速度、加速度的箭頭。

物體運動

  1. 由於我希望粒子只在邊長為 1.2 L 的正立方體空間中運動,到達邊緣時停止,因此將 while 迴圈當中的條件設定為 abs(charge.pos.x) < 0.6*L and abs(charge.pos.y) < 0.6*L and abs(charge.pos.z) < 0.6*L
  2. 計算帶電粒子所受合力,更新帶電粒子加速度、速度、位置。
  3. 更新表示速度、加速度的箭頭,只畫出方向以避免動畫自動縮小。
  4. 更新時間。

模擬結果

以下是5種不同的數據組合及測試結果:

  1. theta = 0, phi = 0 ⇒ 速度只有 x 方向分量,沿著 x 軸等速度運動
  2. theta = 90, phi = 0 ⇒ 速度沒有 x 方向分量,在 yz 平面上做等速圓周運動
  3. theta = 0, phi = 90 ⇒ 速度沒有 x 方向分量,在 yz 平面上做等速圓周運動
  4. theta = 80, phi = 10 ⇒ 速度與 x 軸夾角不於 0 度或 180度,螺線運動
  5. theta = 100, phi = 10 ⇒ 速度與 x 軸夾角不於 0 度或 180度,螺線運動
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
程式 21-1 數據組合1畫面截圖

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
程式 21-1 數據組合2畫面截圖

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
程式 21-1 數據組合3畫面截圖

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
程式 22-1 數據組合4畫面截圖

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
程式 22-1 數據組合5畫面截圖

結語

除了以上幾種角度之外,還可以試著改成其它的角度,例如 theta = 80, phi = 40,觀察粒子的運動軌跡會有什麼變化。


VPython官方說明書

  1. canvas: http://www.glowscript.org/docs/VPythonDocs/canvas.html
  2. box: http://www.glowscript.org/docs/VPythonDocs/box.html
  3. cylinder: http://www.glowscript.org/docs/VPythonDocs/cylinder.html
  4. sphere: http://www.glowscript.org/docs/VPythonDocs/sphere.html
  5. arrow: http://www.glowscript.org/docs/VPythonDocs/arrow.html
  6. label: http://www.glowscript.org/docs/VPythonDocs/label.html

tags:VPython