我正在尝试在Mathematica中编写一个程序,它将模拟带电球轴承在充电时充电的方式(它们相互排斥).到目前为止,我的程序使滚珠轴承不会从屏幕上移开,并计算它们撞到盒子侧面的次数.到目前为止,我的球轴承随机移动,但我需要知道如何使它们相互排斥.
到目前为止,这是我的代码:
Manipulate[
(*If the number of points has been reduced, discard points*)
If[ballcount < Length[contents],
contents = Take[contents, ballcount]];
(*If the number of points has been increased, generate some random points*)
If[ballcount > Length[contents],
contents =
Join[contents,
Table[{RandomReal[{-size, size}, {2}], {Cos[#], Sin[#]} &[
RandomReal[{0, 2 \[Pi]}]]}, {ballcount - Length[contents]}]]];
Grid[{{Graphics[{PointSize[0.02],
(*Draw the container*)
Line[size {{-1, -1}, {1, -1}, {1, 1}, {-1, 1}, {-1, -1}}],
Blend[{Blue, Red}, charge/0.3],
Point[
(*Start the main dynamic actions*)
Dynamic[
(*Reset the collision counter*)
collision …Run Code Online (Sandbox Code Playgroud)