# Thread: Help on Orbiting objects

1. Hello everybody, I need to design a swarm system with n-bodies and I have an issue:

when 2 objects get close to each other (distance less than r_max) they start interacting and enter a formation. The formation I want is one in which one object moves and the other orbits around it. The orbiting object has to always stay within the r_max distance from the other object and cannot move faster than d_max per time_step.
I cannot use the global position of the objects for the calculations, but I know the distance between the 2 objects and the relative angle between the 2.
So far I have this formula:

f(x,y) = e^(-alpha*dist^2)
dx = alpha*f(x,y)*sin(theta)*dist;
dy = -alpha*f(x,y)*cos(theta)*dist;

I return those dx and dy which are going to be added to the global position outside of this function.
If I use this formula, however, the f(x,y) becomes smaller and smaller or larger and larger depending on alpha so the object doesn't stay in orbit.
Can anyone help me getting the object to move at a maximum speed of d_max per time_step and staying in an orbit with a distance that never exceeds r_max?
For semplicity we can assume that the object that doesn't orbit moves at a speed way lower than d_max per time_step
Thank you very much in advance  2. Originally Posted by 8mike Hello everybody, I need to design a swarm system with n-bodies and I have an issue:

when 2 objects get close to each other (distance less than r_max) they start interacting and enter a formation. The formation I want is one in which one object moves and the other orbits around it.
Is this a real word problem or for a game program?

If it is real-world, what you describe violates a few conservation laws unless you have a collision. That a planet captures a moon is a story often told to the general publik. Their view obtained is, invariably, science fiction.  3. Originally Posted by Useful Idiot Is this a real word problem or for a game program?

If it is real-world, what you describe violates a few conservation laws unless you have a collision. That a planet captures a moon is a story often told to the general publik. Their view obtained is, invariably, science fiction.
It is a quadcopter swarm simulation  4. Originally Posted by 8mike It is a quadcopter swarm simulation
I see. Somehow I'd missed that.  5. So is there a way to make it work?  6. Originally Posted by 8mike So is there a way to make it work?
You probably need an initial hierarchy negotiation that creates a master/slave relationship between the 2 objects to allow for the coordination of the movement of the slave(s) object(s) with respect to the master. Once your slave(s) is following its master you can work out how to make it rotate independently without crashing into anything.

For multiple slaves you could extend the hierarchy negotiation to determine the slaves following location (radius based on the total number of slaves in the formation) before merging the new object into the formation (either rotating or stationary).  7. I managed to work out a hierarchy. My problem is exactly in the formulas for the circular motion. If i use uniform circular motion the radius will keep increasing as the master moves. If i use the formula I posted it loses velocity quickly or it gets out of the orbit.  8.  9. Originally Posted by 8mike I managed to work out a hierarchy. My problem is exactly in the formulas for the circular motion. If i use uniform circular motion the radius will keep increasing as the master moves. If i use the formula I posted it loses velocity quickly or it gets out of the orbit.
I don't do this sort of thing, but you might try replacing your f(x,y) with a bump function. I'd start with something like

f(r) = 1/(1-r), where r^2 = x^2 +y^2.

You need a way to bring the slaves close, but not too close.

But you also might need, additionally, an inverse-squared scaling of the velocities. Perhaps f(r) = 1/{r^2 * (1-r)} would do it.

Then

dx = f(r)*sin(theta)
dy = r(r)*cos(theta)  Posting Permissions
 You may not post new threads You may not post replies You may not post attachments You may not edit your posts   BB code is On Smilies are On [IMG] code is On [VIDEO] code is On HTML code is Off Trackbacks are Off Pingbacks are Off Refbacks are On Forum Rules