A collision detection method for 3D CAD models based on BVH and sum-of-squares programming
By combining BVH with square sum planning, the problem of low efficiency in calculating the minimum distance between geometric objects in 3D CAD software is solved, and efficient collision detection and intersection judgment are achieved, which is suitable for 3D CAD systems.
Patent Information
- Application Number
- CN202411050729.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-01
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2044-08-01
AI Technical Summary
Existing 3D CAD software is inefficient in calculating the minimum distance between geometric objects. In particular, the algorithms between different types of geometric objects are complex and inconsistent, resulting in overall inefficiency.
A unified algorithm flow is designed by combining the bounding box hierarchy (BVH) with the sum-of-squares programming (SOSP). By constructing a BVH tree, the parameter range of geometric objects is narrowed down, and the minimum distance problem is solved using the sum-of-squares programming.
It improves the efficiency and accuracy of calculating the minimum distance between geometric objects, can quickly determine collision and intersection relationships, and is suitable for collision detection and picking operations in 3D CAD systems.
Smart Images

Figure CN119129183B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of three-dimensional CAD model query calculation, and in particular relates to a three-dimensional CAD model collision detection method based on BVH and square sum planning. Background Art
[0002] Modeling software is rapidly developing, and 3D modeling tools are now required in many industries, such as gaming, film and television, architecture, and industrial design. In these industries, 3D modeling tools can easily help developers create 3D models and streamline the product design process. During these processes, developers often encounter the problem of finding the minimum distance between two geometric elements.
[0003] 3D CAD software uses precise mathematical models to represent 3D objects. These models can be constructed solid geometry (CSG) or boundary representation models (B-Rep). The goal of solving the minimum distance problem is to calculate the distance between the geometric objects that make up the geometric entity and find the two closest points, including the distance between points, points and lines, points and surfaces, lines and lines, lines and surfaces, or surfaces.
[0004] Exact geometry algorithms can be used to calculate the exact distance between two geometric objects, but they have specific requirements for the expression form and geometric structure of geometric objects. They are generally used for geometric objects such as lines, circles, ellipses, planes, and spheres that can be represented by explicit or implicit equations, and use analytical algorithms to solve the minimum distance between them.
[0005] For general geometric objects, consider two sets A and B consisting of objects. The question is how to find the minimum distance between A and B. A naive solution is to perform a double loop through the elements in A and B, calculating the distance between each pair of elements and updating the currently calculated minimum distance to obtain the result. If |A| = m and |B| = n, the time complexity is O(mn), which is relatively inefficient. If the two geometric objects are of different types, different algorithms are often required. For example, for point-curve, point-surface, curve-curve, curve-surface, and surface-surface, the algorithmic processes for each are often different, and some can be quite complex, leading to overall inefficiency.
[0006] A bounding box hierarchy (BVH) is a space partitioning data structure commonly used in computer graphics and collision detection. It is used to efficiently organize and query objects in three-dimensional space, especially in scenes where distances between objects need to be quickly retrieved or collisions need to be detected. A BVH is constructed by recursively dividing a collection of objects into two subsets and computing a new bounding box for each subset. This process starts with all objects in the scene and continues until the number of objects in each subset reaches a certain threshold or the objects in each subset can be compactly enclosed by a single bounding box. BVH is widely used in real-time rendering systems, physics engines, animation, and simulation software to accelerate collision detection, ray casting, occlusion queries, and more.
[0007] Sum of Squares Programming (SOSP) is a mathematical technique for solving polynomial optimization problems. It exploits the property that polynomials can be expressed as sums of squares to transform and solve optimization problems that are otherwise difficult to handle. Polynomial optimization problems typically involve minimizing or maximizing a polynomial objective function under polynomial constraints. Such problems arise in many practical applications, such as control theory, economics, and engineering design. The core idea of Sum of Squares Programming is to transform a polynomial optimization problem that is difficult to solve directly into one that can be solved using Semidefinite Programming (SDP).
[0008] Solving the minimum distance problem can utilize BVH and SOSP to improve the efficiency of the algorithm and the accuracy of the results. In 3D CAD systems, solving the minimum distance can be applied to collision detection to determine whether two geometrically intersecting objects intersect or overlap. Summary of the Invention
[0009] In view of the shortcomings of the prior art, the present invention aims to provide a collision detection method for 3D CAD models based on BVH and sum-of-squares programming.
[0010] The object of the present invention is achieved through the following technical solution: a collision detection method for a 3D CAD model based on BVH and square sum programming, the specific steps are as follows:
[0011] 1. The 3D CAD system models the two geometric objects A and B for which the minimum distance needs to be determined, or directly imports the information of models A and B. The BVH tree is constructed for the geometric objects. The height of the BVH tree is determined based on the size of the geometric objects in actual physical space and the parameter range. Generally speaking, the more complex the geometric objects and the larger the actual volume represented, the higher the BVH tree height. Then, parameter node pairs are initialized, with each node containing the geometric information of the corresponding geometric object and the divided parameter range.
[0012] 2. Select all leaf nodes in the BVH of the two geometric objects, calculate the minimum and maximum distances between the AABBs, calculate the minimum maximum distance minMaxDist between the bounding boxes of all leaf nodes of the two geometric objects, save all node pairs with a minimum distance less than or equal to minMaxDist into a structure array, and recursively replace adjacent nodes with their parent nodes to reduce the total number of node pairs; the structure array contains node geometry information, parameter ranges, and minimum distances;
[0013] 3. Substitute the parametric equations and parameter ranges of the node pairs calculated in step 2, as well as the corresponding constraints that limit the shape of the geometric objects, into the square sum planning solver model, calculate the minimum distance between each node pair, and update the global minimum distance to ultimately obtain the minimum distance between the two geometric objects.
[0014] 4. Compare the minimum distance calculated in step 3 with the threshold in the actual collision detection scenario. If the minimum distance is less than the threshold, it indicates that geometric objects A and B have collided. Furthermore, if the intersection area of A and B needs to be solved, the point with the closest distance between A and B can be used as the initial point for subsequent algorithm processes such as Newton's iteration. If the minimum distance is greater than or equal to the threshold, it indicates that geometric objects A and B have not collided. Further, subsequent intersection algorithm processes can be avoided.
[0015] Furthermore, the geometric information in step 1 is specifically: parametric equations of curves and surfaces, the curves include straight lines, circles, ellipses, and B-spline curves, and the surfaces include planes, cylinders, cones, spheres, tori, and B-spline surfaces.
[0016] Furthermore, for any of the curve or surface types, it is necessary to construct a suitable BVH structure according to the corresponding data structure and divide it into nodes of appropriate sizes, and then apply the node pairs that may have the closest distance to each other to the square sum programming model for solution.
[0017] Furthermore, the B-spline curve is decomposed and calculated segment by segment to calculate the polynomial expression between each node. For example, for a quadratic B-spline curve with ten control points, according to the relationship between the number of control points of the B-spline curve and the knot vector (knot), it can be decomposed into eight segments of curves that satisfy the quadratic function. The result is q(t)=at 2+bt+c,i∈[1,8],t∈[knot[i],knot[i+1]]; the B-spline surface is decomposed piece by piece to calculate the polynomial expression of the surface patches between adjacent nodes. A k×l-degree B-spline surface containing (m+1)×(n+1) control points can be decomposed into (m-k+1)×(n-l+1) k×l-degree parametric polynomial surfaces.
[0018] Furthermore, step 2 is divided into the following sub-steps:
[0019] 2.1. Select all leaf nodes in the BVH of geometric objects A and B, denoted as S(A) and S(B) respectively; each node represents an AABB bounding box; calculate the distance between the eight vertices of the two bounding boxes to obtain the minimum and maximum distances between the AABB bounding boxes, denoted as a∈S(A) and b∈S(B), where a represents a leaf node of geometric object A and b represents a leaf node of geometric object B. Record the minimum distance minDist between the bounding boxes of nodes a and b. ab and the maximum distance maxDist ab ;
[0020] 2.2. Traverse S(A) and S(B), first calculate the maximum distance maxDist between a and b through a double loop ab , update the minimum maximum distance minMaxDistGlobal between the global BVH nodes, and then save the minimum distance minDist between a and b ab And the a and b node information into a structure array minDistStruct[];
[0021] 2.3. Sort the structure array minDistStruct[] described in step 2.2 in ascending order according to the size of the structure member minDist by quick sorting, and let the set of elements whose structure member minDist is less than or equal to minMaxDistGlobal be T(A) and T(B); for the elements in T(A) and T(B), if there are adjacent node pairs, use the parent node to replace the adjacent node, for example, if there is a node pair {nodeA l ,nodeB l}, {nodeA r ,nodeB r}, then modify it to {nodeA,nodeB}, nodeA, nodeB are the parent nodes of these nodes. Generally speaking, this is a recursive process to achieve the purpose of reducing the number of node pairs in T.
[0022] Furthermore, step 3 is divided into the following sub-steps:
[0023] 3.1. Traverse T(A) and T(B) in step 2, record a∈T(A), b∈T(B), and set the parameter range of a to be [pMin a ,pMax a ], the parameter range of b is [pMin b ,pMax b ]; According to Putinar's theorem, any strictly positive polynomial f(u) in its domain can be decomposed into Where si(i∈[0,m]) is an arbitrary polynomial, gi is a non-negative polynomial on the domain; if there is an equality constraint, then f(u) is decomposed into Where pi is an arbitrary polynomial, hi is a polynomial that is zero on the domain;
[0024] 3.2. For the minimum distance problem, use square sum programming to solve the minimum distance between two geometric objects. Assume that the domain of object one is The domain of object 2 is let where q j It is a related constraint used to limit the shape of geometric objects; define two geometric objects as x 1 (u 1 ) and x 2 (u 2 ), so the distance between the two can be defined as Require the minimum distance, that is, find f * =minf(u 1 ,u 2 ), and to find the corresponding points of the two geometric objects with the closest distance, that is, to find u * =argminf(u 1 ,u 2 ).
[0025] Substitute the parameter range pairs for each node pair calculated in the previous step, the corresponding parametric equations, and the constraints used to restrict the shape of the geometric objects into the square sum programming solver model. Use a constraint solver such as YALMIP or MOSEK to convert it into a semidefinite programming solution for solution. Calculate the minimum distance between each node pair and update the global minimum distance to ultimately obtain the minimum distance between the two geometric objects.
[0026] The beneficial effects of the present invention are as follows: the present invention accelerates the search for node pairs with the possible minimum distance based on BVH, narrows the parameter range of two geometric objects, and uses square sum programming to solve the minimum distance problem. A unified algorithm process is designed for solving the minimum distance between various types of geometric objects. The algorithm can be applied to collision detection in a three-dimensional CAD system and to determine whether two geometric objects have an intersecting or overlapping relationship, as well as to quickly find the geometric object closest to the current mouse position during a picking operation so as to edit it. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 It is a flow chart of the present invention. DETAILED DESCRIPTION
[0028] In various modeling engines, explicit equations or implicit equations are usually used to represent various types of geometric objects such as curves or surfaces. Explicit equations directly give a parametric representation of the geometric object. The advantage of this method is that it is intuitive, easy to understand, and easy to implement, but the computational complexity may be high in some cases. Implicit equations can describe more complex geometric shapes, such as Bezier surfaces or nonlinear curves. The advantage of implicit equations is that they can express complex geometric shapes concisely, but analytical solutions may be more difficult. Regardless of the representation method, to calculate the minimum distance between two geometric objects, the parameter range can be narrowed by constructing a BVH and calculating the distance between the two BVH nodes, and then the minimum distance between the two geometric objects can be solved using a square sum programming optimization algorithm on a small parameter domain.
[0029] like Figure 1 As shown, the present invention proposes a three-dimensional CAD model collision detection method based on BVH and square sum planning, and the detailed process of the method is as follows.
[0030] Step 1: Import or construct two geometric objects A and B in a 3D CAD system, preprocess them, and select a layer with a certain depth to construct a BVH. The BVH construction process is as follows: first, determine the depth of the BVH tree, then construct the BVH tree from the bottom up. Decompose the geometric objects into multiple nodes based on the depth, calculate the bounding box for each node, and store this information. Then, create parent nodes for these leaf nodes, merge adjacent leaf nodes, calculate the bounding box of the merged node, and store it in the parent node. Then, use these parent nodes as child nodes and create parent nodes for them, until only one node remains, which serves as the root node of the BVH. For B-spline curves or B-spline surfaces, when constructing the BVH, the nodes are divided using the knots of the curves or surfaces as the demarcation points. Each curve segment or surface patch thus divided can be represented as a parametric curve or surface, thus decomposing the entire parametric expression of the B-spline curve or surface into parametric expressions over multiple small parameter domains, which is convenient for application in the square sum planning process and obtains more accurate results. Taking a quadratic B-spline curve with six control points as an example, according to the basis function definition, it is decomposed into four segments of cubic parametric curves, such as f(t) = at 2 +bt+c, where a, b, and c are the coefficients of the parametric curve from the highest order to the zeroth order, and t is the parameter on this segment of the curve. The bounding box is calculated for these four segments of the curve and then the BVH is constructed. The specific decomposition process is as follows:
[0031] According to the definition of B-spline curve Among them, P i is the control point, N i,k is the basis function, k represents the degree of the B-spline curve, n represents the number of control points of the B-spline curve, N i,k Specifically defined as:
[0032]
[0033] knot[i]≤t <knot[i+1]
[0034] According to the recursive condition, the non-zero basis functions on [knot[i], knot[i+1]] are expanded to obtain a quadratic equation about t. Furthermore, after multiplying with the control point P, three parametric equations about the x, y, and z directions are obtained. Define the double array param_a[3], param_b[3], param_c[3] to store the intermediate variables of the coefficients of the parametric equations of x, y, and z about t after the basis functions are expanded on the interval. The calculation can be obtained:
[0035]
[0036]
[0037] Then a loop is used to calculate the parameters of the parametric equation of the actual point coordinates about t, which is defined as std::vector <double>coefficientX, coefficientY, coefficientZ. coefficientX+={param_a[j]*P[ij].x,param_b[j]*P[ij].x,param_c*P[ij].x},j∈[0,2], coefficientY and coefficientZ are the same. Finally, std::vector <std::vector <double>> coefficients_i = {coefficientX, coefficientY, coefficientZ} added to a std::vector used to store the coefficients of the parametric equation of each curve segment <std::vector<std::vector <double>>>In curveParams, the decomposition of the quadratic B-spline curve is completed.
[0038] Step 2: Select all leaf nodes from the two BVHs constructed in step 1 and record them as node sets S A and S B , for two S a and S B Traverse and calculate the maximum distance between the bounding boxes of each two nodes, and update the minimum maximum distance minMaxDistance at the same time. Use a structure array (minDistStruct[]) to save the minimum distance minDist between the bounding boxes of each two nodes and the pointer to the corresponding two nodes. Then use quick sort to sort minDistStruct[] in ascending order according to minDist, and find the element set T with the minimum distance less than or equal to minMaxDistance. Further process the elements in T. If there are node pairs of adjacent nodes, replace them with parent node pairs. The specific operation is: if T contains element T i 、T j , T i Contains node node_a i and node_b i ,T j Contains node node_a j and node_b j ,node_a represents the BVH node belonging to geometric object A, node_b represents the BVH node belonging to geometric object B, if node_a i and node_a j For the same parent node node_a parent The child node of node_b i and node_b j For the same parent node node_b parent child nodes, you can i 、T j Merged into T new , the node information included is updated to node_a parent and node_b parebt , looping until there are no more pairs of elements that can be merged.
[0039] Step 3: Further process the elements in the set T obtained in Step 2 whose minimum distance between bounding box pairs is less than or equal to minMaxDistance. Based on the pointer to the BVH node contained in each element, find the specific node and restore the relevant information belonging to the original geometric object (specific parameter expressions and parameter ranges), and substitute this information into the square sum planning solver model. In this invention, the square sum planning is specifically solved using the MOSEK optimization solver. The MOSEK fusion API is called to construct an SOS model for solving the minimum distance. The specific constraint information is then substituted into the model and converted into a problem solved by semidefinite programming.
[0040] Taking the solution of the minimum distance between two B-spline curves as an example, according to the curveParams information obtained in step 1, the coordinates of the point [x, y, z] on the curve can be expressed as Where t∈[t0, t1], assuming that the point on curve A is a point on curve b, it can be expressed as q(t), so the objective function is The goal of the sum-of-squares programming is f * =minf(t1,t2), and find t * =minargf(t1,t2). Use the interface provided by MOSEK to set variables, equality and inequality constraints, for example, set the point on curve A to P A ={X A ,Y A ,Z A }, where X A =Expr::add(Expr::mul(curveParams[i][0],Expr::mul(t,t)),Expr::add(Expr::mul(cur veParams[i][1],t),curveParams[i][2])), Y A ,Z A Similarly. Set the constraint condition M->constraint(Expr::vstack(u1,diff_X),Domain::inQCone()), where diff_X represents the difference in the X values of the two coordinates. The same applies to u2, u3, diff_Y, and diff_Z. Set the objective function to dist_sq = Expr::add(Expr::add(u1,u2),u3); then call the solve function to calculate the minimum distance between the two curves and save it to an array. Finally, find the minimum value in the array to determine the minimum distance between the two B-spline curves. According to the corresponding t * Inversely find the points on the two curves that correspond to the minimum distance.
[0041] In the collision detection scenario, the minimum distance obtained above is compared with a preset threshold. If the minimum distance is less than the threshold, it indicates that the geometric objects A and B collide. Furthermore, if it is necessary to solve the intersection area of A and B, the point with the closest distance between A and B can be used as the initial point for subsequent algorithm processes such as the Newton iteration method; if the minimum distance is greater than or equal to the threshold, it indicates that the geometric objects A and B do not collide. Furthermore, subsequent intersection algorithm processes can be avoided.
[0042] This completes the detailed description of our 3D CAD model collision detection method based on BVH and sum-of-squares programming. We implement the calculation of minimum distances between geometric objects, such as points, curves, and surfaces, and perform specialized processing on B-spline curves and surfaces, ultimately delivering collision detection results between two geometric objects. After extensive testing, our algorithm has demonstrated efficiency and accuracy that meets the requirements of current mainstream modeling software.< / double> < / double> < / double>
Claims
1. A 3D CAD model collision detection method based on BVH and square sum programming, characterized in that: The steps include: (1) Import the geometric objects A and B that need to be collided, construct the BVH of geometric objects A and B, and initialize the parameter node pairs. Each node contains the geometric information of the geometric object and the divided parameter range. (2) Select all leaf nodes in the BVH, calculate the minimum and maximum distances between AABB bounding boxes, calculate the minimum maximum distance minMaxDist between all leaf node bounding boxes of geometric objects A and B, save all node pairs with minimum distance less than or equal to minMaxDist into a structure array, and recursively replace adjacent nodes with the parent nodes of the nodes to reduce the total number of node pairs; the structure array contains node geometry information, parameter range and minimum distance; (3) Construct a square sum program for solving the minimum distance. Substitute the parameter equations and parameter ranges of the node pairs calculated in step (2), as well as the corresponding constraints that restrict the shape of the geometric objects, into the square sum program solution model. Convert the square sum program into a semidefinite program. Use an optimization solver to solve the semidefinite program problem, calculate the minimum distance between each node pair, and update the global minimum distance. Finally, the minimum distance between geometric objects A and B is obtained. (4) Compare the minimum distance obtained in step (3) with a preset threshold. If the minimum distance is greater than or equal to the threshold, it indicates that the geometric objects A and B have not collided; if the minimum distance is less than the threshold, it indicates that the geometric objects A and B have collided.
2. The 3D CAD model collision detection method based on BVH and square sum programming according to claim 1, characterized in that: The geometric information in step (1) is specifically: parametric equations of curves and surfaces, the curves include straight lines, circles, ellipses, and B-spline curves, and the surfaces include planes, cylinders, cones, spheres, tori, and B-spline surfaces.
3. The 3D CAD model collision detection method based on BVH and square sum programming according to claim 2, characterized in that: The curve or surface needs to construct a BVH structure according to the corresponding data structure and divide it into nodes, and then the node pairs with the closest distance are applied to the square sum programming model for solution.
4. The 3D CAD model collision detection method based on BVH and square sum programming according to claim 2, characterized in that: The B-spline curve is decomposed and calculated piece by piece to calculate the polynomial expression between each node; the B-spline surface is decomposed and calculated piece by piece according to the node to calculate the polynomial expression of the surface piece between adjacent nodes.
5. The 3D CAD model collision detection method based on BVH and square sum programming according to claim 1, characterized in that: The step (2) is divided into the following sub-steps: (2.1) Select all leaf nodes in the BVH of geometric objects A and B, denoted as S(A) and S(B) respectively; each node represents an AABB bounding box; calculate the distance between the eight vertices of the two bounding boxes to obtain the minimum and maximum distances between the AABB bounding boxes, denoted as a∈S(A) and b∈S(B), where a represents a leaf node of geometric object A and b represents a leaf node of geometric object B, and record the minimum and maximum distances between a and b; (2.2) Traverse S(A) and S(B), first calculate the maximum distance between a and b through a double loop, update the minimum maximum distance between the global BVH nodes minMaxDistGlobal, and then save the minimum distance between a and b and the node information of a and b into a structure array; (2.3) Arrange the structure array described in step (2.2) in ascending order according to the size of the structure members by quick sort, and let the set of elements whose structure members are less than or equal to minMaxDistGlobal be T(A) and T(B); for the elements in T(A) and T(B), if there are adjacent node pairs, use the parent node instead of the adjacent node.
6. The 3D CAD model collision detection method based on BVH and square sum programming according to claim 1, characterized in that: The step (3) is divided into the following sub-steps: (3.1) Traverse T(A) and T(B), record a∈T(A), b∈T(B), and let the parameter range of a be [pMin a ,pMax a ], the parameter range of b is [pMin b ,pMax b ]; According to Putinar's theorem, any strictly positive polynomial f(u) in its domain can be decomposed into Where u represents the parameters of the geometric object, m represents the number of non-negative polynomials taken on the domain of f(u), and s i (u) represents a square sum polynomial of degree not exceeding f(u), g i is a non-negative polynomial on the domain; if there is an equality constraint, decompose f(u) into where p i is any polynomial, h i is a polynomial that is zero over its domain; (3.2) Use square sum programming to solve the minimum distance between geometric objects A and B. Suppose the domain of geometric object A is The domain of the geometric object B is The domains of geometric objects A and B are where u 1 ,u 2 are the parameters of A and B, is the parametric equation of A and B, q j It is a constraint used to limit the shape of geometric objects; define geometric objects A and B as x 1 (u 1 ) and x 2 (u 2 ), the distance between the two is Get the minimum distance solution formula between geometric objects A and B: f * =minf(u 1 ,u 2 ), the corresponding points of the geometric objects A and B with the closest distance are: u * =argminf(u 1 ,u 2 ); Substitute the parameter polynomial and parameter range of the node pairs calculated in step (2) into the square sum programming model to form a series of constraints for the square sum programming. Use the optimization solver to transform the square sum programming into a semidefinite programming solver, calculate the minimum distance between each node pair, and update the global minimum distance, and finally obtain the minimum distance between the two geometric objects.