1

我正在做一个使用 C++ 创建磁场线的项目。我使用过 C++ 的计算部分(并不真正关心设计或任何太花哨的东西),但我在创建磁场线时遇到了麻烦。我不确定如何对涉及交叉产品的东西进行建模

洛伦兹力 eqn:F = q(vx B)

我已经研究了可能的方法,例如改变半径相对于场的步长,但我也觉得我需要找到一种方法来改变场出现的角度。

我只想模拟一个简单的偶极磁铁。我会使用 C++ 生成点,然后将它们保存为 txt 文件并使用 gnu plot 绘制它们。任何帮助将不胜感激。

4

2 回答 2

0

我会这样开始:

对于您要创建的每条场线,从一个极附近的电荷(例如电子)开始,然后求解微分方程的初始值系统(例如 Runge-Kutta),直到到达另一极。这是一条线。

重复使用不同的起点(靠近一个极点)。

我正在谈论的方程的初始值系统是:

F = q( v x B )

d v / dt = (q/m) ( v x B )

希望这是一个好的开始。(我不会详细介绍 RK 方法,因为你提到你熟悉计算部分,如果你不熟悉它,它很受欢迎,所以你应该可以毫不费力地搜索它)

于 2012-04-10T20:39:50.480 回答
0

As GuyGreer suggests, you can start at a source and follow the field to the sink. A field line follows the vector of the field at every point, so ideally you would consider not just the direction of the field at the point but also the gradient of the field; otherwise you will need more points to obtain an accurate line.

An alternative method would be to draw a straight line from source to sink, and move along its length checking the field vector is aligned with the field line. Where it is not, break the line into two segments and move the centre point; in effect you are moving the line around to find the field line, and adding more line segments where it wiggles more. Ideally go with splines or some other curve.

You mention cross products. If you can obtain the value of a field vector at a point as a 3d vector, then its cross product with another vector is just the standard definition of a cross product:

// given vectors a and b with properties x, y and z representing the components
cross.x = a.y * b.z - a.z * b.y;
cross.y = a.z * b.x - a.x * b.z;
cross.z = a.x * b.y - a.y * b.z;
于 2012-04-10T21:17:27.100 回答