# Fast Overlap Detection between Hard-Core Colloidal Cuboids and Spheres. The OCSI Algorithm
## 2 Algorithms
Eventually, [PERSON]'s algorithm can also be applied to randomly oriented cuboids by performing a transformation of the vectors involved in the calculation of \(d_{min}\) in the reference frame of \(\mathcal{C}\). [PERSON] and [PERSON] proposed to estimate \(d_{min}\) by employing interval analysis and reported a test to determine whether a point \(P\in\mathcal{C}\) is within a sphere delimited by four peripheral points [6]. The algorithms proposed by [PERSON] and co-workers employ quick rejection overlap tests to enhance the efficiency of collision detection between a sphere and either an aligned or a randomly oriented cuboid [7]. The pseudocode of these algorithms are reported in Algorithms 2 and 3, respectively. Both QRI and QRF are based on the implementation of a quick rejection test that immediately excludes an overlap if at least one of the summands in Equation (2) or Equation (5) is larger than \(R^{2}\). For the general case of a randomly oriented cuboid, this condition reads  
\[ \begin{split}\left\{\left|\mathbf{r_{SC}}\cdot\mathbf{\hat{e}_{i} }\right|-c_{i}\right\}^{2}>R^{2}\ \Leftrightarrow\\ \mathbf{r_{SC}}\cdot\mathbf{\hat{e}_{i}}<-c_{i}-R\ \cup\ \mathbf{r_{SC}} \cdot\mathbf{\hat{e}_{i}}>c_{i}+R.\\ \forall\ i=T,L,W\end{split}  \tag{6}\]  
A geometrical representation of this condition is provided in Figure 1, where a sphere \(\mathcal{S}\) of radius \(R\) and centred at \(\mathbf{r_{S}}\) is at the distance \(\mathbf{r_{SC}}\cdot\mathbf{\hat{e}_{L}}\) from the centre of mass of a cuboid \(\mathcal{C}\) that is centred at \(\mathbf{r_{C}}\). For this specific arrangement, the left-hand side of Equation (6) measures the distance of \(\mathcal{S}\) from the face of \(\mathcal{C}\) delimited by \(T\) and \(W\) and schematically identified by the vertical solid line of Figure 1. QRI applies this rejection criterion within the loop that evaluates the minimum distance, precisely at lines 6 and 9 of Algorithm 2. By contrast, QRF performs the three quick rejection tests, one for each summand of Equation (2), before the computation of the minimum distance, between lines 3 and 6 of Algorithm 3. In this case, the scalar products \(\mathbf{r_{SC}}\cdot\mathbf{\hat{e}_{i}}\) are stored in line 4 and eventually employed to compute \(d=d_{min}^{2}\) in the following loop. ```
1:functionQRI(\(\mathbf{r_{SC}},R,\hat{\mathbf{e_{T}}},\hat{\mathbf{e_{L}}},\hat{\mathbf{e_{W}}},c_{T},c_{L},c_{W}\))
2:\(d\gets 0\)\(\triangleright\) initialising minimum distance
3:for\(i\in\{T,L,W\}\)do
4:\(a\leftarrow\mathbf{r_{SC}}\cdot\hat{\mathbf{e_{i}}}\)
5:if(\((l\gets a+c_{i})<0\)) then
6:if(\(l<-r\))return\(false\)\(\triangleright\) quick rejection test
7:\(d\gets d+l^{2}\)
8:elseif(\((l\gets a-c_{i})>0\)) then
9:if(\(l>r\))return\(false\)\(\triangleright\) quick rejection test
10:\(d\gets d+l^{2}\)
11:endif
12:endfor
13:if(\(d\leq r^{2}\))return\(true\)\(\triangleright\) checking overlap
14:return\(false\)
15:endfunction
```  
**Algorithm 2** QRI  
Figure 1: Schematic representation of a sphere \(\mathcal{S}\) and a cuboid \(\mathcal{C}\) at relative distance \(\mathbf{r_{SC}}\cdot\hat{\mathbf{e_{L}}}\). Sphere and cuboid are centred, respectively, at \(\mathbf{r_{S}}\) and \(\mathbf{r_{C}}\), and \(c_{L}\) is half of the cuboid length. If \(\mathbf{r_{SC}}\cdot\hat{\mathbf{e_{L}}}>c_{L}+R\), then \(\mathcal{S}\) and \(\mathcal{C}\) do not overlap.