ベクター フィールドをフラッシュでモデリングし、パーティクルの混乱を生成してフィールドの流れを視覚化しています。ベクトル場F(x,y)=yi-xj の使用
このベクトル フィールドにはカールがあり、粒子は円を描くように移動します。私の問題は、この特定のベクトル場には発散がありませんが、粒子が原点から発散することです。このフィールドの非常に基本的な計算中に、データ型の 10 進数の精度が失われている可能性があると思われます。または、不確かな論理ミスを犯している可能性があります。
このコードは、画面 (800x450) にパーティクルをスポーンします。このコードはおそらく問題にはなりませんが、完全を期すために含めました。
//spawn particles
var i:int;
var j:int;
//spread is the spacing between particles
var spread:Number;
spread = 10.0;
//spawn the particles
for (i=0; i<=800/spread; i++)
{
for (j=0; j<=450/spread; j++)
{
//computes the particles position and then constructs the particle.
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);
}
}
これは、スポーンされるパーティクルに関する重要なすべてを含む「ドット」クラスです。
package
{
//import stuff
import flash.display.MovieClip;
import flash.events.Event;
public class dot extends MovieClip
{
//variables
private var xPos:Number;
private var yPos:Number;
private var xVel:Number;
private var yVel:Number;
private var mass:Number;
//constructor
public function dot(xPos:Number, yPos:Number, mass:Number)
{
//Defines the function to be called when the stage advances a frame.
this.addEventListener(Event.ENTER_FRAME, moveDot);
//Sets variables from the constructor's arguments.
this.xPos = xPos;
this.yPos = yPos;
this.mass = mass;
//Set these equal to 0.0 so the Number type knows I want a decimal (hopefully).
xVel = 0.0;
yVel = 0.0;
}
//Controlls the particle's behavior when the stage advances a frame.
private function moveDot(event:Event)
{
//The vector field is a force field. F=ma, so we add F/m to the velocity. The mass acts as a time dampener.
xVel += yPos / mass;
yVel += - xPos / mass;
//Add the velocity to the cartesian coordinates.
xPos += xVel;
yPos += yVel;
//Convert the cartesian coordinates to the stage's native coordinates.
this.x = xPos + 400.0;
this.y = 225.0 + yPos;
}
}
}
理想的には、パーティクルはすべて、原点を中心に永遠に円を描いて移動します。しかし、このコードは、パーティクルが原点を中心に回転し、外側にらせん状になり、最終的にステージを離れる状況を作り出します。助けていただければ幸いです。ありがとう!