class Dipole { float w = 5.0; float l = 14.0; Vector3D pos; int gr = 0; int gc = 0; int id = 0; Vector3D m; // magnetic dipole Vector3D B; // magnetic field float I; // inertia float f; // friction float t; // torque float v; // angular velocity float a; // angular acceleration int[] nbs = new int[1]; // neighbours in scanrange Dipole() { } Dipole(int r, int c) { nbs[0] = 0; gc = c; gr = r; pos = new Vector3D(0,0,0); m = new Vector3D(1,0,0); B = new Vector3D(1,0,0); // set random angle m.rotate2D(random(0,2*PI)); } void setPos(float px, float py) { pos.setXYZ(px,py,0); } void setStrength(float st) { m.setMagnitude(st); } void update(ArrayList all) { t = -1 * m.magnitude() * B.magnitude() * (float) Math.sin(m.heading2D()-B.heading2D()); t -= f * v; a = t/I; v += a; m.rotate2D(v); } void setFriction(float fr) { f = fr; } void setInertia(float in) { I = in; } // calculate Magnetic Field based on Neighbours void calcB(ArrayList all) { B.setXYZ(0,0,0); //Vector3D distance = new Vector3D(); for(int n=1; n2*PI) a-=2*PI; float d = PI/8; if(a>=0 && aPI*0.5-d && aPI-d && aPI*1.5-d && aPI*2-d && a<=PI*2) c = 255; return c; } }