Modeling Magnetism

Let's say that I have p-nodes on a two-dimensional pixel surface of size n by m, I want the nodes to be pulled together, so the further they separate the strong appeal. But if the distance between two nodes, say d (A, B) is less than a certain threshold value k, then they begin to reflect. Could someone get me to start with some code on how to update the coordinates of nodes over time.

I have something like the code below that is starting to get attention, but looking for some tips. (PS I can not use the existing library for 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);
  }
 }
}

}


}
+3
source share
2 answers

, .

+2

, p- n m, , , . , , d (A, B) k, .

, , , ?

- , .

, , .

. , 2D, , , , , , ,

2D-, , , . - ?

"" , , .

- . "Numerical Recipes" , .

"NR" . , .

+2

Source: https://habr.com/ru/post/1729788/


All Articles