# how to implement formation in group?

This topic is 3264 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I met a problem recently, i want to implement formation in group,something like OpenSteer'pedestrian run on a map,but there are some differences,within these agents,some agents belong to same group,so they will have same velocity,and acceleration also they will closer to each other than to the agent not within same group, but i have no idea about how to implement it, can anybody help me, thank you very much.

##### Share on other sites
Look up flocking and boids.

##### Share on other sites
If I understand your badly worded question correctly, you are trying to progress from a single pool of coordinated pedestrian agents to separate groups of agents that keep a formation only with others in the same group rather than with any agent that happens to be close.
You can simply tag agents with their group and use this information to filter the results of spatial queries for agents: group A agents try to match the velocity of nearby group A agents while walking towards a waypoint, group B agents try to distance themselves from group A agents and get close to group C agents without going anywhere, group C agents just try to spread out, and so on.
Note that you cannot guarantee that such behavioural groups will always be spatially separated: groups can cross each other's path, or even stop in the same place and mingle indefinitely.

##### Share on other sites
Steering behaviors are great for inspiration, but personally I prefer a more principled approach: Define an "energy function" over your agents' positions and velocities that (1) will be minimized by the states you want, and (2) gets very large near unwanted states, and then simply have your agents walk down the gradient of this function in state-space.

Mixtures of quadratic penalty functions (which are "soft") and logarithmic barrier functions (which are "harder") have worked well for me in the past.

##### Share on other sites
Quote:
 Original post by EmergentSteering behaviors are great for inspiration, but personally I prefer a more principled approach: Define an "energy function" over your agents' positions and velocities that (1) will be minimized by the states you want, and (2) gets very large near unwanted states, and then simply have your agents walk down the gradient of this function in state-space.Mixtures of quadratic penalty functions (which are "soft") and logarithmic barrier functions (which are "harder") have worked well for me in the past.

i think your method is something like potential field algorithm,but it is path finding algorithm,but i want agents within same group align with each other,and closer to each other,i do not think this algorithm can solve this problem.thank you very much.

##### Share on other sites
Quote:
 Original post by LorenzoGattiIf I understand your badly worded question correctly, you are trying to progress from a single pool of coordinated pedestrian agents to separate groups of agents that keep a formation only with others in the same group rather than with any agent that happens to be close.You can simply tag agents with their group and use this information to filter the results of spatial queries for agents: group A agents try to match the velocity of nearby group A agents while walking towards a waypoint, group B agents try to distance themselves from group A agents and get close to group C agents without going anywhere, group C agents just try to spread out, and so on.Note that you cannot guarantee that such behavioural groups will always be spatially separated: groups can cross each other's path, or even stop in the same place and mingle indefinitely.

i should apologize for my poor english,Thank you very much~

##### Share on other sites
Quote:
 Original post by InnocuousFoxLook up flocking and boids.

thank you very much~

##### Share on other sites
Quote:
 Original post by hengh2009i think your method is something like potential field algorithm,but it is path finding algorithm,but i want agents within same group align with each other,and closer to each other,i do not think this algorithm can solve this problem.thank you very much.

The idea is to define the potential not over 3-space, but over the state space--which includes agents' headings, etc. And if multiple states are equally desirable -- say, all the states in which the agents are aligned -- then you'd use a potential function which has a "trough"-like minimum (so that all states in which agents are aligned are minima).

A good way to define these functions is as a sum of "interaction potentials."

For alignment, for example, you can use the potential

V_{\mathrm{align}}(\theta_1,\cdots,\theta_N) = \sum_{i=1}^N \sum_{k\in{\cal N}_i}\left(1 - \cos(\Delta\theta_{ik}) \right )

where $\Delta\theta_{ik}$ denotes the difference in heading angle between agents i and j, and ${\cal N}_i$ denotes the neighbors to agent i.

When you differentiate this, you see that each agent should steer according to the average sine of angular deviation with its neighbors; these sines-of-angles can be computed with cross products (or "2d cross products" depending on the number of dimensions) without resorting to trig functions at all.

You could add other terms penalizing when agents are too close together -- or too far apart.

See where I'm going with this?

##### Share on other sites
Quote:
Original post by Emergent
Quote:
 Original post by hengh2009i think your method is something like potential field algorithm,but it is path finding algorithm,but i want agents within same group align with each other,and closer to each other,i do not think this algorithm can solve this problem.thank you very much.

The idea is to define the potential not over 3-space, but over the state space--which includes agents' headings, etc. And if multiple states are equally desirable -- say, all the states in which the agents are aligned -- then you'd use a potential function which has a "trough"-like minimum (so that all states in which agents are aligned are minima).

A good way to define these functions is as a sum of "interaction potentials."

For alignment, for example, you can use the potential

V_{\mathrm{align}}(\theta_1,\cdots,\theta_N) = \sum_{i=1}^N \sum_{k\in{\cal N}_i}\left(1 - \cos(\Delta\theta_{ik}) \right )

where $\Delta\theta_{ik}$ denotes the difference in heading angle between agents i and j, and ${\cal N}_i$ denotes the neighbors to agent i.

When you differentiate this, you see that each agent should steer according to the average sine of angular deviation with its neighbors; these sines-of-angles can be computed with cross products (or "2d cross products" depending on the number of dimensions) without resorting to trig functions at all.

You could add other terms penalizing when agents are too close together -- or too far apart.

See where I'm going with this?

thank you very much,i will try your method.

[Edited by - hengh2009 on December 8, 2009 10:54:22 PM]

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633331
• Total Posts
3011390
• ### Who's Online (See full list)

There are no registered users currently online

×