ARTICLE IN PRESS Computers & Graphics 32 (2008) 402– 411
Contents lists available at ScienceDirect
Computers & Graphics journal homepage: www.elsevier.com/locate/cag
Collision detection between complex polyhedra Juan J. Jime´nez , Rafael J. Segura ´n, Campus de las Lagunillas s/n, Dependencia A3-142, 23071 Jae ´n, Spain Computer Science Department, University of Jae
a r t i c l e in f o
a b s t r a c t
Article history: Received 19 December 2007 Received in revised form 6 May 2008 Accepted 9 May 2008
Collision detection (CD) between two objects is a complex task which demands spatial decomposition or bounding volume hierarchy in order to classify the features of the objects for a successful intersection test. Moreover, when the objects are complex and have concavities, holes, etc., the complexity of the decomposition increases and it is necessary to find a method which detects all special cases and degenerations. In this paper, we present a method for CD between complex polyhedra. We use a polyhedron representation based on simplicial coverings. With such as representation it is possible to model complex objects by using simpler objects (simplices), without any previous decomposition into convex pieces. The spatial decomposition so-called tetra-tree is utilized in order to classify the simplices of the covering, as well as a bounding volume hierarchy based on tetrahedra and spheres which allows us to drastically reduce the number of intersection tests between the features of both polyhedra. A time study has been performed to obtain a real time CD between two complex objects. & 2008 Elsevier Ltd. All rights reserved.
Keywords: Barycentric coordinates Collision detection Non-convex geometry Simplicial covering Spatial decomposition Tetra-cone Tetra-tree Tetrahedron
1. Introduction Collision detection (CD) is a well-known problem [1–3]. In this paper, we use the term collision detection to make decision about two moving objects are intersecting each other or not. We distinguish this term from collision determination (finding the colliding parts), and collision response [4] (the subsequent movement or deformation of the colliding objects). CD is usually divided into two phases, the broad phase (reducing the number of pairs of objects) and the narrow phase or detailed collision detection (establishing whether a pair of objects collide). Here we deal with the latter. For an exact CD between frames it is necessary to have a suitable increment of the simulation time in order to assure that an object does not cross another one and all collisions are detected. Some authors choose a continuous CD [5] in order to solve this problem, but this solution is less time effective. On the other hand, to obtain an adequate increment of the simulation time is not an easy task [6]. Usually, a small increment of time is chosen, which increases the time cost of the CD because of the greater number of tests performed when the movement of the objects is divided into a greater number of steps. We use this choice in our proposal.
Corresponding author. Tel.: +34 953212884; fax: +34 953212472.
E-mail addresses:
[email protected] (J.J. Jime´nez),
[email protected] (R.J. Segura). 0097-8493/$ - see front matter & 2008 Elsevier Ltd. All rights reserved. doi:10.1016/j.cag.2008.05.002
Generally, CD systems depend on object representation; some techniques are more appropriate than others for certain types of representations [7]. Most of the algorithms deal with convex objects formed by convex polygons or triangle meshes. We can emphasize, among others, the closest features algorithm [8], the GJK algorithm [9], or the separating vector algorithm [10]. For non-convex objects, either a previous decomposition of the object into convex pieces is performed, or a classification of the features of the object in a hierarchy of bounding volumes. Other studies perform a CD between non-convex objects, as Borro et al. [11]. The development of efficient algorithms for non-convex objects or objects formed by non-convex polygons plays a key role in the decomposition of the object into convex pieces, although this decomposition is carried out in a pre-processing step, is an expensive task and increases the complexity of the problem, due to the fact that big number of pairs of pieces obtained, and the complexity (as it could occur in collision determination) of the composition of the results. In addition, most CD methods use different type of spatial decomposition, like Octrees [12] or BSP-trees [13], in order to classifying the features of the objects and reducing their complexity. To do so several types of hierarchies of bounding volumes are normally used, such us AABB-trees [14], OBB-trees [15], Box-trees [16], Sphere-trees [17] or k-DOP-trees [18]. In this paper, we present a method for a detailed CD between a pair of polyhedra. The nature of the polyhedra considered may be complex; that is, they may be non-convex or formed by nonconvex polygons, or with holes in their interior. However, it is not
ARTICLE IN PRESS J.J. Jime´nez, R.J. Segura / Computers & Graphics 32 (2008) 402–411
necessary to carry out a decomposition into convex pieces in preprocessing if we use simplicial coverings [19]. With this representation we decompose the polyhedron into tetrahedra which may be non-disjoint and obtained directly from the vertices that form the polyhedron; it is only necessary to add a set of arbitrary points. The use of simplicial coverings provide a suitable representation to deal with special cases as could occur in the collision between polyhedra, as well as to contribute a simple, robust and efficient solution, because we deal with basic operations between simplices. By using this representation we will employ a spatial decomposition that utilizes tetra-cones, such that we will construct a tree hierarchy called tetra-tree [20]. This hierarchy will be used for classifying the tetrahedra of the covering of a polyhedron. The classification and a hierarchy of bounding tetrahedra and spheres associated to the tetra-cones, all together, will allow us to quickly discard sets of tetrahedra in the collision test between polyhedra in a simple way. This paper is organized as follows: in Section 2 we will describe the spatial decomposition (simplicial covering and tetratree) and the bounding volumes used. Then in Section 3 we will detail the CD method which uses these elements. In Section 4 we will perform a temporal study in which we will show the efficiency of the implemented algorithm for the CD. Finally, the paper is concluded in Section 5.
2. Polyhedron decomposition In this section we will review and define the data structures used by the spatial decomposition of a polyhedron, as well as the bounding volumes, utilized to classify the features of an object, both of them in the context of a simplicial covering [19] and the representation used by the polyhedra in the collision detection. Most of the data structures for spatial decomposition or hierarchies of bounding volumes used in CD are difficult to update between frames or do not adjust suitably to the represented objects in a proper way. This is less time effective in the CD due to the added cost incurred in updating the data structure between frames. An incorrect adjustment of the bounding volume to the object means a lower number of pairs of features discarded in the CD. In order to avoid these problems of time consuming due to the updating cost and unfitted bounding volumes, we will use an invariant space decomposition called tetra-tree. This decomposition is based on a recursive decomposition of the space by means of tetra-cones, together with a hierarchy of bounding tetrahedra and spheres which fits closely the geometry of the objects. Before a formal definition of the previous concepts, we will present a theorem which supports the simplicial covering theory used by polyhedra representation, and we will define the geometric modeling scheme utilized in collision detection.
403
Theorem 1. Any non-manifold homogeneous polyhedron in three dimensions can be represented as an expression of objects in the following way: A 3D polyhedron with n faces, P, delimited by the set of faces fF i ; i ¼ 1; . . . ; ng, with F i ¼ fEi;j ; j ¼ 1; . . . ; li g given in consistent orientation (the normal vector of each face goes outside the solid), and Ei;j ¼ ðQ i;j Q i;j1 Þ, being Q i;j the j-vertex of the i-face, can be expressed as follows: 0 1 li n X X @ (1) signðSi;j Þ Si;j A P¼ i¼1
j¼1
where Si;j is the tetrahedron OW i Q i;j Q i;j1 , being W i any fixed reference point located in the same plane as face F i and being O any fixed reference point. The theorem defines a generator system for a polyhedron. As can be seen, the tetrahedra do not have to be disjoint. Then we can deal with coverings of the polyhedra, instead of disjoint partitions of them. Now we define the terms covering of face and covering of polyhedron in order to use the previous representation effectively. Definition 1. The covering of a face F i of a polyhedron P (Fig. 1a) is the set of triangles obtained by joining an arbitrary point W i located on the supporting plane of F i (for example, the centroid) with each one of the edges of the face. The arbitrary point W i is called origin of the covering of the face F i . Definition 2. The covering of a polyhedron P (Fig. 1b) is the set of tetrahedra obtained by joining an arbitrary point O (for example, the centroid of the polyhedron), and the triangles obtained in the covering of each one of the faces F i of the polyhedron. The arbitrary point O is called origin of the covering or origin of the tetrahedra of the covering. The main advantage of this approach is that the covering can be obtained in a very simple way with a linear algorithm, maintaining the initial representation of the solid (a vertex-edge-face graph). As well in this approach it is not necessary to store the
2.1. Simplicial covering The following theorem allows us to decompose a polyhedron into oriented tetrahedra. Then we can apply operations to the polyhedron (in our case the construction of the spatial decomposition and collision detection operations) by means of simple operations to tetrahedra. This theorem has been simplified and obtained from the simplicial covering theory presented in [19]. The demonstration and the terms related to the theorem can be seen in detail in the previous reference.
Fig. 1. (a) Covering (left) vs. triangulation (right). (b) Covering of a polyhedron.
ARTICLE IN PRESS ´nez, R.J. Segura / Computers & Graphics 32 (2008) 402–411 J.J. Jime
404
triangulation of the polyhedron; it is only necessary to know the edges of the polyhedron, an arbitrary point for the whole polyhedron and an arbitrary point for each face, and therefore there is no additional information to store.
V3
V3
V0
2.2. Spatial decomposition
(V3+V1)/2
Definition 3. Let T ¼ V 0 V 1 V 2 V 3 be a tetrahedron with positive orientation. A tetra-cone associated to the tetrahedron T, noted as ffT, is the region of the space delimited by the supporting planes of V 0 V 1 V 2 , V 0 V 2 V 3 and V 0 V 3 V 1 , so that T is inside this region (Fig. 2). The tetrahedron T will be called generating tetrahedron of the tetra-cone ffT. Definition 4. A tree of tetra-cones or tetra-tree is a tree structure whose root node has eight sub-tetra-cones as children (ffT 0 , ffT 1 , ffT 2 , ffT 3 , ffT 4 , ffT 5 , ffT 6 and ffT 7 ), all of them with a common origin and covering the entire space without overlappings, except for the border. Each tetra-cone of this first level is divided into four child tetra-cones, the tetra-cone ffT i has four sub-tetra-cones in the second level (ffT i0 , ffT i1 , ffT i2 and ffT i3 ). Each sub-tetra-cone is constructed from the parent tetra-cone ffT i defined by vertices V 0 , V 1 , V 2 , V 3 as follows (Fig. 3): ffT i0 ¼ ðV 0 ; V 1 ; ðV 1 þ V 2 Þ=2; ðV 3 þ V 1 Þ=2Þ ffT i1 ¼ ðV 0 ; ðV 1 þ V 2 Þ=2; V 2 ; ðV 2 þ V 3 Þ=2Þ ffT i2 ¼ ðV 0 ; ðV 3 þ V 1 Þ=2; ðV 2 þ V 3 Þ=2; V 3 Þ ffT i3 ¼ ðV 0 ; ðV 1 þ V 2 Þ=2; ðV 2 þ V 3 Þ=2; ðV 3 þ V 1 Þ=2Þ. In the same way, each tetra-cone is subdivided into four sub-tetracones recursively, until a predefined threshold is reached.
V3 V2 V1 V0 Fig. 2. Tetra-cone definition.
(V2+V3)/2 V0
V2
Here we state the spatial decomposition utilized to classify the features of the polyhedra and accelerate the operations involved in collision detection. Intuitively, a tetra-cone is a region of space delimited by three planes that intersect in a common point. It is possible to define a tetra-cone by means of a tetrahedron in which one of the vertices is situated on the origin of the tetra-cone. This vertex, together with each pair of the three remaining vertices of the tetrahedron defines the planes that delimit this tetra-cone. A tetra-tree is composed by several tetra-cones with a common origin, the centroid of the polyhedron. Therefore these tetra-cones cover the whole space without overlapping, but the borders. When the tetra-tree is constructed, the tetrahedra that form the polyhedron are classified in each one of their tetra-cones. Each tetra-cone is recursively subdivided into new tetra-cones, normally until a maximum depth in the tree is reached, or until the number of triangles classified in a tetra-cone is smaller than a preestablished value. The concepts of tetra-cone and tetra-tree are formally defined as:
T02
T03 T00
V1
T01
V1
V2 (V1+V2)/2
Fig. 3. A tetra-cone and its four sub-tetra-cones.
1 1 x 1 z y Fig. 4. Tetra-cone that represents the octant ðxX0; yX0; zX0Þ.
For each polyhedron is created eight first level tetra-cones, all of them with their origin at the centroid of the object; therefore if a translation of the centroid of the object to the origin of coordinates is carried out then each tetra-cone limits an octant. For example, the first level tetra-cone ffT 0 represents the octant (xX0, yX0, zX0), being T 0 formed by vertices V 0 ¼ ð0; 0; 0Þ, V 1 ¼ ð0; 0; 1Þ, V 2 ¼ ð1; 0; 0Þ and V 3 ¼ ð0; 1; 0Þ (Fig. 4). The other first level tetra-cones are constructed in a similar way so that each one represent an octant, and the vertices of these tetrahedra will be situated on the coordinated axes, with a unitary distance from the origin. When the eight first level tetra-cones have been defined, the tetrahedra of the covering of the polyhedron are classified. Each tetra-cone is subdivided into four sub-tetra-cones and the tetrahedra classified in the parent tetra-cone are classified again in their children. This is done recursively until a threshold is reached (maximum depth in the tree or maximum number of tetrahedra classified in a tetra-cone). We obtain a decomposition which includes all tetrahedra of the covering and which is translation and rotation invariant. This decomposition (Fig. 5) will allow us to deal with certain tetrahedra of the covering of the object, but only with those classified in the tetra-cones involved. Due to the fact that the operations with the polyhedra are performed with simplices (tetrahedra), if we exclude non-related tetrahedra we obtain the same result as when we use all the tetrahedra of the covering. This allows us to perform the collision detection operations (like a segment-face intersection test) only with the tetrahedra classified in some tetra-cones, those tetrahedra of the tetra-cones in which the testing segment is included. The rest of the non-classified tetrahedra do not interfere with the tetrahedra involved in the operations and obtain a correct result for the test. 2.2.1. Tetrahedra classification In order to classify the tetrahedra of the covering of an object in each one of the tetra-cones we must consider several configurations of the classifying tetrahedron S and the tetra-cone ffT (Fig. 6). These configurations are translated into a complete
ARTICLE IN PRESS J.J. Jime´nez, R.J. Segura / Computers & Graphics 32 (2008) 402–411
405
Fig. 5. Polyhedron decomposition using tetra-trees. Tetrahedra associated to tetra-cones of levels 1, 2 and 3 are displayed.
and sequential set of tests which determine whether or not a tetrahedron intersects with a tetra-cone to be classified in a tetracone (taking into account that the tetrahedra and the tetra-cones have a common point, the centroid of the polyhedron):
If any vertex of the triangle V 01 V 02 V 03 is inside the tetra-cone
ffT (Fig. 6a), then the tetrahedron S is classified in the tetracone ffT. If any vertex of the triangle V 1 V 2 V 3 is inside the tetra-cone ffS (Fig. 6b), then the tetrahedron S is classified in the tetracone ffT. If any edge of the triangle V 01 V 02 V 03 intersects with the border of the tetra-cone ffT (Fig. 6c), then the tetrahedron S is classified in the tetra-cone ffT. If none of the previous conditions is satisfied then the tetrahedron S is not classified in the tetra-cone ffT (Fig. 6d).
For the third test we have to verify only two edges with three faces of the tetra-cone, since two edges always intersect with the tetracone (the case of only one edge intersecting the tetra-cone is included in the second test). These verifications have been done by means of the calculation of the sign of the barycentric coordinates of points with regard to the generating tetrahedra of the tetra-cones, considering that in order to verify the inclusion of a point in a tetra-cone it is only necessary to verify the sign of three of the four barycentric coordinates. 2.3. Bounding volumes For each tetra-cone of the tetra-tree we associate a bounding tetrahedron, so that this bounding tetrahedron envelops the geometry of the object contained in the tetra-cone. This is equivalent to incorporate a plane into the tetra-cone in order to limit the geometry contained in it. Afterwards, we define a bounding sphere for the geometry of the object contained in the tetra-cone. This bounding sphere will be used as a previous intersection test between bounding volumes, less expensive than the test between bounding tetrahedra. 2.3.1. Bounding tetrahedron associated to a tetra-cone Definition 5. Let P be a polyhedron with associated tetra-tree TT P . Let T ¼ V 0 V 1 V 2 V 3 be a tetrahedron which satisfies ffT 2 TT F . We
define bounding tetrahedron of the geometry of P contained in ffT as the tetrahedron T b ¼ V 0 V 01 V 02 V 03 where (see Fig. 7): (1) (2) (3) (4)
V 01 is on the ray from V 0 to V 1 . V 02 is on the ray from V 0 to V 2 . V 03 is on the ray from V 0 to V 3 . All vertices V i of the tetrahedra of the covering of P classified in ffT are on the same side as V 0 with regard to the supporting plane of V 01 V 02 V 03 .
Given that in a tetra-cone there exist more than one possible bounding tetrahedron, we will use a bounding tetrahedron that fits to the tetrahedra of the covering classified in this tetra-cone. As this is a complex operation, we use an approximation. This approximation consists of obtaining the farthest vertex from the origin of the covering to the vertices of the tetrahedra classified in a tetra-cone. The distance from this vertex to the centroid is utilized to create an isosceles bounding tetrahedron. Now an iterative algorithm performs an approximation of this bounding tetrahedron to the geometry of the polyhedron. This algorithm is executed a number of times fixed a priori. The algorithm shortens a percentage of the edges’ length of the bounding tetrahedron, one edge at a time, determining if the new tetrahedron is a bounding tetrahedron for the tetra-cone. If this occurs, the edges are shortened again. Otherwise, the last edge is lengthened by a percentage and it is tested again. In Fig. 8 we represent some iterations of this algorithm in a 2D framework. In Fig. 9 is showed the bounding tetrahedra at different levels of the tetra-tree of a polyhedron. The bounding tetrahedra obtained fits properly the geometry of the polyhedra, producing an efficient algorithm properly to the CD. The operations for an acceptable adjustment of the bounding tetrahedra which cause an increment of 50% approximately increasing of pre-processing time. 2.3.2. Bounding sphere associated to a tetra-cone Now we define and associate a bounding sphere for the geometry classified in a tetra-cone. Definition 6. Given a polyhedron P and a tetra-cone ffT 2 TT P , we define a bounding sphere, Eb ðC; rÞ, of the vertices (excluding the origin) of the tetrahedra of the covering of P classified in this tetra-cone ffT. Being C the centroid of these vertices and r the maximum distance from C to each vertex (Figs. 10 and 11).
ARTICLE IN PRESS ´nez, R.J. Segura / Computers & Graphics 32 (2008) 402–411 J.J. Jime
406
V2’ S
V’1
V’3
V’3
S V’ 1
V3
V3
V3
T
V1
V1 V0
V0
V0 V’2
V’2
V’ 1
V’ 3
S
V’3 V3
V’3
V3
V’1 V2
T V1
S
S V’1
V2
V3
V2
V2
T
T
V0
V1
V0
S V3
V’1
T
V1
V1
V’3
S
V2
V2 T
V’2
V’2
V’3
V’2
V0 V’3
V’2
V’2
S V’2 S
V’3
V3
V’ 1 V2
V’ 1
V2
T
V3
V’1
V2
T V1
T V1
V1
V0
V0
V0
V 0 V 01 V 02 V 03
Fig. 6. Relation between the tetrahedron S ¼ to be classified and the tetra-cone ffT, T ¼ V 0 V 1 V 2 V 3 . (a) Tetrahedron S with vertices included in the tetra-cone ffT. (b) The roles of S and T swapped, vertices of T included in the tetra-cone ffS. (c) Some edges of the triangle V 01 V 02 V 03 intersect with the tetra-cone ffT. (d) Tetrahedron S not classified in the tetra-cone ffT.
V’3
V2
V2
V2
V’2
V3
V1
V1 10%
V’
V1 5%
1
V1 V0 Fig. 7. Bounding tetrahedron T b ¼ V 0 V 01 V 02 V 03 associated to a tetra-cone, and geometry classified in this tetra-cone.
V0
V0
V2 10%
V2
V0
V2
20% V1 5%
This bounding sphere and the bounding tetrahedron associated to a tetra-cone are used for limiting the geometry included in the tetra-cone. Hence we may consider that the volume, we are dealing with, is the intersection between the sphere and the tetrahedron. In the CD phase, first we will check if the bounding spheres intersect, and later if the bounding tetrahedra intersect, at different levels in the hierarchy of the tetra-trees. Only when there is an intersection bounding volumes in the last level of the hierarchies will be the exact intersection test between the geometry contained in the bounding volumes performed.
V0
30% V1 5%
V0
V1 5% V0
Fig. 8. Bounding tetrahedron adjustment (2D representation).
2.3.3. Regular hull of a polyhedron Now we define the concept of the regular hull of a polyhedron. This concept will support the rapid elimination of bounding tetrahedra in the collision test between polyhedra, taking advantage of the properties of this regular and convex hull. This regular hull is composed of a set of bounding tetrahedra associated to the tetra-cones of a level of the tetra-tree. Therefore,
ARTICLE IN PRESS J.J. Jime´nez, R.J. Segura / Computers & Graphics 32 (2008) 402–411
407
Fig. 9. Bounding tetrahedra (levels 3–6).
we obtain a regular hull at each level for the corresponding tetra-tree. Definition 7. Let P be a polyhedron with associated tetra-tree TT P . Let X b be the set of bounding tetrahedra associated to a level of TT P . Let dmax be the maximum distance between V 0 and each one of the vertices V 01 , V 02 and V 03 of each tetrahedron of X b . We define a regular hull of P, X rh as the set of bounding tetrahedra obtained when we substitute the points V 01 , V 02 and V 03 from each bounding tetrahedron T b 2 X b with V 001 , V 002 and V 003 situated on the rays V 0 V 01 , V 0 V 02 and V 0 V 03 , respectively, and with distance dmax from V 0 . Intuitively, the regular hull definition obtains for each level of the tetra-tree of a polyhedron, a set of bounding tetrahedra whose triangles V 001 V 002 V 003 form a convex hull for the polyhedron (Fig. 12).
3. Collision detection Our proposal of algorithm for CD between polyhedra is based on going through the hierarchies of the tetra-trees associated to both polyhedra. Then we will obtain the tetra-cones involved in the collision due to the intersection between bounding spheres and bounding tetrahedra. This approach reduces the number of pairs of tetra-cones, thus reducing the number of features of both polyhedra for the intersection test. The following theorem provides a way to discard bounding tetrahedra from both polyhedra quickly by using the bounding tetrahedra of a regular hull. Given two polyhedra, we discard bounding tetrahedra of one with regard to bounding tetrahedra of a regular hull of the other. Theorem 2. Let P and Q be two polyhedra with associated tetratrees TT P and TT Q . Let T rh ¼ V 0 V 001 V 002 V 003 be a bounding tetrahedron from a regular hull X rh associated to a determined level of TT P . Any bounding tetrahedron T b 2 TT Q whose vertices are on the opposite side to V 0 regarding the supporting plane of the triangle V 001 V 002 V 003 , satisfies that T b does not intersect with any bounding tetrahedron from TT P (Fig. 13a). Given that the regular hull is convex its demonstration is evident. With the following definition we can choose the appropriated bounding tetrahedra (reference bounding tetrahedra) from a pair
V’3
V’2
V3 V’ 1 V1 V0 Fig. 10. Bounding sphere of the vertices (excluding the origin) of tetrahedra classified in a tetra-cone.
of polyhedra in order to apply Theorem 2 and eliminate bounding tetrahedra from both polyhedra to the CD. Definition 8. Given two polyhedra P and P0 with regular hulls X rh and X 0rh regarding to the deeper level of TT P and TT P0 with origin at C and C 0 , respectively. We say that T rh 2 X rh and T 0rh 2 X 0rh are reference bounding tetrahedra if ½C in ffT 0rh and ½C 0 in ffT rh (Fig. 13b). This definition suppose the elimination of bounding tetrahedra and then reduce the calculations for the CD between polyhedra, overall when the objects under consideration are far away. To do this, we apply Theorem 2 to the reference bounding tetrahedra of the polyhedra and each one of the bounding tetrahedra, for the different levels of the tetra-tree of each polyhedron. In this way, we obtain a reduced set of bounding tetrahedra for the intersection test (Fig. 14a), discarding the rest. Initially, in a pre-processing step, it is necessary to classify the tetrahedra of the covering of the polyhedron in the tetra-cones which form the tetra-tree. For each tetra-cone a bounding tetrahedron and a bounding sphere, both of the geometry of the polyhedron contained in this tetra-cone, are generated. In the phase of CD between a pair of polyhedra (Algorithm 1), firstly it applies the concept of regular hull and Theorem 2 in order to discard pairs of bounding tetrahedra (and tetra-cones). To do this, Theorem 2 is applied to the reference bounding tetrahedra of the polyhedra (Fig. 14a). Secondly, by using only the tetra-cones not discarded yet, the algorithm traverses recursively the tetratrees of both polyhedra, and discards pairs of tetra-cones for the CD, utilizing the bounding spheres (Fig. 14b) and bounding tetrahedra (Fig. 14c).
ARTICLE IN PRESS ´nez, R.J. Segura / Computers & Graphics 32 (2008) 402–411 J.J. Jime
408
Fig. 11. Bounding spheres associated to the tetra-cones of a level. Levels 4–6.
Fig. 12. Bounding tetrahedra of a regular hull of a polyhedron.
Given two nodes from two tetra-trees, and only if an intersection between bounding volumes occurs, we descend recursively to the children nodes until we reach two leaf nodes. An effective criteria to accomplish this task can be the respective volume of the nodes (descending first by the ones with the greatest volume). When we reach the leaf nodes we perform a detailed collision test between segments and faces (both classified in the corresponding tetra-cones). For the segment-face intersection test we use a method similar to the one described in [21], based on the concept of simplicial covering but optimized and adapted to our particular situation. This method could be extended to obtain the features of the polyhedra involved in the collision (collision determination) in an easy way.
4. Time study In this section we study the efficiency of the algorithm for the CD between polyhedra. We measure the number of frames per second which in turn represents the number of executions of the algorithm per time unit. The time needed for the visualization has not been considered. We used an Intel Pentium IV - 1.6 GHz processor with 1 MB RAM in a Linux operating system. The algorithm was implemented in C þ þ with gcc, using OpenGL for visualization.
We used polyhedra of two types (Fig. 15): on the one hand complex polyhedra with flat and non-convex faces, some with holes inside; and on the other hand polyhedra formed by triangle meshes. Two complex polyhedra and two triangle meshes have been used in the tests; the first one with fewer vertices than the triangle meshes. The relative size of a pair of testing polyhedra has been varied, a relative size of 1: X meaning that the radius of the bounding sphere of the first polyhedron is 1=X of the second. The relative sizes considered were 1:1, 1:2, 1:4, 1:8 and 1:16. The position of one polyhedron has been fixed and the other moves with regard to the first one. Two types of trajectories have been considered. First a circular trajectory on a random plane which crosses the centroid of the fixed object, with center on the centroid and a radius adapted to the polyhedron; therefore the collision percentage is smaller than 5% and both polyhedra are close. This circular trajectory is modified by a small random translation for each position. The second trajectory is the contour trajectory. The moving object goes nearby the border of the static object, at a small distance and with a small random translation for each position. The collision percentage is in the range of 5–10%. For each polyhedron a tetra-tree has been constructed in a preprocessing step, with a depth adjusted to the number of vertices of the polyhedron and to the relative size of the objects. We have compared the number of frames per second obtained in the CD between all the pairs of objects considered (Complex polyhedron I and II, cat and horse), with a relative size of 1:1 for circular and contour trajectories (Fig. 16). We obtain a CD rate greater than 50 frame/s (real time) for all combinations of objects and trajectories. Regarding the pairs of objects with different relative sizes (Fig. 17) we have obtained better times when the relative size is greater. This is due to the increasing of spatial coherence with the subsequent decreasing in the number of intersection tests performed between bounding volumes.
5. Conclusions In this paper we have developed a set of techniques for CD between 3D objects using simplicial coverings. We used a spatial decomposition so-called tetra-tree to classify the simplices of the covering of an object, and bounding volumes to accelerate the CD calculation.
ARTICLE IN PRESS J.J. Jime´nez, R.J. Segura / Computers & Graphics 32 (2008) 402–411
409
Q Tb6
Tb5
3
Tb
7
Tb V’’ 2
4
Tb
2 8 Tb T 1 Tb b
T’rh
P’
Trh 1
V0
C’
V’’ 1
Trh
Tb
X’rh
C P
P Xrh
Xrh
Fig. 13. (a) If we apply Theorem 2 to a bounding tetrahedron T rh (in red) from a regular hull of the polyhedron P, we obtain a set of bounding tetrahedra of Q that do not intersect with any bounding tetrahedron of P (in green). (b) Reference bounding tetrahedra of two polyhedra (in solid red).
Fig. 14. (a) Theorem 2 applied to bounding tetrahedra (we show the bounding tetrahedra of the regular hull which passes the test). (b) Collision between bounding spheres. (c) Bounding tetrahedra considered for the detailed intersection test between edges and faces (after applying Theorem 2 and confirm that the bounding volumes intersect).
We obtain a CD time which allows us to use the developed algorithm with interactive and real time applications. The simplicial covering representation allows us to reduce the number of special cases, our algorithms being more robust than others due to the operations performed by means of the sign of the barycentric coordinates (3 3 determinants). The sign
calculation is only limited by the precision of the evaluation of determinants [22], calculated with a determined tolerance or error. Future work includes: the use of tetra-trees for other types of applications like modeling, levels of detail, deformable objects, etc. The development of new algorithms for the CD based on the
ARTICLE IN PRESS 410
´nez, R.J. Segura / Computers & Graphics 32 (2008) 402–411 J.J. Jime
Fig. 15. Polyhedra used in tests. (a) Complex polyhedron (32 vertices, 18 faces). (b) Complex polyhedron II (44 vertices, 29 faces). (c) Triangle mesh (cat, 382 vertices, 760 faces). (d) Triangle mesh (horse, 3582 vertices, 7172 faces).
Fig. 16. Frame/s for the CD between objects. (a) For contour trajectory. (b) For circular trajectory.
by the Consejerı´a de Innovacio´n, Ciencia y Empresa of the Junta de Andalucı´a through the research projects P06-TIC-01403 and P07TIC-02773.
Appendix A
Fig. 17. Frame/s for the CD between horse and horse with different relative size for contour and circular trajectories.
use of particles, collision response algorithms, and finally their implementation in the programmable GPU.
Acknowledgments This work has been partially supported by the Spanish Ministry of Education and Science and the European Union (via ERDF funds) through the research project TIN2007-67474-C03-03, and
Algorithm 1. Collision Detection between complex polyhedra. bool polyhedron::CollisionDetection(polyhedron P) { if (not this.boundingSphere().intersects(P.boundingSphere())) return false Tref1 ¼ this.getReferenceBoundingTetrahedron(P.V 0 ()) // definition 7 Tref2 ¼ P.getReferenceBoundingTetrahedron(this.V 0 ()) for (tc ¼ 0; tc o 8; tc++) { //theorem 2 P.child(tc).removeBoundingTetrahedra(Tref1) this.child(tc).removeBoundingTetrahedra(Tref2) } for (tc1 ¼ 0; tc1 o 8; tc1++) if (this.child(tc1).considered()) for (tc2 ¼ 0; tc2 o 8; tc2++) if (P.child(tc2).considered()) if (this.child(tc1).CollisionDetection(P.child(tc2))) return true return false }
ARTICLE IN PRESS J.J. Jime´nez, R.J. Segura / Computers & Graphics 32 (2008) 402–411
bool tetracone::CollisionDetection(tetracone tc) { if (not this.boundingSphere().intersects(tc.boundingSphere())) { return false if (not this.boundingTetrahedron().intersects(tc.boundingTetrahedron())) return false if (this.isLeaf() and tc.isLeaf()) { if (this.DetailedCollisionDetection(tc) or tc.DetailedCollisionDetection(this)) return true } else if (this.isLeaf()) { for (tc1 ¼ 0; tc1 o 4; tc1++) if (tc.child(tc1).considered()) if (tc.child(tc1).CollisionDetection(this) return true } else if (tc.isLeaf()) { for (tc2 ¼ 0; tc2 o 4; tc2++) if (this.child(tc2).considered()) if (this.child(tc2).CollisionDetection(tc) return true } else { for (tc1 ¼ 0; tc1 o 4; tc1++) if (this.child(tc1).considered()) for (tc2 ¼ 0; tc2 o 4; tc2++) if (tc.child(tc2).considered()) if (this.child(tc1).CollisionDetection(tc.child(tc2))) return true } return false } bool tetracone::DetailedCollisionDetection(tetracone tc) { for (edge ¼ 0; edge o tc.numberOfEdgesClassified(); edge++) { Q1Q2 ¼ tc.edgeClassifed(edge) for(face ¼ 0; face o this.numberOfFacesClassified(); face++) if (this.faceClassified(face).intersects(Q1Q2)) return true } return false } void tetracone::removeBoundingTetrahedra(tetrahedron Tref) { this.considered ¼ false for (vert ¼ 1; vert o 4; vert++) if (Tref.sameSideAsV 0 regardToV 1 V 2 V 3 (this.boundingTetrahedron().vertex(vert))) { this.considered ¼ true for (tc ¼ 0; tc o 4; tc++) this.child(tc).removeBoundingTetrahedra(Tref) break } }
411
References [1] Garcia-Alonso A, Serrano N, Flaquer J. Solving the collision detection problem. IEEE Computer Graphics and Applications 1994;3(3):35–43. [2] Jimenez P, Thomas F, Torras C. 3D collision detection: a survey. Computers and Graphics 2001;25:269–85. [3] Ericson C. Real-time collision detection. Los Altos, CA, Amsterdam: Morgan Kaufmann, Elsevier; 2005. [4] Bergen G. Collision detection in interactive 3D environments. Los Altos, CA, Amsterdam: Morgan Kaufmann, Elsevier; 2004. [5] Redon S, Kheddar A, Coquillart S. Fast continuous collision detection between rigid bodies. Computer Graphics Forum 2002;21:3. [6] Snyder JM. Interval analysis for computer graphics. In: Proceedings of SIGGRAPH’92. Computer Graphics 1992;(26)2. [7] Lin MC, Gottschalk S. Collision detection between geometric models: a survey. In: IMA conference on mathematics of surfaces; 1998. [8] Lin MC, Canny JF. Efficient algorithms for incremental distance computation. In: IEEE conference on robotics and automation; 1991. p. 1008–14. [9] Gilbert E, Johnson D, Keerthi SS. A fast procedure for computing the distance between complex objects in three-dimensional space. IEEE Journal of Robotics and Automation 1988;4(2). [10] Chung K, Wang W. Quick collision detection of polytopes in virtual environments. In: Proceedings of the ACM symposium on virtual reality software and technology (VRST 96); 1996. p. 125–32. [11] Borro D, Garcı´a-Alonso A, Matey L. Approximation of optimal voxel size for CD in maintainability simulations within massive virtual environments. Computer Graphics Forum 2004;23(1):13–23. [12] Ayala D, Brunet P, Juan R, Navazo I. Object representation by means of nonminimal division quadtrees and octrees. ACM Transactions on Graphics 1985;4(1):41–59. [13] Naylor B, Amanatides J, Thibault W. Merging bsp trees yield polyhedral modeling results. In: Proceedings of ACM SIGGRAPH; 1990. p. 115–24. [14] Bergen G. Efficient collision detection of complex deformable models using AABB trees. Journal of Graphics Tools 1997;2(4):1–14. [15] Gottcshalk S, Lin MC, Manocha D. OBB-Tree: A hierarchical structure for rapid interference detection. In: Proceedings of the ACM SIGGRAPH; 1996. p. 171–80. [16] Zachmann G. Rapid collision detection by dynamically aligned DOP-trees. In: Proceedings of IEEE virtual reality annual international symposium VRAIS’98; 1998. p. 90–7. [17] Bradshaw G, O’sullivan C. Adaptative medial-axis approximation for spheretree construction. ACM Transactions on Graphics 2004;23(1):1–26. [18] Klosowski JT, Held M, Mitchell JSB, Sowizral H, Zikan K. Efficient collision detection using bounding volume hierarchies of k-dops. IEEE Transactions on Visualization and Computer Graphics 1998;4(1):21–36. [19] Feito FR, Torres JC. Boundary representation of polyhedral heterogeneous solids in the context of a graphic object algebra. The Visual Computer 1997;13:64–77. [20] Jimenez JJ, Feito FR, Segura RJ, Ogayar C. Particle oriented collision detection using simplicial coverings and tetra-trees. Computer Graphics Forum 2006;25(1):53–68. [21] Segura RJ, Feito FR. An algorithm for determining intersection segmentpolygon in 3D. Computer and Graphics 1998;22(5):587–92. [22] Avanaim F, Boissonnat JD, Devillers O, Preparata FP, Yvinec M. Evaluating sings of determinants using simple-precision arithmetic. Algoritmica 1997;17:111–32.