Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 www.elsevier.com/locate/cma SMB: Collision detection based on temporal coherence C.F. Li, Y.T. Feng *, D.R.J. Owen Civil and Computational Engineering Centre, School of Engineering, University of Wales Swansea, Swansea SA2 8PP, UK Accepted 5 May 2005 Abstract The paper presents a novel collision detection algorithm, termed the sort moving boxes (SMB) for large number of moving 2D/3D objects which are represented by their axis-aligned bounding boxes (AABBs). The main feature of the algorithm is the full exploitation of the temporal coherence of the objects exhibited in a dynamic environment. In the algorithm, the AABBs are first projected to each Cartesian axis. The projected intervals on the axes are separately sorted by the diminishing increment sort (DIS) and further divided into subsections. By processing all the intervals within the subsections to check if they overlap, a complete contact list can be built. The SMB is a fast and robust collision detection algorithm, particularly for systems involving a large number of moving AABBs, and also supports for the dynamic insertion and deletion of objects. Its performance in terms of both expected total detection time and memory requirements is proportional to the total number of AABBs, N, and is not influenced by size differences of AABBs, the space size and packing density over a large range up to ten times difference. The only assumption made is that the sorted list at one time step will remain an almost sorted list at the next time step, which is valid for most applications whose movement and deformation of each AABB and the dynamic change of the total number N are approximately continuous. 2005 Elsevier B.V. All rights reserved. Keywords: Collision detection; Contact search; Sort; Axis-aligned bounding boxes (AABBs); Moving; Temporal coherence 1. Introduction The goal of collision detection (also known as contact search) is to automatically report interference between two or more geometric objects in static and dynamic environments. The geometric objects may be polygonal objects, splines, or algebraic surfaces. In some cases, the interference report only requires answers with Yes or No, while in many other cases an exact or approximate overlapping extent report is * Corresponding author. Tel.: +44 1792 295161; fax: +44 1792 295676. E-mail address: [email protected] (Y.T. Feng). 0045-7825/$ - see front matter 2005 Elsevier B.V. All rights reserved. doi:10.1016/j.cma.2005.05.003 C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 2253 required. Fast and robust collision detection is of great importance in fields such as computer graphics [1– 4,14], robotics [5], computational geometry [6,7] and computational mechanics [8,9,15,19], and has been extensively studied in the related literature. In computer graphics and computational geometry, collision detection frequently arises in applications such as video games, animation, computer aided design and virtual reality. In robotics, collision detection is an essential component of robot motion planning and control, where it aids in steering the robot away from surrounding obstacles. Examples in computational mechanics include simulations involving multi-fracture and discrete phenomena [10,11], adaptive re-meshing approaches and multi-grid solution methods [12,13]. In many applications collision detection is considered to be a major computational bottleneck [2,3,10,11]. There are already several comprehensive reviews [17,18] on this subject. This paper however tackles the subject from a slightly different point of view, which may provide more useful information for the field of computational mechanics. All major collision detection algorithms can be classified into three categories: (i) geometry, (ii) bounding volume hierarchy (BVH) and (iii) spatial subdivision. The geometric approach [6] is to analyse the topology of each separate model, track and then capture the closest features between two or more models. Most geometric collision detection algorithms are restricted to the static environment, suitable only for convex hulls, and are typically non-trivial to implement. BVH-based methods, for example GottschalkÕs OBBTree [1] and our previous work ASDT [9], organize the objects in a hierarchical (tree) manner, and these methods differ by the type of bounding volume at each level of the tree or by adopting different techniques to build, update and balance the tree. Typical examples of bounding volumes include AABBs, spheres and oriented bounding boxes (OBBs). As a result of using a tree structure, the efficiency of BVH-based collision detection algorithms is usually O(N log N), where N is the total number of objects. The idea behind spatial subdivision [8,19] is simple: the domain is first divided into equal cells, and at every instant the objects are assigned to one or more cells. Collisions are then checked between all object pairs belonging to a series of related cells. Since each space cell may need a storage location in the computer memory, the total memory requirement and the CPU time will inevitably be influenced by the overall space size. To overcome this memory issue, Munjiza [8] and Williams [19] employ a space scanning technique to reduce the memory cost O(L), where L denotes the characteristic length of the space. Collision detection algorithms in computational mechanics often have to cope with a large number of simple objects (elements) whose configuration undergoes continuous change. A practical collision detection algorithm usually includes two steps: a global search and a local resolution. By approximating each object with a simple geometric primitive, the global search aims to reduce the O(N2) running time needed to perform intersection tests on all possible contact pairs of the N objects; the local resolution then undertakes more detailed intersection calculations only for those potential contact pairs obtained in the global search. In the current work, an AABB is employed in the global search for representing each object. The ‘‘sort moving boxes’’ (SMB), a global search algorithm presented in this paper, is then employed to detect collision among these moving AABBs. The sorting of AABBs is not a new approach, and related work can be found, for instance, in references [14,15]. CohenÕs I-COLLID method [14] and its various extensions, including RAPID, PDP and SWIFT, use either M · M flag pairs, which are stored in a static upper-triangular O(M2) matrix or a dynamic sparse matrix list, to represent the contact status of M rigid bodies, and during the sorting procedure tracks and update the overlap status by swapping two immediately neighbouring items each time. Therefore, these collision detection packages may be compromised in terms of either memory requirement or CPU time cost for problems involving a large number of moving bodies. In fact, they are mainly developed for applications in visual reality, which normally involve a small number of complex rigid bodies without self-collision instead of a large number of simple primitives (elements) arising in computational mechanics. Perkins and WilliamsÕ method [15] uses globally ordered lists to represent projection intervals on fixed world axes and can deal with a large number of objects, but as the number of objects grows the overlap checking procedure may become increasingly more expensive than the sorting procedure which further reduces the efficiency. To the authorsÕ best knowledge, the SMB may be the first 2254 C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 sort-based collision detection algorithm that can be efficiently applied to large scale realistic problems, i.e. N > 200,000. Also, if a sorted list at one time step remains as an almost ordered list at the next time step, which is often held by a system with temporal coherence, the SMB will become a linear algorithm whose computational cost is only proportional to N. The rest of the paper is organised as follows. Section 2 describes the collision detection algorithm in detail, including temporal coherence, diminishing increment sort (DIS), space locality and axial cut. Section 3 outlines the implementation issue and summarises the performance of the algorithm. In Section 4, the theoretically predicted performance of the SMB is verified on a range of numerical experiments differing in packing density, size difference of AABBs, space size and the total number of objects. Finally conclusions are drawn in Section 5. 2. Sort moving boxes (SMB) 2.1. Definition of the collision detection problem The collision detection algorithm presented in this paper, termed the sort moving boxes (SMB), assumes that every object for collision detection purposes can be approximated with an axis-aligned bounding box (AABB) in a 2D or 3D environment. All the primitives with collision potential should be regarded as independent objects, no matter whether they are topologically linked or separate in reality. As shown in Fig. 1(a), body A is considered as seven independent objects which are represented by AABBs 1–7 respectively, and similarly AABBs 8–11 are used to approximate body B. In Fig. 1(b), five AABBs are built to approximate five ellipsoidal particles. Thus, a general collision detection problem is transformed into contact detection between 2D or 3D AABBs. A square/cubic region filled with 2D/3D AABB objects, which can be different in size and undergoing continuous displacement, is taken as the initial state and the task is to find all AABB couples that are close to each other in a sense that the distance between their closest points is less than zero, or in other words ‘‘overlap’’. As shown in Fig. 2, N AABBs are moving and deforming in a square/cubic region of length x, where a denotes the lower limit of the length of sides and b the upper limit, and the SMB will produce a contact list consisting of all the overlapping AABB pairs. In this context, the goals to be achieved of the SMB include: 1. Efficiency: The complexity of collision detection time should ideally be of order O(N), regardless of the AABB sizes, the packing density and the space size. 2. Memory cost: Total memory requirements should be minimized and proportional to N. 3. Flexibility for dynamic environments: Besides the movement and deformation of objects, the algorithm should allow insertion and deletion of objects from the environment without loss of efficiency. 2.2. Temporal coherence and diminishing increment sort (DIS) Temporal coherence is the property that some features of an application do not change significantly between two consecutive time steps. The objects move and deform only slightly from last time step to the current time step and, in the meantime, the change of the total number of objects is within an acceptable level. The underlying assumption is that the time steps are small enough so that the objects do not undergo large movements and/or the total number does not increase/decrease significantly between time instants. Such a temporal coherence is present in most dynamical applications. However, a traditional collision detection algorithm always consumes the same CPU resource every time step even if nothing in the environment C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 2255 Fig. 1. Collision detection problem: (a) 2D example; (b) 3D example. has changed. This paper addresses this issue by utilising temporal coherence information in order to speed up collision detection. As illustrated in Fig. 2 two AABBs intersect each other if, and only if, their orthogonal projections onto the axes of the coordinate system are all overlapping. This means, that the problem can be reduced to one dimension since the overlapping intervals can be obtained from the ordered lists after sorting the AABBsÕ one-dimensional projections. Naturally, for most cases, these sorted lists would possess a temporal coherence, i.e. they will change only slightly between time steps. This observation further suggests a special sorting algorithm that may be effective in handling this situation: the diminishing increment sort (DIS). DIS, presented first by Shell in 1959 [16], is one of the oldest sorting algorithms. It is inefficient compared to the quick sort or the heap sort, on average. However, as an extension of the insertion sort, DIS can achieve a O(N) speed for an almost ordered input, and also behave much more robust than its predecessor. DIS is the first key component of the proposed SMB algorithm and, after the second time step, can significantly accelerate the sorting procedure in a system with temporal coherence. However, it is non-trivial to efficiently produce an actual overlap list from these ordered one-dimensional lists. Using pffiffiffiffi enumeration [14,15] to scan all the ordered lists after the sorting procedure will cost OðNMÞ ¼ OðN N Þ CPU time, on average, where M is the average number of overlapping intervals for one object. For this reason, an axial 2256 C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 Fig. 2. Collision detection of AABBs (a) 2D example; (b) 3D example. cut technique is then employed to overcome this obstacle and, in fact, it constitutes the second key component of the algorithm. 2.3. Space locality and axial cut Similarly to other mechanical phenomena such as deformation and movement, collision is also a local behaviour, i.e., an object can only collide with objects in its proximity and is hardly affected by objects far away from where the object is. This property of collision is often termed the space locality. In Fig. 3, object B is non-local to object A and therefore should not be considered when dealing with the collision of the latter. However, if all the projections are sorted together, objects A and B will overlap on the x-axis and therefore inevitably be recorded once. This makes the overlap checking procedure increasingly more expensive than the sorting procedure when N increases. In order to overcome this, during the sorting procedure each axis is cut into a series of segments containing the (nearly) same number of projection intervals, and following the axial cut the objects are divided C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 2257 A Y B X Fig. 3. Space locality and axial cut (2D case). into a series of subsets which are subject to the overlap checking. As shown in Fig. 3, the x and y-axes are both cut into two segments, and the corresponding division is marked by dashed lines. Since overlap checking is limited within each subset, objects A and B, which are in different subsets, will not interfere with each other. The above axial cut method can be regarded as an equivalent partition strategy, but is different from space subdivision. A traditional space subdivision method divides a simulation space into cells of equal size, however there is no best size for all situations. The axial cut takes objects instead of the space into account and is incorporated with the sorting procedure DIS, so the efficiency of the algorithm is not influenced by the space size or object distribution, and the total memory requirement becomes independent of the space size. 2.4. SMB algorithm For the sake of simplicity, the 2D case shown in Fig. 4 is taken as an example to explain the SMB algorithm in detail and a general 2D/3D implementation can be easily obtained afterwards based on the understanding of the algorithm. Twelve AABBs are represented by their 48 vertices. For example, AABB 5 is represented by vertices 20, 21, 22 and 23. In general, AABB n has the corresponding vertices 4n, 4n + 1, 4n + 2, and 4n + 3 respectively and, vice versa. The main procedure of the SMB algorithm is as follows: (1) Integer list Y1, which is initialized as {0, 1, 2, 3, 4, . . . , 46, 47} before the first time step, represents the forty-eight AABB-vertex projections on the y-axis. DIS is performed to sort projection list Y1 and the sorted list becomes: Array Y1 f18; 19; 10; 11; 16; 17; 2; 3; 8; 9; 0; 1; . . . ; 26; 27; 4; 5; 24; 25; 44; 45g. ð1Þ Since vertex projections 2n and 2n + 1, where n = 0, . . . , 23, always have the same coordinate value in list Y1, only even vertex projections 2n(n = 0, . . . , 23) need to be considered in DIS and the complete ordered list can be obtained by inserting odd ones immediately after their even counterparts respectively. (2) Cut the y-axis along the dashed line AB shown in Fig. 4 and treat the sorted list Y1 (1) as two equallength sub-lists connected together, i.e., 2258 C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 C 11 6 1 Sub-list II20 21 3 5 23 Sub-list 3 A D Sub-list 4 E 8 22 B 7 9 10 0 Sub-list I Y 2 4 Sub-list 1 X Sub-list 2 F Fig. 4. SMB delineation (2D case). f Array Y1 18; 19; 10; 11; 16; 17; 2; 3; 8; 9; 0; 1; 42; 43; 38; 39; 30; 31; 40; 41; 36; 37; 28; 29; |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} 24 items in sub-list I 22; 23; 34; 35; 32; 33; 14; 15; 20; 21; 12; g. 13; 6; 7; 46; 47; 26; 27; 4; 5; 24; 25; 44; 45 |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} ð2Þ 24 items in sub-list II (3) Similarly, integer list X12 is also initialized as {0, 1, 2, 3, 4, . . . , 46, 47} before the first time step but used to represent AABB-vertex projections on the x-axis. The axial cut just performed on list Y1 (2) is transformed to list X12 (7). Assume that list X12 sorted in the last time step, which consists of two equallength sub-lists as well, is as shown in expression (3). Items {36, 39, 16, 19, 37, 38, 17, 18, 31, 40, 43, 30, 8, 11, 41, 42, 0, 3, 9, 10, 1, 2}, which appear in the same sub-list, i.e. sub-list I, in both lists X12 (3) and Y1 (2), are termed normal items, as are items {4, 7, 24, 27, 12, 15, 5, 6, 13, 14, 25, 26, 20, 32, 35, 44, 47, 21, 45, 46, 33, 34} in sub-list II. On the contrary, items appearing in different sub-lists in X12 (3) and Y1 (2) are termed singular items. In this example, singular items are {23, 22} located in sub-list I in list X12 (3) but sub-list II in list Y1 (2) and items {28, 29} located in sub-list II in list X12 (3) but sub-list I in list Y1 (2). The singular items in the two sub-lists are then swapped without touching the normal ones until all the items in the lists become normal. f 36; 39; 16; 19; 37; 38; 17; 18; 31; 40; 43; 30; 23; 8; 11; 41; 42; 0; 3; 22; 9; 10; 1; 2; |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} 24 items in sub-list I Array X12 4; 7; 24; 27; 12; 15; 5; 6; 13; 14; 25; 26; 28; g. 20; 29; 32; 35; 44; 47; 21; 45; 46; 33; 34 |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} 24 items in sub-list II ð3Þ C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 2259 To do this efficiently, two temporary integer arrays are introduced: an index array and a stack array. Firstly, loop over list Y1 (2) and initialize the index array as shown in expression (4). Elements 0–47 in the index array (4) represent items in list Y1 (2) from 0 to 47 respectively, and the value of each element identifies which sub-list the corresponding item is actually in. For example, element 3 (the fourth element in expression (4)) is assigned 1 because item 3 in list Y1 (2) locates in sub-list I. Secondly, loop over list X12 (3) and push all the singular items, which can easily be recognized according to the index array (4), into the stack array (6). The result is shown in expressions (5) and (6) in which 1 denotes an empty element. The stack array (6) consists of two equal-length stacks, one for each sub-list, and the last elements server as stack pointers respectively. Finally, loop over list X12 (5) to replace all the 1s with the elements popped from the right stack in the stack array (6), so that all the sub-lists in list X12 (3) become normal as shown in expression (7). f1; 1; 1; 1; 2; 2; 2; 2; 1; 1; 1 ; 1 ; 2 ; 2 ; 2 ; 2 ; 1 ; 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1; 1; 1; 2; 2; 2; 2; 2; 2; 2; 2; 1; 1; 1; 1; Temporary index array 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ð4Þ 2 ; 2 ; 2 ; 2 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 2 ; 2 ; 2 ; 2 g. 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 36; 39; 16; 19; 37; 38; 17; 18; 31; 40; 43; f 30; 1; 8; 11; 41; 42; 0; 3; 1; 9; 10; 1; 2; |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} 24 items in sub-list I Array X12 ð5Þ 4; 7; 24; 27; 12; 15; 5; 6; 13; 14; 25; 26; 1; g. 20; 1; 32; 35; 44; 47; 21; 45; 46; 33; 34 |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} 24 items in sub-list II 28; 29; 1; 1; 1; 1; 1; 1; 1; 0 2 1 3 5 4 7 6 8 ; 1; 1; 1; 1; 1; 1; 1; 1; f 1 9 10 11 12 13 14 15 16 17 2 1; 1; 1; 1; 1; 18 19 20 21 22 23ðstack pointerÞ |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} stack for sub-list I Temporary stack array ð6Þ 23; 22; 1; 1; 1; 1; 1; 1; 1 24 25 26 27 28 29 30 31 32 1; 1; 1; 1; 1; 1; 1; 1; 1 g. 33 34 35 36 37 38 39 40 41 1; 1; 1; 1; 1; 26 42 43 44 45 46 47ðstack pointerÞ |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} stack for sub-list II 2260 C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 36; 39; 16; 19; 37; 38; 17; 18; 31; 40; 43; f 30; 28; 8; 11; 41; 42; 0; 3; 29; 9; 10; 1; 2; |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} 24 items in sub-list I Array X12 4; 7; 24; 27; 12; 15; 5; 6; 13; 14; 25; 26; 23; ð7Þ g. 20; 22; 32; 35; 44; 47; 21; 45; 46; 33; 34 |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} 24 items in sub-list II (4) Sort the almost ordered sub-lists in list X12 (7) with DIS respectively and which leads: 36; 39; 37; 38; 16; 19; 17; 18; 28; 31; 40; f 43; 29; 30; 41; 42; 8; 11; 0; 3; 9; 10; 1; 2; |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} 24 items in sub-list I Array X12 ð8Þ 4; 7; 24; 27; 5; 6; 12; 15; 13; 14; 25; 26; 20; 23; 32; 35; 44; 47; 21; 22; 45; 46; 33; 34 |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} g. 24 items in sub-list II (5) Cut the x-axis as shown by dashed lines CD and EF in Fig. 4, so that list X12 (8) becomes four equallength sub-lists connected together as shown in expression (9). List X12 (9), which is locally ordered in sub-lists 1–4 respectively, will be employed in the last step to check overlap among projection intervals on x-axis. f36; 39; 37; 38; 16; 19; 17; 18; 28; 31; 40; 43; 0 0 0 0 1 1 1 1 2 2 3 3 |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} 12 items in sub-list 1 29; 30; 41; 42; 8; 11; 0; 3; 9; 10; 1; 2; 0 0 1 1 2 2 3 3 2 2 3 3 |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} 12 items in sub-list 2 Array X12 4; 7; 24; 27; 5; 6; 12; 15; 13; 14; 25; 26; 0 0 1 2 1 0 0 2 2 2 1 1 |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} ð9Þ 12 items in sub-list 3 20; 23; 32; 35; 44; 47; 21; 22; 45; 46; 33; 34g. 2 0 0 0 0 1 1 2 2 2 1 1 |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} 12 items in sub-list 4 (6) List Y2 (10) also consisting of four sub-lists is a counterpart of list X12 (9) but represents projection intervals on y-axis. And it is achieved by applying division structure in list X12 (9) onto list Y1 (2) such that items with global sequence become locally ordered in each new sub-list, i.e. sub-lists 1–4 in expression (10) respectively. A temporary index array (11) is formed to facilitate the regrouping. Each element in index array (11) represents an item in list X12 (9) and the value identifies in which sub-list the item is located. For example, element 4 (the fifth element in expression (11)) has value 3 because item 4 belongs to sub-list 3 in list X12 (9). To achieve list Y2 (10), loop over list Y1 (2) from the beginning to the end and copy items, in turn, into the correct sub-list indicated by index array (11). C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 2261 f18; 19; 16; 17; 43; 38; 39; 31; 40; 36; 37; 28; |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} 12 items in sub-list 1 10; 11; 2; 3; 8; 9; 0; 1; 42; 30; 41; 29; |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} 12 items in sub-list 2 Array Y2 14; 15; 12; 13; 6; 7; 26; 27; 4; 5; 24; 25; |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} ð10Þ 12 items in sub-list 3 22; 23; 34; 35; 32; 33; 20; 21; 46; 47; 44; 45g; |fflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl{zfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflfflffl} 12 items in sub-list 4 f2; 2; 2; 2; 3; 3; 3; 3; 2; 2; 2 ; 2 ; 3 ; 0 1 2 3 4 5 6 7 8 9 10 11 12 3; 3; 3; 1; 1; 1; 1; 4; 4; 4; 4; 3; 13 14 15 16 17 18 19 20 21 22 23 24 Temporary index array 3; 3; 3; 1; 2; 2; 1; 4; 4; 4; 4; 1; ð11Þ 25 26 27 28 29 30 31 32 33 34 35 36 1 ; 1 ; 1 ; 1 ; 2 ; 2 ; 1 ; 4 ; 4 ; 4 ; 4 g. 37 38 39 40 41 42 43 44 45 46 47 (7) A global–local map (12) is built to overcome memory explosion caused by a global flag matrix [14] in the overlap checking procedure. Elements in map (12) represent all the vertices from 0 to 47 in turn, each vertex belongs to a unique AABB, and the value of an element is the local index of the corresponding AABB in its sub-list in list X12 (9). Consider sub-list 2 in Fig. 4, AABB 7 has its vertices {29, 30} located in the sub-list, so are AABB 10 with vertices {41, 42}, AABB 2 with vertices {8, 9, 10, 11} and AABB 0 with vertices {0, 1, 2, 3}. According to their appearing sequence in sub-list 2 in list X12 (9), each AABB is assigned to a local index. For instance, AABB 7 with vertices {29, 30} is the first one appearing in sub-list 2, therefore vertices {29, 30} have a local index 0. Global–local map (12) can easily be formed by extracting local index information from list X12 (9). f3; 3; 3; 3; 0; 0; 0; 0; 2; 2; 2 ; 2 ; 2 ; 0 1 2 3 4 5 6 7 8 9 10 11 12 2; 2; 2; 1; 1; 1; 1; 0; 0; 0; 0; 1; 13 14 15 16 17 18 19 20 21 22 23 24 Global–local map array 1; 1; 1; 2; 0; 0; 2; 1; 1; 1; 1 0; 25 26 27 28 29 30 31 32 33 34 35 36 ð12Þ 0 ; 0 ; 0 ; 3 ; 1 ; 1 ; 3 ; 2 ; 2 ; 2 ; 2 g. 37 38 39 40 41 42 43 44 45 46 47 (8) Lists X12 (9) and Y2 (10) are finally taken to exclusively determine overlap status, and as discussed in the previous Section 2.3 overlap checking should be strictly limited in every sub-domain denoted by sublists 1–4 in Fig. 4 respectively. Thus, from 1 to 4 go through each sub-list to check overlapping projection intervals separately, and add an AABB pair into the contact list if and only if their projections overlap on both the x-axis determined by list X12 (9) and y-axis determined by list Y2 (10). A temporary m · m upper triangular character matrix, where m = 12 is the length of sub-lists, is used to help, and all the matrix elements are initialized as 0 before starting overlap checking. Taking sub-list 1 as an example: AABB 7, whose local index is 2 for vertices 28 and 31 in global–local map (12), and AABB 10, whose local index is 3 for vertices 40 and 43 in global–local map (12), overlap on x-axis, so the first bit of matrix element (2, 3) is marked as 1; similarly, AABB pairs (9, 7), (9, 10) and (7, 10) overlap on the y-axis respectively, and leads to matrix elements (0, 2), (0, 3) and (2, 3) to be marked as 1 at the second bit. Because matrix element (2, 3) is marked as 1 at both the first and the second bit, which mean two AABBs are overlapping, their corresponding AABBs pair (7, 10) is added to the contact list. 2262 C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 AABB pair (7, 10) crosses sub-lists 1 and 2 in Fig. 4, and therefore will be tested and added into the contact list twice during the above procedure. To avoid this redundant computation, a mask array (13) is used of each element are in which each element is a byte and represents an AABB. Only the first two bits, i.e. 21, shown in expression (13), where bit 1 represents the X loop, i.e. checking sub-lists along x-axis, and bit 2 represents the Y loop, i.e. checking sub-list along y-axis. AABBs 9, 4, 7 and 10 are first checked in sub-list 1, and therefore the corresponding masks are turned on as shown in (13b). When checking sub-list 2, collision between AABBs 7 and 10 is ignored because they are both marked at the X bit in (13b). As shown in Fig. 4, the first X loop is finished after checking sub-list 2, all the X bits are turned off and concurrently all the Y bits for those AABBs which have been checked in the last X loop including sub-lists 1 and 2 are turned on (see expression (13c)). Similarly, after checking sub-list 3 AABBs 1, 6 and 3 are marked at X bit as shown in (13d). This updating operation on mask array (13) is always performed after checking a sub-list, and if two AABBs have already been marked at the same bit, either both X bits or both Y bits, the collision detection between them will be ignored in the remaining checking process. Initial mask array: f00; 00; 00; 00; 00; 00; 00; 00; 00; 00; 00; 00g. 0 1 2 3 4 5 6 7 8 9 10 11 ð13aÞ Mask array after checking sub-list 1: f00; 00; 00; 00 01; 00; 00; 01; 00; 01; 01; 00g. 0 1 2 3 4 5 6 7 8 9 10 11 ð13bÞ Mask array after checking sub-list 2: f10; 00; 10; 00; 10; 00; 00; 10; 00; 10; 10; 00g. 0 1 2 3 4 5 6 7 8 9 10 11 ð13cÞ Mask array after checking sub-list 3: f10; 01; 10; 01; 10; 00; 01; 10 00 10 10; 00g. 0 1 2 3 4 5 6 7 8 9 10 11 ð13dÞ (9) Remark: 1. In the DIS procedure, we choose {Dk = 2tk 1j0 6 k < t, k 2 Z} as the increment sequence, where t is a positive integer constant within each single sorting procedure. To achieve the best performance, t is adaptively determined in the SMB algorithm. 2. In the example of Fig. 4 all the sub-lists have exactly the same number of items, i.e. 24 items in sub-lists I and II, and 12 items in sub-lists 1–4. However, it is not an essential condition for the SMB algorithm to allocate an equal number of items to each sub-list. The algorithm works well, as long as there is a simple mapping between lists X and Y and between time steps. In our implementation, an equal number of items is arranged for all the sub-lists except for the last one. For example, if there are 6 sub-lists and 200 items all together, the first 5 sub-lists will have 34 items each and the sixth sub-list will have 30 items. 3. The performance of the SMB algorithm is not sensitive to insertion or deletion of AABBs from the environment, which is an advantage for fracture simulations. However, the algorithm does not permit modification to the whole sequence and renumbering all the items, since this will affect the internal temporal coherence of the system. In other words, all the lists should be renumbered sequentially whenever an AABB is inserted or deleted from the environment. 4. In general, the more segments an axis is cut into, the faster the algorithm runs. However, an axis should not be cut unlimitedly, and the limit is that an AABB must not be cut more than once on C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 2263 Fig. 5. Restriction of axial cut. any direction. As shown in Fig. 5, if that happens, the collision with regard to part B of the AABB will be missed. This is a restriction of SMB, but in reality, it is not necessary to cut an axis into tiny segments to achieve good performance. In cases where a few objects are very large, a pre-processing procedure can be applied to divide each large object into several smaller objects before the contact detection takes place. In the current implementation, a partition is always at least twice as large as the largest AABB, and therefore the situation shown in Fig. 5 will not occur. 3. Implementation and performance Following the above 2D example, the implementation of the SMB algorithm is outlined as follows: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. Sort list Y1 (List Y1 is naturally cut after sorting) Perform DIS on even items Insert odd items after the corresponding even ones Initialize list X12 Initialize the index array and stack pointers Push elements into stacks Pop elements out of stacks Perform DIS on list X12 (List X12 is naturally cut after sorting) Regroup list Y1 as Y2 Initialize the index array Copy each item to its right sub-list Form the global–local map Loop over each sub-list and do Check overlapping intervals in list X12 Check overlapping intervals in list Y2 and report contact pairs Update the mask array 2264 C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 Regarding to the space cost of the algorithm, since the information stored in lists Y1, X12 and Y2 has to be kept during the whole simulation in order to trace temporal coherence, these lists must be allocated independent memory spaces. Conversely, the information in the index and stack arrays in step 5, the index array in step 10, the global–local map in step 12 and the mask array in step 16 are temporary and can be discarded immediately after use. Therefore these arrays can share memory whenever they do not conflict with each other. Further investigation reveals that the algorithm needs two temporary arrays, of the same length as those lists. Another memory cost is the flag matrix used in overlap checking. However after the axial cut this memory requirement is negligible and can be ignored when compared with those five lists. Thus, the total memory requirement of the SMB algorithm is approximately 5L = 20N in the 2D case, where L = 4N denotes the length of each list. In the same way, the time cost of the SMB algorithm could be obtained by adding up the costs of all the operations from step 1 to step 16. The algorithm includes ten linear operations, i.e. steps 2, 3, 5, 6, 7, 8, 10, 11, 12 and 16, and the cost of each is approximately equivalent to one loop over a list. There are only two non-linear operations in the algorithm, i.e. steps 14 and 15, but because of the axial cut their costs are approximately proportional to N as well. Hence, the performance of the SMB in terms of CPU time is a function of O(N). 4. Numerical experiments In this section, the performance of the SMB algorithm is investigated in detail through a range of 3D numerical examples. As stated in Section 2.1, a total of N 3D AABBs are randomly distributed in a cubic box of length x (see Fig. 2(b)). Controlled by a update factor K, the environment is randomly modified every time step by evolution of the following: the new total number of AABBs N 0 = N + kN, new location of an AABB x0i ¼ xi þ ki x (i = 1, 2, 3) and new length of side of an AABB l 0 i = li + kib (i = 1, 2, 3), where xi is the old location, li the old length of side, and k and ki are random variables satisfying 0 < jkj, jkij < K. In N ðaþbÞ3 addition, the packing density E ¼ x23 is defined to describe distribution of AABBs in the space and size ratio H ¼ ba is defined to measure size difference among AABBs, and without loss of generality we assume b 1. The SMB algorithm is tested at each time step in this artificial dynamic environment. The algorithm is coded in C++ and compiled by Microsoft Visual Studio 6 under Windows XP. All the numerical examples are tested on a PC with a 2.4 GHz Intel processor and 1 GByte DDR memory. 4.1. Influence of the total number of AABBs and update factor As listed in Table 1, packing density E and size ratio H are limited to relatively small range, i.e., [0.31, 0.43] and [1.4, 3.3] respectively, and the total number of AABBs, N, is gradually changed from 10,000 to 1,000,000 and update factor K from 0.00001 to 0.1. The results are shown in Figs. 6–8. Fig. 6 illustrates the relation between N and detection time for five cases differing in K, and Fig. 7 shows their corresponding correlation coefficients respectively. A clear linear relation between N and detection time is observed for every case and is not influenced by K over a large range. Fig. 8 shows the memory cost is proportional to N and independent of K. Table 1 Initial data for examples in Section 4.1 N (K) 10 100 200 300 400 500 600 700 800 900 1000 E H 0.43 2.5 0.43 3.3 0.31 2.5 0.38 3.3 0.33 2.0 0.41 2.0 0.40 2.5 0.38 3.3 0.34 2.0 0.38 2.0 0.36 1.4 C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 40 Case 1 Λ = 0.00001 Case 2 Λ = 0.0001 Case 3 Λ = 0.001 Case 4 Λ = 0.01 Case 5 Λ = 0.1 35 30 Detection Time (s) 2265 25 20 15 10 5 0 0 200 400 600 800 1000 Total Number of AABBs (K) Fig. 6. Total number of AABBs versus detection time. 1.00 Correlation Coefficient 0.98 0.96 Case 1 Λ = 0.00001 Case 2 Λ = 0.0001 Case 3 Λ = 0.001 Case 4 Λ = 0.01 Case 5 Λ = 0.1 0.94 0.92 0.90 1 2 3 4 5 Case Number Fig. 7. Linear dependence relation for different cases. 4.2. Influence of packing density and space size Initial data are listed in Table 2, in which the size ratio H and update factor K are fixed and only the space length x and the packing density E are allowed to change. For three cases with different number of AABBs, Figs. 9 and 10 illustrate the influence of E and x on the performance of the algorithm. In Fig. 9, detection time has a small variation while E increases over eight times from 0.008 to 0.067, and this shows that the time cost of the algorithm is insensitive to packing density over a large range up to eight times difference. In addition, it can be seen from Fig. 10 that the memory cost is independent of the space 2266 C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 Case 1 Λ = 0.00001 Case 2 Λ = 0.0001 Case 3 Λ = 0.001 Case 4 Λ = 0.01 Case 5 Λ = 0.1 Total Memory Requirement (MByte) 250 200 150 100 50 0 0 200 400 600 800 1000 Total Number of AABBs (K) Fig. 8. Total number of AABBs versus total memory requirement. Table 2 Initial data for examples in Section 4.2 x 100 120 140 160 180 200 E H K 0.067 10.0 0.00001 0.038 0.024 0.016 0.011 0.008 7.5 7.0 Case 1 N = 400,000 Case 2 N = 600,000 Case 3 N = 800,000 6.5 Detection Time (s) 6.0 5.5 5.0 4.5 4.0 3.5 3.0 2.5 2.0 0.00 0.01 0.02 0.03 0.04 0.05 0.06 Packing Density Fig. 9. Packing density versus detection time. 0.07 C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 2267 Total Memory Requirement (MByte) 200 Case 1 N = 400,000 Case 2 N = 600,000 Case 3 N = 800,000 180 160 140 120 100 100 120 140 160 180 200 Space Length Fig. 10. Space length versus total memory requirement. size, a property that a spatial subdivision method does not normally hold. However, very high packing density, i.e. over 0.5, may decrease temporal coherence of the system and consequently increase detection time. This shortcoming of the algorithm can be observed when comparing detection time in Figs. 6 and 9. Table 3 Initial data for examples in Section 4.2 1.111 x K 200 0.00001 1.25 1.429 1.667 10 2 2.5 3.333 Case 1 N = 500,000 Case 2 N = 700,000 Case 3 N = 900,000 9 Detection Time (s) H 8 7 6 5 4 0 2 4 6 Size Ratio 8 Fig. 11. Size ratio versus detection time. 10 5 10 2268 C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 Total Memory Requirement (MByte) 240 220 Case 1 N = 500,000 Case 2 N = 700,000 Case 3 N = 900,000 200 180 160 140 120 0 2 4 6 8 10 Size Ratio Fig. 12. Size ratio versus total memory requirement. 4.3. Influence of size ratio In Table 3, the space length x and update factor K are initialized as constants and the size ratio varies from 1.111 to 10. Influence of the size ratio is then investigated in three different cases, i.e., N = 500,000, N = 700,000 and N = 900,000. In Fig. 11, the detection time changes little while H increases by almost ten times from 1.111 to 10. Fig. 12 shows that the memory cost does not change with the size ratio. In other words, the performance of the SMB algorithm in terms of time and space costs is not affected by the size ratio. 5. Conclusions In this paper, a fast and robust collision detection algorithm for multiple moving AABBs is presented. The performance of the algorithm is comprehensively investigated through theoretical analysis and some elaborately designed numerical examples. Different to most other collision detection algorithms, such as those geometric based, bounding volume hierarchy (BVH) and spatial subdivision, the algorithm presented here is based on a sequencing model. In a system with temporal coherence, detection time and total memory requirement of the SMB algorithm will both become a linear function of N, and this relation is unaffected by any size differences of AABBs, packing density or space size over a large range. Acknowledgments This work is funded by the EPSRC of UK under grant No. GR/R87222/01. This support is gratefully acknowledged. References [1] S. Gottschalk, M.C. Lin, D. Manocha, OBB: a hierarchical structure for rapid interference detection, in: Proc. ACM SIGGRAPH, 1996, pp. 171–181. C.F. Li et al. / Comput. Methods Appl. Mech. Engrg. 195 (2006) 2252–2269 2269 [2] A. Wilson, E. Larsen, D. Manocha, M.C. Lin, Partitioning and handling massive models for interactive collision detection, Comput. Graph. Forum (Proc. Eurographics) 18 (3) (1999), p. C319-+ Sp. [3] D.J. Kim, L.J. Guibas, S.Y. Shin, Fast collision detection among multiple moving spheres, IEEE Trans. Visual. Comput. Graph. 4 (3) (1998) 230–242. [4] S. Redon, A. Kheddar, S. Coquillart, Fast continuous collision detection between rigid bodies, Comput. Graph. Forum 21 (3) (2002), p. 279-+ Sp. [5] J. Canny, Collision detection for moving polyhedra, IEEE Trans. Pattern Anal. Mach. Intell. 8 (2) (1986) 200–209. [6] B. Mirtich, V-clip: fast and robust polyhedral collision detection, ACM Trans. Graph. 17 (3) (1998) 177–208. [7] H. Edelsbrunner, A new approach to rectangle intersections, Int. J. Comput. Math. 13 (3–4) (1983) 209–219. [8] A. Munjiza, K.R.F. Andrews, NBS contact detection algorithm for bodies of similar size, Int. J. Numer. Methods Engrg. 43 (1) (1998) 131–149. [9] Y.T. Feng, D.R.J. Owen, An augmented spatial digital tree algorithm for contact detection in computational mechanics, Int. J. Numer. Methods Engrg. 55 (2) (2002) 159–176. [10] A. Munjiza, D.R.J. Owen, N. Bićanić, A combined finite-discrete element method in transient dynamics of fracturing solids, Int. J. Numer. Methods Engrg. 12 (1995) 145–174. [11] D.R.J. Owen, Y.T. Feng, J. Yu, D. Perić, Finite/discrete element analysis of multi-fracture and multi-contact phenomena, Lecture Notes Comput. Sci. 1981 (2001) 483–505. [12] Y.T. Feng, D. Perić, D.R.J. Owen, A non-nested Galerkin multi-grid method for solving linear and nonlinear solid mechanics problems, Comput. Methods Appl. Mech. Engrg. 144 (1997) 307–325. [13] Y.T. Feng, D. Perić, Coarse mesh evolution strategies in the Galerkin multigrid method with adaptive remeshing for geometrically non-linear problems, Int. J. Numer. Methods Engrg. 49 (2000) 547–571. [14] J. Cohen, M. Lin, D. Manocha, K. Ponamgi, I-COLLIDE: an interactive and exact collision detection system for large-scaled environments, in: Proc. ACM Symposium on Interactive 3D Graphics, 1995, pp. 189–196. [15] E. Perkins, J.R. Williams, A fast contact detection algorithm insensitive to object sizes, Engrg. Comput. 18 (1–2) (2001) 48–61. [16] D.L. Shell, A high-speed sorting procedure, Commun. ACM 2 (7) (1959) 30–32. [17] P. Jimenez, F. Thomas, C. Torras, 3D collision detection: a survey, Comput. Graph. 25 (2) (2001) 269–285. [18] M.C. Lin, S. Gottschalk, Collision detection between geometric models: a survey, in: IMA Conference on Mathematics of Surfaces, San Diego, CA, vol. 1, May 1998, pp. 602–628. [19] J.R. Williams, E. Perkins, B. Cook, A contact algorithm for partitioning N arbitrary sized objects, Engrg. Comput. 21 (2/3/4) (2004) 235–248.
© Copyright 2026 Paperzz