磁性模拟 [英] magnetism simulation

查看:178
本文介绍了磁性模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在一个n×m像素的二维表面上有p个节点,我希望这些节点彼此吸引,这样它们就越远离吸引力。但是如果两个节点之间的距离,比如d(A,B)小于某个阈值k,那么它们开始排斥。任何人都可以让我着手一些关于如何随着时间的推移更新节点坐标的代码。



我有点像下面的代码,它开始做吸引力,但寻找一些建议。 (P.S.我不能使用现有的库来做到这一点)。

pre $ public c $ c
float pos;
float posY;
}

公共类mySimulator {

ArrayList< node> myNodes = new ArrayList< node>();

//假设我向myNodes添加了一些节点
myNodes.add(.....

//现在,图像是更新例程,在每个固定时间增量处被调用

public void updateLocations(){
for(int i = 0; i< = myNodes.size(); i ++){
for (i = 0; i <= myNodes.size(); i ++){
myNodes.get(i).posX = myNodes.get(i).posX +some constant*(myNodes.get (j).posX -myNodes.get(i).posX);
myNodes.get(i).posY = myNodes.get(i).posY +some constant*(myNodes.get(j) .posY -myNodes.get(i).posY);
}
}
}

}


}


解决方案

kinetic model 与磁性完全无关,但是这个设计可能会给你一些建模相互作用粒子集合的想法。 / p>

Say I have p nodes on a n by m pixel 2D surface, I want the nodes to be attracted to each other such that the further they are apart the strong the attraction. But if the distance between two nodes, say d(A,B) is less than some threshold say k then they start to repel. Could anyone get me started on some code on how to update the co-ordinates of the nodes over time.

I have something a little like the code below which is start to do the attraction, but looking for some advice. (P.S. I can not use an existing library to do this).

public class node{
 float posX;
 float posY;
}

public class mySimulator{

ArrayList<node> myNodes = new ArrayList<node>();

// Imagine I add a load of nodes to myNodes
myNodes.add(.....

// Now image this is the updating routine that is called at every fixed time increment

public void updateLocations(){
 for(int i =0; i <= myNodes.size(); i++){
  for(int i =0; i <= myNodes.size(); i++){
  myNodes.get(i).posX = myNodes.get(i).posX + "some constant"*(myNodes.get(j).posX -myNodes.get(i).posX);
  myNodes.get(i).posY = myNodes.get(i).posY + "some constant"*(myNodes.get(j).posY -myNodes.get(i).posY);
  }
 }
}

}


}

解决方案

This kinetic model of elastic collisions is completely unrelated to magnetism, but the design might give you some ideas on modeling an ensemble of interacting particles.

这篇关于磁性模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆