I‘m trying to get an Attractor simulation running on a pseudo infinite surface, but i can‘t get it to work properly.

What i‘m doing is basically set up a normal 1D Attractor simulation (Particles with pos, direction and updating direction with dist to other particles)(already made some Attractors, so that works just fine), with the difference, that i‘m trying to get it to work on a circle for now (circle = infinite 1D line) and later extend this to a sphere to get an infinite 2D surface.

Now i have the problem that i don‘t know how to calculate the velocity for the other direction. I even got some (pretty complex) formula to get the right values in theory, but they don‘t work right. I‘m sure there is a way better way to get this done. So if someone knows, please tell me.

Thanks in advance

For reference, this is one of the 6 Projects started to get something to work (started over 5 times already…maybe more, cause it Never worked out) :

```
Particle p,p2;
void setup() {
size(screen.width, screen.height);
frameRate(4);
p = new Particle(0,0);
p2 = new Particle(3.5,0);
}
void draw() {
background(0,0,255);
p.display();
p.move();
p.update();
p2.display();
p2.move();
p2.update();
if (abs(p.pos-p2.pos) <= PI) {
p.vel += (p2.pos-p.pos)/2000;
p2.vel += (p.pos-p2.pos)/2000;
} else {
p.vel += ((p2.pos-p.pos)-PI)/2000;
p2.vel += ((p.pos-p2.pos)-PI)/2000;
}
p.vel *= 0.95;
p2.vel *= 0.95;
}
```

```
class Particle {
float pos;
float vel;
Particle(float x, float v) {
pos = x;
vel = v;
}
void display() {
point(150+sin(pos)*50,100+-cos(pos)*50);
}
void move() {
pos += vel;
}
void update() {
pos = pos%(2*PI);
}
}
```