Provided your coordinate system is set with 0,0 at the centre of the circle/elipse then simply switching the polarity of both X and Y is all you will ever need.
Sounds simple enough
yes ... with center at 0,0
thing is ...
we don't want the bot to stumble ... ie ... miss a step/cycle.
so if ...
wherever in the routine it is determined that a bot is going to be 'out of bounds'
in it's next position ...
BEFORE adding the deltaX and deltaY to it's position ...
swap the polarity the x, y posistion ...
THEN ... add the delta velocities ... and repopulate.
this should put them back within the field ... in the new quadrant ...
without having missed a step.
yes?
no?
a modification of the above:
this all depends upon the relative magnitude of bot velocity vs field width.
if the bot's delta v is small compared to the field width ...
it isn't going to ever be way 'out of bounds'.
so it really doesn't make much difference if we fudge a bit on exactly where we repopulate or if it 'misses a step'.
how-some-ever ...
if we have some bot screaming thru our enviro ...
then we will need to accurately calculate how far their delta x and y would have
taken them out of bounds ... and accruately calculate how far 'in bounds' we should
then repopulate them on the next cycle.
this can of course be done for every bot that transgresses ...
but it will take computing time.
so it all depends on how willing we are to trade off accuracy for speed ...
or if it is even neccessary to do so.
everything contains some sort of compromise, does it not? ;)
taking a look at priorities is always the first step ...
in establishing/embarking upon ... any plan of attack.
or so it seems to me.