# Fast Overlap Detection between Hard-Core Colloidal Cuboids and Spheres. The OCSI Algorithm
## 2 Algorithms
Moreover, in this way, vectorization of the algorithm can be assisted for different programming languages, e.g., Fortran, since SIMD intrinsic functions are available only in C and C++. Given the heterogeneous nature of the communities using collision-detection algorithms and their preference for likely different programming languages, an user-friendly code is a crucial advantage. Our algorithm, referred to as Oriented Cuboid Sphere Intersection (OCSI), proved to be efficient and functional for both C and Fortran 90 (F90). Its pseudocode is presented in Algorithm 5. ```
1:function\(\text{OCSI}(\mathbf{r_{\text{SC}}},R,\hat{\mathbf{e}}_{\text{T}},\hat{\mathbf{e}}_{\text{L}}, \hat{\mathbf{e}}_{\text{W}},c_{T},c_{L},c_{W})\)
2:for\(i\in\{T,L,W\}\)do\(\triangleright\) this cycle is vectorised
3:\(a_{i}=\mathbf{r_{\text{SC}}}\



## 3 Computational Details

To test the relative performance of the above algorithms, we have developed two versions of the same program in C and in F90 that detect collision between one cuboid and one sphere. For compatibility with the benchmark program by [PERSON] et al., all the floating point variables are expressed in 32-bit single precision. The dimensions of the cuboid and sphere are given in units of the cuboid thickness \(T\), which is our unit length, and do not change within the same detection-collision test. In particular, the colloid length and width are \(L^{*}\equiv L/T\) and width \(W^{*}\equiv W/T\), respectively, whereas the sphere radius is \(R^{*}\equiv R/T\). For each of the cuboid shapes analysed, we have pondered the impact on the algorithms' efficiency of changing the sphere radius between \(R^{*}=0.05\) and \(R^{*}=5\). To control the value of the acceptance ratio, i.e., the percentage of random configurations that do not produce overlaps, the sphere \(\mathcal{S}\) is generated within a spherocuboid. This spherocuboid, centred and oriented as \(\mathcal{C}\), results from the Minkowski addition [48] of \(\mathcal{C}\) and a sphere larger than \(\mathcal{S}\) and whose diameter is optimized to obtain the desired acceptance rate. A dedicated program optimises the volume of the spherocuboid according to the target value of the acceptance ratio and the dimensions of both \(\mathcal{C}\) and \(\mathcal{S}\), which are specified as input parameters. To generate a configuration, \(\mathcal{C}\) is initially aligned with the reference axes and its centre is set as origin, while the centre of \(\mathcal{S}\) is randomly positioned within the volume of the spherocuboid. Then, the reference system is randomly rotated and the cuboid-sphere overlap checked. For consistency, the section of the code that calls the overlap function is the same as that proposed by [PERSON] et al. [7]. The time spent by each algorithm to detect collisions for a specific case of cuboid and sphere (in term of radius of the sphere and dimensions of the cuboid) is computed for 3 independent sets of \(N_{c}=2\times 10^{6}\) configurations and then averaged out. The efficiency of the algorithms has been assessed on a Lenovo ThinkCentre M920s Desktop PC, with 8 Gb of DDR4 RAM and Intel(r) Core(tm) i5-8500 CPU @ 3.00 GHz (Coffee Lake) CPU with 9 Mb of cache, with Ubuntu 18.04 Desktop version OS. In order to prove the versatility of our algorithm, we performed benchmarks using two different compilers. In particular, we compiled the F90 and C/C++ versions of the program using Intel(r) Fortran and C Compilers version 19 [49] and GNU Fortran and C++ Compilers version 10 [50]. Both the compilers used OpenMP API 4.5 Specification for vectorization [51]. In addition, for all the cases listed above, we compiled two versions of the same program, enabling the generation of SSE or AVX instructions. In this work, configurations of cuboids with \(L^{*}=[1,20]\), \(W^{*}=[1,20]\) and spheres with \(R^{*}=\{0.05,0.5,5\}\) with an average acceptance ratio of 40% have been tested.