I simulate a vector field in a flash and create a mess of particles to visualize the flow of the field. Using the vector field F (x, y) = yi-xj
This vector field has a curl, the particles must move in the circles that they perform. My problem is that the particles diverge from the origin, although this particular vector field has no divergence. I suspect that my data types may lose decimal precision during the most basic cases for this field, or perhaps I am mistaken in a logical error. I'm not sure.
This code produces particles on the screen (this is 800x450). This code is probably not in trouble, but for completeness I have included it.
var i:int;
var j:int;
var spread:Number;
spread = 10.0;
for (i=0; i<=800/spread; i++)
{
for (j=0; j<=450/spread; j++)
{
var iPos:Number = spread * Number(i) - 400.0;
var jPos:Number = 225.0 - spread * Number(j);
var particle:dot = new dot(iPos,jPos,10.0);
addChild(particle);
}
}
This is the point class, which contains everything that is important for the generated particles.
package
{
import flash.display.MovieClip;
import flash.events.Event;
public class dot extends MovieClip
{
private var xPos:Number;
private var yPos:Number;
private var xVel:Number;
private var yVel:Number;
private var mass:Number;
public function dot(xPos:Number, yPos:Number, mass:Number)
{
this.addEventListener(Event.ENTER_FRAME, moveDot);
this.xPos = xPos;
this.yPos = yPos;
this.mass = mass;
xVel = 0.0;
yVel = 0.0;
}
private function moveDot(event:Event)
{
xVel += yPos / mass;
yVel += - xPos / mass;
xPos += xVel;
yPos += yVel;
this.x = xPos + 400.0;
this.y = 225.0 + yPos;
}
}
}
. , , . .
!