# Position-Based Formation Control Scheme for Crowds Using Short Range Distance (SRD)
## 3 Proposed Algorithms
### Proposed Algorithms  
#### 3.3.1 Short Range Destination (SRD)  
PBD was first introduced by [PERSON] and is a constraint-based physics simulation technique [7]. The principle of this technique is to modify the position of an object by solving the constraints. This chapter briefly describes the basic principles of PBD. The constraint solver finds the solution of the constraint equation. Equation (5) is an equation that expresses a distance constraint that keeps two objects a certain distance apart:  
\[C_{dist}(p_{i},p_{j})=\mid p_{i}-p_{j}\mid-d \tag{5}\]  
where \(C_{dist}:\mathbb{R}^{2}\rightarrow\mathbb{R}\) is the scalar constraint function and \(p_{i}\in\mathbb{R}^{3}\) are the positions of the two objects involved in the constraint of distance \(p_{j}\), in which \(d\) is the size of the distance to be maintained between the two points. Solving the distance constraint forces the two objects to move the specific positions, \(p_{i}\) and \(p_{j}\), appropriately to maintain a distance equal to \(d\). Figure 7 is a graphical representation of Equation (5). In Figure 7, \(p\) is the position of an object in the distance constraint, and \(\Delta p\in\mathbb{R}^{3}\) is a vector that \(p\) must move to satisfy the constraint. To find \(\Delta p\), we need to first calculate the gradients of the constraint function. The gradient \(\
abla p_{j}\) can be obtained by applying the derivative at a point in a scalar field and represents the direction of the maximum change at the point. Finally, Equations (6) and (7) show the generalized solution for finding \(\Delta p\):  
\[\Delta p_{i}=-\lambda\
abla p_{i}C(p_{1},\ \ldots,\ p_{n}) \tag{6}\]  
\[s=\frac{C(p_{1},\ \ldots,\ p_{n})}{\Sigma_{j}|\
abla p_{j}\,C(p_{1},\ \ldots,\ p_{n})|^{2}} \tag{7}\]  
where \(\lambda\in\mathbb{R}\) is a scaling factor that controls the magnitude of the direction in which the object should move. For more details on the derivation of this equation, see [7]. In this paper, we propose the Short Range Destination (SRD) to control crowd formation. An SRD is a single short-term goal position that is given to an agent to maintain the given formation, and the priority action of an agent is to reach this destination. After the initial positions of the agents are completely set, each SRD is generated in the same position of each agent at the beginning. Once the destinations are generated for all agents, the formation constraints, which are extensions of the distance constraints between the current position of the agent and the SRD, are added to the simulation loop. Equation (8)  
Figure 6: A group moves to a final destination along the path drawn by the user. Figure 7: Distance constraints between two objects. illustrates the formation constraint. Note that, since formation constraints are one of the soft constraints, they can be ignored during the simulation to avoid emergent situations such as collision with other agents. That is, although the SRD is the _ideal_ position for an agent to satisfy the formation, the agent may not go there directly if the situation does not allow it. However, agents are able to return to the formation using the positions of the SRDs that are kept in the group once they exit the emergent situation. \[C_{formation}(\;p_{i},\;s_{i}\;)=\;|\;p_{i}-s_{i}\;|-d \tag{8}\]  
where \(C_{formation}\in\mathbb{R}\) is for the formation constraint, \(p_{i}\in\mathbb{R}^{3}\) is the current position of the \(i\)-th agent, \(s_{i}\in\mathbb{R}^{3}\) is the position of the SRD that \(p_{i}\) needs to chase, and \(d\) is the distance that \(p_{i}\) and \(s_{i}\) should maintain. The distance between the agent and the destination to be chased can be adjusted according to \(d\). In this paper, we set \(d\) to \(0\), so that the agent always moves to the exact position of the SRD. If the agent is far away from the SRD, then the agent will take the action of chasing to the destination to reduce the distance. The formation constraint is maintained throughout the simulation in this way.