# Fast Overlap Detection between Hard-Core Colloidal Cuboids and Spheres. The OCSI Algorithm
## 2 Algorithms
; validation, L.T. and A.P. ; formal analysis, L.T. ; investigation, L.T. and A.P. ; resources, A.P. ; data curation, L.T. ; writing--original draft preparation, L.T. ; writing--review and editing, A.P. ; visualization, L.T. ; supervision, A.P. All authors have read and agreed to the published version of the manuscript. This research was funded by the Leverhulme Trust grant number RPG-2018-415. The authors acknowledge the use of Computational Shared Facility at the University of Manchester and [PERSON] (University of Palermo) for a critical reading of the manuscript. The authors declare no conflict of interest. ## Appendix A On the Minimum Distance between a Sphere and a Randomly Oriented Cuboid

Let \(\mathbf{V}\) be a \(n\)-dimensional vector space in an orthonormal basis \(\mathcal{B}=\left\{\hat{\mathbf{x}}_{1},\hat{\mathbf{x}}_{2},...,\hat{ \mathbf{x}}_{n}\mid\hat{\mathbf{x}}_{i}\cdot\hat{\mathbf{x}}_{j}=\delta_{ij} \right\}\), with \(\delta_{ij}\) the Kronecker delta. The set of points of a cuboid \(\mathcal{C}\) in \(\mathbf{V}\) is

\[\mathbf{C}=\mathbf{r_{C}}+\sum_{i=1}^{n}\alpha_{i}c_{i}\hat{\mathbf{e}}_{i}, \tag{1}\]

where \(\mathbf{r_{C}}\) is the position of the centre of the cuboid, \(c_{i}>0\) is a scalar equal to half of the cuboid length, width or thickness, \(\alpha_{i}\) is also a scalar with values in \([-1,1]\) and \(\hat{\mathbf{e}}_{i}\) is a unit vector that defines the orientation of \(\mathcal{C}\). Specifically \(\hat{\mathbf{e}}_{i}\cdot\hat{\mathbf{e}}_{j}=\delta_{ij}\), so also \(\mathcal{B}^{\prime}=\left\{\hat{\mathbf{e}}_{1},\hat{\mathbf{e}}_{2},..., \hat{\mathbf{e}}_{n}\right\}\) is an orthonormal basis for \(\mathbf{V}\). The minimum distance between \(\mathbf{C}\) and a random point \(\mathbf{r_{S}}\) reads

\[\min\left(\left\|\mathbf{r_{S}}-\mathbf{C}\right\|\right)=\min\left(\left\| \mathbf{r_{S}}-\mathbf{r_{C}}-\sum_{i=1}^{n}\alpha_{i}c_{i}\hat{\mathbf{e}}_{ i}\right\|\right). \tag{2}\]

Since \(\mathcal{B}^{\prime}\) is an orthonormal basis for \(\mathbf{V}\), the vector \(\mathbf{r_{SC}}=\mathbf{r_{S}}-\mathbf{r_{C}}\) can be written as

\[\mathbf{r_{SC}}=\sum_{i=1}^{n}\left(\mathbf{r_{SC}}\cdot\hat{\mathbf{e}}_{i} \right)\,\hat{\mathbf{e}}_{i} \tag{3}\]

and substituting Equation (3) in Equation (2)

\[\min\left(\left\|\sum_{i=1}^{n}\left\{\left(\mathbf{r_{SC}}\cdot\hat{\mathbf{ e}}_{i}\right)-\alpha_{i}c_{i}\right\}\,\hat{\mathbf{e}}_{i}\right\|\right)= \tag{4}\] \[=\sqrt{\min\left(\sum_{i=1}^{n}\sum_{j=1}^{n}\left\{\left( \mathbf{r_{SC}}\cdot\hat{\mathbf{e}}_{i}\right)-\alpha_{i}c_{j}\right\}\left\{ \left(\mathbf{r_{SC}}\cdot\hat{\mathbf{e}}_{j}\right)-\alpha_{j}c_{j}\right\} \,\hat{\mathbf{e}}_{i}\cdot\hat{\mathbf{e}}_{j}\right)}=\] \[=\sqrt{\sum_{i=1}^{n}\min\left(\left\{\left(\mathbf{r_{SC}}\cdot \hat{\mathbf{e}}_{i}\right)-\alpha_{i}c_{i}\right\}^{2}\right)}\]

The last term in Equation (4) has been obtained considering that \(\hat{\mathbf{e}}_{i}\cdot\hat{\mathbf{e}}_{j}=\delta_{ij}\) and that every member of the sum depends on just one value \(\alpha_{i}\), hence they are all independent. It is sufficient to calculate only one term of this sum as all dimensions are equivalent. In particular, this term equals zero if the following conditions are met:\[\alpha_{i}c_{i}-\left(\mathbf{r_{SC}}\cdot\hat{\mathbf{e}}_{i}\right)=0\ \Leftrightarrow\ \alpha_{i}=\frac{\mathbf{r_{SC}}\cdot\hat{\mathbf{e}}_{i}}{c_{i}} \tag{12}\]

As a result that \(\alpha_{i}=[-1,1]\), this implies that

\[-1\leq\frac{\mathbf{r_{SC}}\cdot\hat{\mathbf{e}}_{i}}{c_{i}}\leq 1\ \Leftrightarrow\ \left|\frac{\mathbf{r_{SC}}\cdot\hat{\mathbf{e}}_{i}}{c_{i}}\right|\leq 1 \ \Leftrightarrow\ \left|\mathbf{r_{SC}}\cdot\hat{\mathbf{e}}_{i}\right|\leq c_{i} \tag{13}\]

If \(|\mathbf{r_{SC}}\cdot\hat{\mathbf{e}}_{i}|>c_{i}\), then \((\mathbf{r_{SC}}\cdot\hat{\mathbf{e}}_{i})>c_{i}\) or \((\mathbf{r_{SC}}\cdot\hat{\mathbf{e}}_{i})<-c_{i}\).