A cylinder-cylinder space collision detection method
By constructing a collaborative detection logic and selectively executing different types of detection methods, the problem of incomplete cylinder collision detection in existing technologies is solved, achieving efficient and reliable collision detection and meeting real-time requirements.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- RUERMAN INTELLIGENT TECHNOLOGY (BEIJING) CO LTD
- Filing Date
- 2025-09-28
- Publication Date
- 2026-05-05
AI Technical Summary
Existing cylinder collision detection methods suffer from incomplete detection when dealing with collisions between cylinders, especially the collision types between end faces and sides, and have high computational complexity, making it difficult to meet real-time requirements.
By constructing a collaborative detection logic, parallel detection, wall-to-wall detection, loop-to-line distance detection, and plane cutting detection are selectively performed based on spatial location relationships, comprehensively covering all possible collision types, and reducing unnecessary complex calculations through preliminary judgment.
It achieves comprehensive coverage of all possible collision types between cylinders, improves detection efficiency and reliability, meets real-time requirements, avoids false positives and false negatives, and provides technical support for high-precision applications.
Smart Images

Figure CN121374555B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of robotic arm control technology, and in particular to a method for detecting collisions between cylinders in space. Background Technology
[0002] Collision detection is a crucial foundational technology in fields such as robotics, virtual reality, and computer-aided design. Its purpose is to pre-determine whether contact or interference will occur between objects or between objects and their environment, thus providing a basis for decision-making in path planning, motion control, and behavior simulation, and preventing collisions or clipping. Cylinders, as a common basic geometric shape, are frequently used to enclose and simplify the representation of links in robotic arms, the torso of robots, and objects such as pipes and columns in the working environment. Therefore, the problem of collision detection between two cylinders in space has become very common in practice.
[0003] Currently, several classic methods have been proposed and widely applied for collision detection between basic geometric shapes, such as the Separating Axis Theorem (SAT), the projection plane method, geometric methods, and algebraic methods. These methods are relatively mature in handling collisions between geometric shapes such as cuboids and spheres. However, due to the unique geometric properties of cylinders, the above-mentioned conventional methods face significant challenges in practical applications. Cylinders simultaneously contain smooth curved surfaces and two flat end faces (bottoms). This mixed characteristic makes it difficult to find a complete set of projection axes to apply the separating axis theorem, rendering the projection axis method unsuitable.
[0004] On the other hand, while algebraic methods theoretically determine collisions by establishing and solving mathematical equations, the parametric representation of a cylinder is relatively complex, involving multiple variables such as angles, radii, heights, and direction vectors. This makes solving the constructed equations difficult, resulting in high computational complexity and making it unsuitable for applications with high real-time requirements. Existing technical solutions often have limitations when handling cylinder-to-cylinder collisions; they either fail to comprehensively cover all collision types (such as end-face-to-side collisions, end-face-to-end collisions) or are inefficient due to excessive computational complexity. These shortcomings limit their application in complex scenarios requiring high real-time performance and high reliability. Summary of the Invention
[0005] The purpose of this invention is to provide a method for detecting collisions between cylinders in space. By constructing a collaborative detection logic, the method intelligently selects and executes the corresponding detection method based on the spatial relationship, which not only achieves comprehensive coverage of all possible collision types between cylinders, but also significantly improves detection efficiency.
[0006] To address the aforementioned technical problems, a first aspect of this invention provides a method for detecting collisions between cylinders in space, comprising the following steps:
[0007] Obtain the geometric parameters and real-time spatial position data of the first and second cylinders;
[0008] Based on the geometric parameters and the real-time spatial position data, determine the spatial positional relationship between the first cylinder and the second cylinder;
[0009] Based on the determination result of the spatial position relationship, at least one of parallel detection, wall-to-wall detection, loop-to-line distance detection and plane cutting detection is selectively performed to determine whether the first cylinder and the second cylinder collide.
[0010] Further, determining the spatial relationship between the first cylinder and the second cylinder based on the geometric parameters and the real-time spatial position data includes:
[0011] Based on the axial vectors of the first cylinder and the second cylinder, it is determined whether the axes of the first cylinder and the second cylinder are parallel, and a first determination result is obtained;
[0012] Calculate the first shortest distance between the axes of the first cylinder and the second cylinder, determine whether the first shortest distance is greater than the sum of the radii of the first cylinder and the second cylinder, and obtain a second determination result;
[0013] Calculate the second shortest distance from any point on the end face ring of the first cylinder to the axis of the second cylinder, determine whether the second shortest distance is less than the radius of the second cylinder, and obtain the third judgment result.
[0014] Further, based on the determination result of the spatial positional relationship, selectively performing at least one of parallel detection, wall-to-wall detection, loop-to-line distance detection, and planar cutting detection to determine whether the first cylinder and the second cylinder collide includes:
[0015] If the first judgment result is that the axes of the first cylinder and the second cylinder are parallel, then the parallel detection logic is executed to determine whether the first cylinder and the second cylinder collide.
[0016] If the first judgment result is that the axes of the two cylinders are not parallel and the second judgment result is that the first shortest distance is less than or equal to the sum of the radii of the first cylinder and the second cylinder, then the wall-to-wall detection logic is executed to determine whether the sides of the first cylinder and the second cylinder collide.
[0017] If no collision is detected after executing the wall-to-wall detection logic, or if the second judgment result is that the first shortest distance is greater than the sum of the radii of the first cylinder and the second cylinder, then a selection is made according to the third judgment result: if the third judgment result is that the second shortest distance is less than the radius of the second cylinder, then the loop-to-line detection logic is executed, and it is determined whether the second shortest distance is less than the radius of the second cylinder, and whether a collision occurs between the end ring of the first cylinder and the side of the second cylinder;
[0018] If the third judgment result is that the second shortest distance is greater than or equal to the radius of the second cylinder, or if no collision is detected after executing the loop-line detection logic, then the plane cutting detection logic is finally executed. The intersection line is obtained by intersecting the plane where the end face of the first cylinder and the end face of the second cylinder are located, and the projection interval of the two cylinder end face rings on the intersection line is calculated to determine whether a collision occurs between the end faces of the first cylinder and the second cylinder.
[0019] Further, executing the parallel detection logic includes:
[0020] Calculate the vertical distance from the center of the bottom surface of the first cylinder to the axis of the second cylinder. If the vertical distance is greater than the sum of the radii of the first cylinder and the second cylinder, then it is determined that no collision has occurred.
[0021] If the vertical distance is less than or equal to the sum of the radii of the first cylinder and the second cylinder, then obtain the first projection point position and the second projection point position of the center of the upper bottom surface and the center of the lower bottom surface of the first cylinder on the axis of the second cylinder, respectively.
[0022] Determine whether the positions of the first projection point and the second projection point are within the range of the axis segment of the second cylinder. If at least one projection point is within the range of the axis segment, a collision is determined to have occurred; otherwise, no collision is determined to have occurred.
[0023] Further, executing the wall-to-wall detection logic includes:
[0024] Obtain the common perpendicular line between the axis of the first cylinder and the axis of the second cylinder;
[0025] Determine the position of the first perpendicular point between the common perpendicular line and the axis of the first cylinder, and determine whether the first perpendicular point is located within the range of the axis line segment of the first cylinder;
[0026] Determine the position of the second perpendicular point between the common perpendicular line and the axis of the second cylinder, and determine whether the second perpendicular point is located within the range of the axis line segment of the second cylinder;
[0027] If both the first perpendicular point and the second perpendicular point are within the range of the corresponding axis line segment, then a wall-to-wall collision is determined to have occurred; otherwise, no collision is determined to have occurred.
[0028] Further, executing the loop-to-line detection logic includes:
[0029] Obtain the point with the minimum distance from the end face ring of the first cylinder to the axis of the second cylinder;
[0030] Calculate the actual minimum distance from the minimum distance point to the axis of the second cylinder;
[0031] Determine whether the actual minimum distance value is less than the radius value of the second cylinder. If so, determine that a collision has occurred between the end face ring of the first cylinder and the side face of the second cylinder; otherwise, determine that no collision has occurred.
[0032] Further, calculating the actual minimum distance value from the minimum distance point to the axis of the second cylinder includes:
[0033] Based on the parameterized representation of the end face annulus of the first cylinder, construct a squared distance function from any point on the end face annulus to the axis of the second cylinder;
[0034] Taking the derivative of the squared distance function with respect to the annular parameter angle and setting the derivative to zero, we obtain the equation for the extreme point.
[0035] The extreme point equation is solved by Newton's iteration method. Initial iteration parameter angle values are selected and iterative calculations are performed until the parameter angle difference obtained from two adjacent iterations is less than a preset accuracy threshold.
[0036] Substitute the parameter angle value obtained from the final iteration into the parameterized representation of the end face annulus to calculate the spatial coordinates of the minimum distance point.
[0037] Further, executing the planar cutting detection logic includes:
[0038] Determine the spatial plane equations containing the first cylinder end face to be tested and the second cylinder end face to be tested;
[0039] Calculate the equation of the intersection of the equations of two spatial planes to obtain a spatial straight line;
[0040] Calculate the perpendicular distances from the center of the first cylinder and the center of the second cylinder to the spatial line, respectively;
[0041] Based on the radius of the first cylinder and the distance from its center to the spatial straight line, calculate the length of the first half chord of the chord obtained by the spatial straight line intercepting the annulus on the end face of the first cylinder;
[0042] Based on the radius of the second cylinder and the distance from its center to the spatial straight line, calculate the length of the second half chord of the chord obtained by the spatial straight line intercepting the annulus on the end face of the second cylinder;
[0043] Based on the first half-chord length, the second half-chord length, and the direction of the spatial straight line, the projection intervals of the first cylindrical end face annulus and the second cylindrical end face annulus on the spatial straight line are obtained;
[0044] Determine whether there is an overlap between the two projection intervals. If there is an overlap, it is determined that a collision has occurred between the end faces; otherwise, it is determined that no collision has occurred.
[0045] Further, obtaining the projection intervals of the first cylindrical end face annulus and the second cylindrical end face annulus on the spatial straight line based on the direction of the first half-chord length, the second half-chord length, and the spatial straight line includes:
[0046] A scalar parameter coordinate system for the spatial line is established with a reference point on the spatial line as the origin and the direction vector of the spatial line as the base direction.
[0047] The coordinates of the two intersection points of the spatial straight line and the annulus on the end face of the first cylinder are converted into corresponding first scalar parameter values and second scalar parameter values. The smaller value of the first scalar parameter value and the second scalar parameter value is used as the lower boundary of the first projection interval, and the larger value is used as the upper boundary of the first projection interval, thereby determining the first projection interval of the annulus on the spatial straight line.
[0048] The coordinates of the two intersection points of the spatial straight line and the annulus on the end face of the second cylinder are converted into corresponding third and fourth scalar parameter values. The smaller of the third and fourth scalar parameter values is used as the lower boundary of the second projection interval, and the larger value is used as the upper boundary of the second projection interval, thereby determining the second projection interval of the annulus on the spatial straight line.
[0049] Accordingly, a second aspect of the present invention provides an electronic device, including: at least one processor; and a memory connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to cause the at least one processor to perform the above-described cylinder-to-cylinder spatial collision detection method.
[0050] Accordingly, a third aspect of the present invention provides a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the above-described cylinder-to-cylinder spatial collision detection method.
[0051] The above-described technical solutions of the embodiments of the present invention have the following beneficial technical effects:
[0052] 1. By constructing a hierarchical collaborative detection system, the spatial positional relationship between two cylinders is first determined (such as parallelism, axial distance, and distance between end face and axial line). The most suitable specialized detection logic (parallelism, wall-to-wall, ring-to-line, and plane cutting) is then selected and invoked, ensuring coverage of all possible collision types such as bottom-to-bottom, wall-to-wall, bottom-to-wall, and ring-to-ring. This overcomes the detection blind spots of existing single methods (such as the projection axis method) due to the complex geometric characteristics of cylinders, and greatly improves the completeness and reliability of collision detection.
[0053] 2. Based on preliminary spatial relationship judgments with relatively low computational cost, decisions are made on whether subsequent more complex and precise detections are needed, avoiding a large amount of unnecessary complex calculations. For example, once parallelism is determined, only parallel detection is called; if the axis distance is too far, wall-to-wall detection is skipped. In loop-to-line detection, optimization algorithms such as Newton's iteration method are used to quickly solve for extreme values. In planar cutting, a scalar parameter coordinate system is established to simplify interval judgment, significantly reducing the overall computational cost of the algorithm and enabling it to be applied to scenarios with high real-time requirements, such as real-time obstacle avoidance for robots.
[0054] 3. Based on rigorous mathematical modeling and geometric calculations, whether it is the determination of projection points in parallel detection, the verification of the foot of the common perpendicular in wall-to-wall detection, the determination of the precise minimum distance point through optimization algorithms in loop-to-line detection, or the determination of collision judgment based on half-chord length calculation and overlapping projection intervals in plane cutting detection, all ensure that collision judgment is based on precise geometric relationships rather than approximate estimations. The deterministic algorithm based on mathematical derivation effectively avoids misjudgment and omission, and the output results are accurate and reliable, providing technical support for precision applications where safety is critical. Attached Figure Description
[0055] Figure 1 This is a schematic diagram of the geometric parameters of a cylinder provided in an embodiment of the present invention;
[0056] Figure 2 This is a flowchart of the cylinder-to-cylinder spatial collision detection method provided in an embodiment of the present invention;
[0057] Figure 3 This is a schematic diagram of parallel detection of two cylinders provided in an embodiment of the present invention;
[0058] Figure 4 This is a schematic diagram of wall-to-wall detection of two cylinders provided in an embodiment of the present invention;
[0059] Figure 5 This is a schematic diagram of the loop-line distance detection of two cylinders provided in an embodiment of the present invention. Figure 1 ;
[0060] Figure 6This is a schematic diagram of the loop-line distance detection of two cylinders provided in an embodiment of the present invention. Figure 2 ;
[0061] Figure 7 This is a schematic diagram of the loop-line distance detection of two cylinders provided in an embodiment of the present invention. Figure 3 ;
[0062] Figure 8 This is a schematic diagram of planar cutting detection of two cylinders provided in an embodiment of the present invention. Figure 1 ;
[0063] Figure 9 This is a schematic diagram of planar cutting detection of two cylinders provided in an embodiment of the present invention. Figure 2 . Detailed Implementation
[0064] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to specific embodiments and the accompanying drawings. It should be understood that these descriptions are merely exemplary and not intended to limit the scope of the invention. Furthermore, descriptions of well-known structures and techniques are omitted in the following description to avoid unnecessarily obscuring the concept of the invention.
[0065] like Figure 1 As shown, the geometric parameters of the cylinder are as follows: Let C be the height of the cylinder, and C be the center of the cylinder. Where is the radius of the cylinder. Let be the axial vector per unit length of the cylinder, and b and d be the two vertices.
[0066] set up and It is perpendicular to Two vectors, and A set of orthonormal bases is formed, and the parameterized expression for any point in the cylinder is as follows:
[0067] (1)
[0068] in, This represents any point inside the cylinder. Represents the coordinates of the cylinder's center. express and Length in direction, Indicates circling Angle of rotation for Length in direction, , , .
[0069] Please refer to Figure 2 The first aspect of this invention provides a method for detecting collisions between cylinders in space, comprising the following steps:
[0070] Step S100: Obtain the geometric parameters and real-time spatial position data of the first cylinder and the second cylinder.
[0071] In the basic data preparation phase of collision detection, it is necessary to extract the fundamental properties and instantaneous states of the two cylinders from the system or model. Geometric parameters mainly include the radius and height values of each cylinder, which are inherent dimensions describing its cross-sectional size and axial extension. Real-time spatial position data is used to accurately characterize the instantaneous orientation and attitude of the cylinders in the global coordinate system, and must include at least its axial unit vector (to determine the cylinder's orientation), center point coordinates (to determine the cylinder's position), and coordinates of the centers of the two base circles (to accurately locate the endpoints of the axes). Accurate acquisition of this data is a prerequisite for all subsequent geometric calculations.
[0072] Step S200: Based on geometric parameters and real-time spatial position data, determine the spatial positional relationship between the first cylinder and the second cylinder.
[0073] The initial classification of the relative spatial positions of two cylinders is achieved through calculations on basic data. First, the cross product modulus of the axial vectors of the two cylinders is calculated. If it is zero or approximately zero (within a preset tolerance), the two axes are determined to be parallel. If they are determined to be non-parallel, the shortest distance between the two skew axes is further calculated and compared with the sum of the radii of the two cylinders to determine whether there is a possibility of collision on their sides. Subsequently, the distance from a point on the end face annulus (i.e., the bottom boundary circumference) of one cylinder to the axis of the other cylinder is evaluated. By calculating whether the minimum distance is less than the radius of the other cylinder, it is determined whether there is a possibility of the end face and side approaching each other. The results of this series of judgments constitute the decision-making basis for selecting a specific detection algorithm.
[0074] Step S300: Based on the judgment result of the spatial position relationship, selectively perform at least one of parallel detection, wall-to-wall detection, loop-to-line distance detection and plane cutting detection to determine whether the first cylinder and the second cylinder collide.
[0075] Based on the output of step S200, the most relevant specialized detection algorithm is intelligently invoked instead of performing all detections, thereby optimizing computational efficiency. If the two cylinders are determined to be parallel, the parallel detection logic is activated, which mainly determines whether the projection point of the center of the bottom surface on the axis of the other cylinder falls within the range of the axis segment. If they are determined to be non-parallel but the shortest distance between the axes is less than or equal to the sum of the radii, the wall-to-wall detection logic is activated, which determines side collision by solving for the common perpendicular and verifying whether the two perpendicular points are both located on their respective axis segments. If no collision occurs in the above cases, or if the axis distance itself is too far, the ring-to-line distance detection logic is then executed based on the minimum distance between the end face ring and the axis. This logic solves for the minimum distance point through an optimized algorithm and performs a precise comparison. If no collision is still detected, the plane cutting detection logic is finally activated, which determines the complex end face collision situation by establishing the intersection line of the two end face planes and calculating whether the projection intervals of the two cylinder end face rings on this intersection line overlap. The entire process ensures that all possible collision modes are covered by the corresponding detection logic.
[0076] By executing the above steps in an orderly manner, comprehensive coverage of all possible collision scenarios between two cylinders in space is achieved, eliminating detection blind spots and significantly improving the completeness and reliability of collision detection. Simultaneously, this method uses a preliminary judgment based on spatial positional relationships to intelligently select subsequent detection paths, effectively avoiding unnecessary complex calculations, reducing computational resource consumption, and meeting the high real-time requirements of applications such as robotics and virtual reality. Furthermore, each detection logic in the scheme is based on rigorous mathematical derivation and geometric calculations, ensuring the accuracy and determinism of the detection results and providing reliable technical support for applications requiring high precision and high safety.
[0077] Specifically, step S200, which involves determining the spatial relationship between the first cylinder and the second cylinder based on geometric parameters and real-time spatial position data, includes:
[0078] Step S210: Based on the axial vectors of the first cylinder and the second cylinder, determine whether the axes of the first cylinder and the second cylinder are parallel, and obtain the first judgment result.
[0079] The vectors are cross-multiplied, and the magnitude of the resulting vector is calculated. If the magnitude is zero or less than a preset minimum tolerance threshold (used to overcome precision errors in floating-point calculations), the two axes are determined to be parallel in space, and this first judgment result is recorded as parallel; otherwise, they are determined to be non-parallel. This judgment result is the highest-level decision-making basis for subsequent processes, because whether they are parallel or not will lead to completely different detection branches.
[0080] Step S220: Calculate the first shortest distance between the axes of the first cylinder and the second cylinder, determine whether the first shortest distance is greater than the sum of the radii of the first cylinder and the second cylinder, and obtain the second determination result.
[0081] First, based on the principles of spatial analytic geometry, the shortest distance between two skew lines (i.e., the axes of the two cylinders) is calculated. This distance is the length of the common perpendicular segment connecting the two lines and perpendicular to both. Then, this shortest distance is compared to the sum of the radii of the two cylinders. If the shortest distance is greater than the sum of the radii, it indicates that even when the two cylinders are closest in space, there is still a gap between their sides, and there is absolutely no possibility of collision; therefore, a second judgment result of "safe" is obtained. If the shortest distance is less than or equal to the sum of the radii, a second judgment result of "potential collision risk" is obtained, providing a basis for subsequently initiating detailed wall-to-wall collision detection.
[0082] Step S230: Calculate the second shortest distance from any point on the end face ring of the first cylinder to the axis of the second cylinder, determine whether the second shortest distance is less than the radius of the second cylinder, and obtain the third judgment result.
[0083] This step is used to detect the possibility that the end face ring of one cylinder is close to the side surface of another cylinder. The end face ring specifically refers to the circumferential boundary where the bottom surface of the cylinder is located. This step does not directly calculate the distance from all points on the ring to the axis. Instead, it establishes a parameterized equation for the ring and constructs a mathematical function representing the distance from each point to the target axis. By analyzing the properties of this function (e.g., finding extreme points through differentiation) or using numerical optimization methods (e.g., Newton's iteration method), the minimum value of this distance function, i.e., the second shortest distance, is found. This minimum distance value is compared with the radius of the target cylinder. If the minimum distance is less than the radius, it indicates that a point on the end face ring has encroached into the radius space of the other cylinder, posing a collision risk, resulting in a "close" third judgment; otherwise, a "not close" judgment is obtained. This result provides input for determining whether to initiate a ring-line fine detection.
[0084] Specifically, in step S300, based on the judgment result of the spatial position relationship, at least one of parallel detection, wall-to-wall detection, loop-to-line distance detection, and plane cutting detection is selectively performed to determine whether the first cylinder and the second cylinder collide, including:
[0085] Step S310: If the first judgment result is that the axes of the first cylinder and the second cylinder are parallel, then the parallel detection logic is executed to determine whether the first cylinder and the second cylinder collide.
[0086] like Figure 3As shown, firstly, the magnitude of the cross product vector of the axis vectors of the two cylinders is detected. If it is 0, the two cylinders are parallel. Then, the distance between the center of the lower base of cylinder 1 and the axis of cylinder 2 is detected. If this distance is greater than the sum of the radii of the two cylinders, it indicates that the two cylinders have not collided. If this distance is less than or equal to the sum of the radii, the projections of the centers of the upper and lower bases of cylinder 1 onto the axis of cylinder 2 are detected. If the projection points fall on cylinder 2, a collision has occurred; otherwise, no collision has occurred.
[0087] When step S210 determines that the two axes are parallel, it enters a detection path specifically designed to handle collisions between parallel cylinders. This parallel detection logic first calculates the perpendicular distance from the center of the bottom surface of the first cylinder to the axis of the second cylinder. If this distance is greater than the sum of the radii of the two cylinders, it can be immediately determined that the two cylinders have not collided. If this distance is less than or equal to the sum of the radii, it is necessary to further calculate the coordinates of the projection points of the centers of the upper and lower bottom surfaces of the first cylinder onto the axis of the second cylinder, and then determine whether these projection points are located within the range of the axis segment of the second cylinder (i.e., the line segment between its two bottom surfaces). If any projection point is within this range, it is determined that the two cylinders have collided; otherwise, it is determined that no collision has occurred. This logic efficiently handles possible bottom-to-bottom collisions between parallel cylinders.
[0088] Step S320: If the first judgment result is that the axes of the two cylinders are not parallel and the second judgment result is that the first shortest distance is less than or equal to the sum of the radii of the first cylinder and the second cylinder, then the wall-to-wall detection logic is executed to determine whether the sides of the first cylinder and the second cylinder collide.
[0089] When step S210 determines that the two axes are not parallel, and step S220 calculates that the shortest distance between the two axes is less than or equal to the sum of their radii, it indicates that there is a geometric possibility of a collision between the sides of the two cylinders, and then the wall-to-wall detection logic is invoked. The core of this logic is to calculate the common perpendicular of the two skew axes (i.e., the axes of the two cylinders) and accurately locate the point where the perpendicular is perpendicular to the two axes; then, it is determined whether both of these points are located within the range of the axis segment of their respective cylinders (i.e., the line segment connecting the centers of the two bases of the cylinder); only when both points are simultaneously located on their corresponding axis segments is it finally determined that the two cylinders have collided on their sides (wall-to-wall); if either point falls outside the line segment, it is determined that no collision has occurred.
[0090] like Figure 4 As shown, this detection method is applicable to collisions between the walls of two cylinders. First, determine the straight line... and Distance: If the distance between two straight lines is less than the sum of the radii of the two cylinders, calculate the perpendiculars of the two lines. If the feet of the perpendiculars both fall on the two line segments, it indicates that the two cylinders have undergone a wall-to-wall collision.
[0091] Step S330: If no collision is detected after executing the wall-to-wall detection logic, or if the second judgment result is that the first shortest distance is greater than the sum of the radii of the first cylinder and the second cylinder, then a selection is made based on the third judgment result: if the third judgment result is that the second shortest distance is less than the radius of the second cylinder, then the loop-to-line detection logic is executed, and it is determined whether the second shortest distance is less than the radius of the second cylinder, and whether a collision occurs between the end ring of the first cylinder and the side of the second cylinder.
[0092] This step handles the detection branch after wall-to-wall collisions are absent or impossible. Whether the wall-to-wall detection failed to detect a collision or the distance between the two axes is too great (the shortest distance is greater than the sum of the radii) to perform wall-to-wall detection, the focus shifts to the possibility of a collision between the end face ring and the side face. At this point, a decision is made based on the third judgment result of step S230: if the result indicates that there is a point on the end face ring of the first cylinder whose distance to the axis of the second cylinder is less than its radius (i.e., "close"), then the ring-line detection logic is initiated. This logic first uses a numerical optimization method (such as Newton's iteration method) to accurately solve for the point on the end face ring with the smallest distance to the axis of the second cylinder, and calculates the precise value of this minimum distance; if this precise minimum distance value is indeed less than the radius of the second cylinder, then it is determined that a collision has occurred between the end face ring of the first cylinder and the side face of the second cylinder.
[0093] like Figure 5 , Figure 6 and Figure 7 As shown, the two cylinders are divided into cylinder 1 and cylinder 2 (two calculations are required, the second one involving swapping all data between cylinder 1 and cylinder 2). According to formula (1), the parameterized representation of any point on the annulus of cylinder 1 is as follows:
[0094] (2)
[0095] The axis of cylinder 2 passes through and Two points, let For any point on the annulus of cylinder 1 (the sign can be determined by the distance from the center of the top and bottom surfaces of cylinder 1 to the axis of cylinder 2; if the top surface is closer to the axis, take the positive sign). to the straight line The distance formula is:
[0096] (3)
[0097] Traversal Finding The smallest possible interval must contain a point on ring 1 such that its distance to the axis of cylinder 2 is minimized. Therefore, this problem is a convex optimization problem with a given range. Differentiating the formula, we use Newton's iteration method to calculate the point on ring 1 with the shortest distance to the axis of cylinder 2, denoted as P. The foot of the perpendicular from this point to the axis of cylinder 2 is d. If the foot of the perpendicular d lies on the axis of cylinder 2, and the length of line segment dP is less than the radius of cylinder 2, then a collision occurs. Furthermore, for details on the collision types that ring-line distance detection can detect, please refer to [link to details]. Figure 5 , Figure 6 and Figure 7 .
[0098] Step S340: If the third judgment result is that the second shortest distance is greater than or equal to the radius of the second cylinder, or if no collision is detected after executing the loop-line detection logic, then the plane cutting detection logic is finally executed. The intersection line is obtained by intersecting the plane where the end face of the first cylinder and the end face of the second cylinder are located, and the projection interval of the two cylinder end face rings on the intersection line is calculated to determine whether a collision occurs between the end faces of the first cylinder and the second cylinder.
[0099] When none of the aforementioned detection logic is triggered or a collision is detected, the planar cutting detection logic is finally invoked to handle the most complex end-face collision situation. This logic first determines the spatial plane equations of the two cylindrical end faces to be detected (e.g., upper and lower bases) and solves for the intersection of these two planes. Then, it calculates the perpendicular distance from the center point of each cylinder to the intersection line and uses the radius of each cylinder to calculate the half-chord length of the chord obtained by intercepting the end-face annulus on the intersection line. Next, using a reference point on the intersection line as the origin and the direction of the intersection line as the reference, a one-dimensional scalar parameter coordinate system is established. The two intersection points of the two end-face annulus rings and the intersection line are mapped to scalar values on this coordinate system, thus obtaining the projection interval of each annulus ring on the intersection line (i.e., a closed interval consisting of a maximum and a minimum value). Finally, it determines whether these two projection intervals overlap; if they overlap, a collision is determined to have occurred between the end faces of the two cylinders; otherwise, no collision is determined to have occurred.
[0100] like Figure 8 As shown, calculate sequentially. arrive and distance and arrive and Find the shortest distance between the two cylinders. As shown in the diagram below, assume the shortest distance between the two cylinders is... and At this point, only calculation is needed. The plane and The plane in which it is located is sufficient.
[0101] The parameterized representation of points on the end faces of cylinders 1 and 2 is shown below (the lower base plane is...). ):
[0102] (4)
[0103] Let the line of intersection formed by the two intersecting faces be L. According to formula (4), the two sets of equations have three unknowns and cannot be solved. The line of intersection is composed of countless points, so we need to determine one of the values to solve the equation. Let x=0 and x=1 be the x-coordinates of two points on the line of intersection L. The variables of the above equations can be expressed as follows: and , two groups Substituting into the above equation, we can obtain the coordinates of two points on the line after the two planes intersect, and thus the equation of the line L is determined.
[0104] Next, calculate the centers of the two cylinders in sequence. and The distance to line L. If the distance to line L is... Length less than And the straight-line distance L Length less than ,Right now and As shown in the figure above, let the straight line L reach... and The foot of the perpendicular is and The intersection points of L and the annulus of cylinder 1 are respectively The intersection point with the cylinder and the two annulus is Straight line L to and Given the distances, the formulas for the half-chord lengths of the lines intersecting annulus 1 and annulus 2 are as follows:
[0105] (5)
[0106] set up Let L be the unit direction vector of line L, and calculate sequentially. , The coordinate formula is as follows:
[0107] (6)
[0108] Next, calculate and The projection interval of line L is calculated as follows:
[0109] (7)
[0110] like Two cylinders collide. The planar cutting algorithm can detect collisions such as... Figure 9 As shown.
[0111] Through the aforementioned step-by-step collaborative detection mechanism, full coverage detection of all possible collision types between cylinders is achieved, eliminating blind spots inherent in single detection methods and significantly improving the completeness and reliability of the detection results. This method employs a hierarchical judgment strategy based on spatial positional relationships, intelligently selecting and executing the most relevant detection algorithm. This effectively avoids a large amount of unnecessary complex calculations, significantly reducing the overall computational overhead of the algorithm and enabling it to meet the stringent real-time requirements of applications such as robotics and virtual simulation. Simultaneously, each detection logic is rooted in rigorous mathematical derivation and precise geometric calculations, ensuring the accuracy of collision judgments and providing a solid technical guarantee for applications requiring high precision and high safety.
[0112] Furthermore, the execution of parallel detection logic in step S310 includes:
[0113] Step S311: Calculate the vertical distance from the center of the bottom surface of the first cylinder to the axis of the second cylinder. If the vertical distance is greater than the sum of the radii of the first cylinder and the second cylinder, it is determined that no collision has occurred.
[0114] First, a spatial geometric model is established. The perpendicular distance from the center of the lower surface of the first cylinder to the axis of the second cylinder is calculated using the formula for the distance from a point in space to a line. This calculation involves determining the direction vector of the axis of the second cylinder and the coordinates of a point on it. Then, the precise distance value is obtained using vector cross product and modulus operations. This perpendicular distance is then numerically compared with the sum of the radii of the two cylinders. If the perpendicular distance is strictly greater than the sum of the radii, it indicates that the two cylinders are completely separated radially, with no possibility of collision, and the conclusion that no collision has occurred can be directly drawn. This judgment constitutes part of the rapid exclusion mechanism, effectively improving detection efficiency.
[0115] Step S312: If the vertical distance is less than or equal to the sum of the radii of the first cylinder and the second cylinder, then obtain the first projection point position and the second projection point position of the center of the upper bottom surface and the center of the lower bottom surface of the first cylinder on the axis of the second cylinder, respectively.
[0116] When the vertical distance is not greater than the sum of the radii, a collision is possible, requiring precise projection calculation. This step uses a vector projection method. First, the direction vector of the second cylinder's axis and the coordinates of a base point are obtained. Then, the coordinates of the projection points of the centers of the upper and lower bases of the first cylinder onto this axis are calculated. The projection calculation is achieved through vector dot product operations, obtaining the parameterized position representation of each center point on the axis vector. Determining these two projection points provides the necessary input data for subsequent judgment of the axial overlap of the cylinders.
[0117] Step S313: Determine whether the positions of the first projection point and the second projection point are within the range of the axis line segment of the second cylinder. If at least one projection point is within the range of the axis line segment, it is determined that a collision has occurred; otherwise, it is determined that no collision has occurred.
[0118] First, the spatial range of the axis segment of the second cylinder is determined, which is defined by the coordinates of the centers of its two base circles. The coordinates of the two projection points obtained in step S312 are converted into parameter representations relative to this axis segment, and it is determined whether the parameter values are within the interval [0,1]. If the parameter value of at least one projection point falls within this interval, it indicates that the first cylinder overlaps with the second cylinder in the axial direction. Combined with the radial distance condition, it is determined that the two cylinders have collided. If the parameter values of both projection points are not within this interval, it is determined that no collision has occurred. This judgment criterion ensures the accuracy and completeness of collision detection between parallel cylinders.
[0119] Through the three-step detection logic described above, a comprehensive and accurate assessment of collisions between parallel cylinders is achieved. This method establishes a rapid exclusion mechanism through vertical distance comparison, reducing unnecessary computational costs; it ensures the reliability of the detection results through projection point calculation and axial overlap judgment; the entire process is rigorous in structure and computationally efficient, fully meeting the dual requirements of performance and accuracy for real-time collision detection applications.
[0120] Furthermore, the execution of wall-to-wall detection logic in step S320 includes:
[0121] Step S321: Obtain the common perpendicular line between the axis of the first cylinder and the axis of the second cylinder.
[0122] The shortest connecting line segment between two skew lines, i.e., the common perpendicular, is determined through spatial geometric calculations. The calculation process first obtains the direction vectors of the two axes and the coordinates of a point they pass through, establishing the equations of the lines. Then, based on the formula for solving the common perpendicular of two skew lines, the direction vector of the common perpendicular, which is perpendicular to both axes, is calculated. By solving a system of linear equations, the exact coordinates of the intersection point between the common perpendicular and the two axes are determined, thus fully defining the spatial position and direction of the common perpendicular segment.
[0123] Step S322: Determine the position of the first perpendicular point between the common perpendicular and the axis of the first cylinder, and determine whether the first perpendicular point is located within the range of the axis segment of the first cylinder.
[0124] Based on the obtained common perpendicular, this step precisely locates the intersection point of the common perpendicular and the axis of the first cylinder, i.e., the first perpendicular foot point. The coordinates of this point are converted into a parameterized representation relative to the axis segment of the first cylinder through vector projection calculation. This axis segment is defined by the coordinates of the centers of the two bases of the first cylinder. It is then determined whether the parameter value of the perpendicular foot point is within a closed interval of zero to one. If so, it indicates that the point lies within the actual axis segment range of the first cylinder.
[0125] Step S323: Determine the position of the second perpendicular point between the common perpendicular and the axis of the second cylinder, and determine whether the second perpendicular point is located within the range of the axis segment of the second cylinder.
[0126] Using the same calculation method as in step S322, locate the intersection point of the common perpendicular and the axis of the second cylinder, i.e., the second perpendicular foot point. Convert the coordinates of this point into a parameterized representation of a line segment relative to the axis of the second cylinder, which is defined by the coordinates of the centers of the two bases of the second cylinder. Determine whether the parameter value of this perpendicular foot point is within a closed interval of zero to one to determine whether it is located within the actual axis line segment range of the second cylinder.
[0127] Step S324: If both the first perpendicular point and the second perpendicular point are within the range of the corresponding axis line segment, then it is determined that a wall-to-wall collision has occurred; otherwise, it is determined that no collision has occurred.
[0128] The final collision determination is made based on the results of the first two steps. A collision between the two cylinders' sides is determined only if the first perpendicular point is within the range of the first cylinder's axis segment, and simultaneously the second perpendicular point is within the range of the second cylinder's axis segment. If either perpendicular point is outside its corresponding axis segment, no side collision is determined. This condition ensures that a collision is only considered to have occurred when the two cylinders actually overlap in the axial direction and are sufficiently close in radial distance.
[0129] Through the above four-step detection logic, accurate judgment of collision situations between the sides of non-parallel cylinders is achieved. This method accurately determines the shortest distance path between two cylinders by calculating the common perpendicular, and ensures the accuracy of collision detection by judging the position of the perpendicular foot. The entire process is based on rigorous spatial geometric calculations and can effectively identify various collision situations between the sides of cylinders, providing reliable collision detection assurance for applications such as robot motion and virtual simulation.
[0130] Furthermore, the execution of loop-to-loop detection logic in step S330 includes:
[0131] Step S331: Obtain the minimum distance point from the end face ring of the first cylinder to the axis of the second cylinder.
[0132] The minimum distance point is determined by establishing a mathematical parameterized model of the annulus on the end face of the first cylinder, defined by the circumference of the cylinder's base. Based on the cylinder's spatial orientation parameters, including the coordinates of the end face center, the axial vector, and the radius, a three-dimensional coordinate expression for any point on the annulus is constructed. The Newton-Raphson iteration algorithm, a numerical optimization method, is used, with the annulus parameter angle as the variable and the squared distance from that point to the axis of the second cylinder as the objective function. By solving the equation where the derivative of the objective function is zero, the algorithm converges precisely to the parameter angle that minimizes the distance, ultimately determining the spatial coordinates of the minimum distance point.
[0133] Step S332: Calculate the actual minimum distance from the minimum distance point to the axis of the second cylinder.
[0134] After obtaining the spatial coordinates of the minimum distance point, this step uses spatial geometry calculations to determine the precise distance from that point to the axis of the second cylinder. Using the formula for calculating the distance from a spatial point to a line, combined with the direction vector of the second cylinder's axis and the coordinates of a point on it, the perpendicular distance between the minimum distance point and the axis is calculated. This calculation process involves vector cross product operations and modulus calculations, ultimately yielding a precise actual minimum distance value, which characterizes the minimum interval between the end face annulus and the axis.
[0135] Step S333: Determine whether the actual minimum distance value is less than the radius value of the second cylinder. If so, determine that a collision has occurred between the end face ring of the first cylinder and the side face of the second cylinder; otherwise, determine that no collision has occurred.
[0136] The calculated minimum distance value is compared with the radius of the second cylinder. If the minimum distance value is less than the radius of the second cylinder, it indicates that a point on the end face ring of the first cylinder has entered the radial space of the second cylinder, and a collision between the end face ring and the side surface is determined to have occurred. If the minimum distance value is greater than or equal to the radius of the second cylinder, it indicates that there is a sufficient safety distance between the two end face rings and the axis, and no collision is determined to have occurred. This judgment criterion ensures the accuracy and reliability of end face and side surface collision detection.
[0137] Through the three-step detection logic described above, accurate collision detection is achieved between the end face ring of a cylinder and the side face of another cylinder. This method accurately solves for the minimum distance point through parametric modeling and optimization algorithms, obtains precise distance values through geometric calculations, and finally completes the collision determination through numerical comparison. The entire process is accurate in calculation and reliable in judgment, effectively identifying complex collision scenarios between end faces and side faces, providing accurate collision detection assurance for various engineering applications.
[0138] Further, the calculation of the actual minimum distance value from the minimum distance point to the axis of the second cylinder in step S332 includes:
[0139] Step S3321: Construct a squared distance function from any point on the end face ring of the first cylinder to the axis of the second cylinder based on the parameterized representation of the end face ring of the first cylinder.
[0140] First, a complete parametric model of the end-face annulus is established. Based on the spatial orientation parameters of the cylinder, including the coordinates of the end-face center, the axial vector, and the radius, a three-dimensional coordinate expression for any point on the annulus is constructed. Building upon this, and combining the direction vector of the second cylinder's axis and the coordinates of a point on it, a function representing the squared distance from any point on the end-face annulus to the second cylinder's axis is established. This function, to avoid square root calculations, transforms the spatial geometric relationship into a scalar function with the annulus's parameter angle as the independent variable, providing a mathematical foundation for subsequent optimization solutions.
[0141] Step S3322: Differentiate the squared distance function with respect to the annular parameter angle and make the derivative zero to obtain the equation of the extreme point.
[0142] After obtaining the squared distance function, this step finds the extrema of the function through differentiation. The first derivative of the squared distance function is calculated with respect to the annular parameter angle, yielding the function's first derivative expression. This derivative is then set to zero, establishing the extremum equation. The solutions to this equation correspond to the critical points of the squared distance function, including possible minimum and maximum distance points. This step transforms the geometric optimization problem into a problem of solving algebraic equations.
[0143] Step S3323: Solve the extreme point equation using the Newton-Raphson iteration method, select the initial iteration parameter angle value and perform iterative calculation until the parameter angle difference obtained from two adjacent iterations is less than the preset accuracy threshold.
[0144] A numerical method is employed to solve the extreme point equations. First, suitable initial iterative parameter angle values are selected, typically estimated based on geometric relationships. Then, Newton's iteration method is applied for iterative calculations, updating the parameter angle estimate in each iteration using the function value and its derivative. The iteration process continues until the difference in parameter angle between two consecutive iterations is less than a preset accuracy threshold, ensuring the solution meets the required computational accuracy. This method exhibits a fast convergence speed and can efficiently obtain solutions that meet the accuracy requirements.
[0145] Step S3324: Substitute the parameter angle value obtained from the final iteration into the parameterized representation of the end face annulus to calculate the spatial coordinates of the minimum distance point.
[0146] After obtaining the required angle parameters, this step determines the spatial location of the minimum distance point through reverse calculation. The converged angle parameters are then substituted into the parameterized expression of the end-face ring to calculate the corresponding three-dimensional spatial coordinates. This coordinate point is the point on the end-face ring with the minimum distance to the axis of the second cylinder, providing accurate geometric information for subsequent distance calculations and collision detection.
[0147] Through the above four-step calculation process, the precise solution for the minimum distance point from the end face annulus to the axis is achieved. This method transforms the geometric problem into a mathematical optimization problem through parametric modeling, and ensures the accuracy and computational efficiency of the solution through differentiation and iterative calculation. The final obtained minimum distance point provides a reliable geometric basis for collision detection. The entire calculation process is rigorous and efficient, meeting the dual requirements of real-time collision detection for both computational accuracy and speed.
[0148] Furthermore, the execution of the planar cutting detection logic in step S340 includes:
[0149] Step S341: Determine the spatial plane equations of the first cylinder end face to be tested and the second cylinder end face to be tested.
[0150] A mathematical model of the plane containing the end faces is established based on the spatial orientation parameters of the cylinder. For each end face to be detected, the specific coordinates of the center of the end face are determined according to its type (upper or lower base). These coordinates are obtained by superimposing the coordinates of the cylinder's center point onto the product of half the height and the axial vector. Using the center of this end face as a point on the plane and the cylinder's axial vector as the normal vector, a spatial plane equation is established using the point normal form. The plane equations corresponding to the two end faces completely describe their precise position and orientation in three-dimensional space.
[0151] Step S342: Calculate the equation of the intersection of the two spatial plane equations to obtain the spatial straight line.
[0152] The line of intersection is determined by solving a system of simultaneous equations for two planes. First, the cross product of the normal vectors of the two planes is calculated, yielding a vector perpendicular to both normal vectors; this vector is the direction vector of the line of intersection. Then, the coordinates of a specific point on the line of intersection are obtained by solving a system of linear equations. This point is typically determined by setting a specific value for one coordinate component and solving for the remaining two components. Combining the direction vector and the coordinates of this point, the parametric or symmetric equations of the line of intersection are established, providing a complete description of this spatial line.
[0153] Step S343: Calculate the perpendicular distances from the center of the first cylinder and the center of the second cylinder to the spatial straight line, respectively.
[0154] For each cylinder's center point, calculate its perpendicular distance to the spatial line obtained in step S342. This calculation involves a vector cross product operation: first, construct a vector from a known point on the line to the cylinder's center; then, calculate the cross product of this vector and the line's direction vector; finally, divide the magnitude of the cross product vector by the magnitude of the line's direction vector to obtain the precise perpendicular distance value. These two distance values will form the basis for subsequent calculations of the half-chord length.
[0155] Step S344: Based on the radius of the first cylinder and the distance from its center to the spatial straight line, calculate the length of the first half chord of the chord obtained by the spatial straight line intersecting the annulus on the end face of the first cylinder.
[0156] Consider the perpendicular distance from the center of the first cylinder to the spatial line and the radius of the first cylinder as two sides of a right triangle, with the radius as the hypotenuse and the distance from the center to the line as one leg. Calculate the length of the other leg using the Pythagorean theorem; this length is half the chord length of the chord intercepted by the spatial line on the annulus. This half-chord length determines half the length of the chord segment intercepted by the intersection line on the annulus.
[0157] Step S345: Based on the radius of the second cylinder and the distance from its center to the spatial straight line, calculate the length of the second half chord of the chord obtained by the spatial straight line intersecting the annulus on the end face of the second cylinder.
[0158] Using the same calculation method as in step S344, the second half-chord length is calculated using the Pythagorean theorem based on the radius of the second cylinder and the perpendicular distance from its center to the spatial line. This value represents half the length of the chord segment intercepted by the spatial line on the annulus at the end face of the second cylinder, and is used together with the first half-chord length for subsequent projection interval calculations.
[0159] Step S346: Based on the length of the first half chord, the length of the second half chord, and the direction of the spatial straight line, obtain the projection interval of the first cylindrical end face ring and the second cylindrical end face ring on the spatial straight line.
[0160] A one-dimensional parametric coordinate system is established, with a known point on the straight line as the origin and the direction vector of the line as the unit basis vector. For each end-face ring, the parameter values corresponding to its two intersection points with the spatial line are calculated. These two parameter values are equal to the parameter value of the projection point of the center plus or minus half the chord length. These two parameter values form a closed interval, which is the projection interval of the end-face ring on the spatial line. The projection intervals of the two end-face rings are calculated separately to provide input for the final overlap determination.
[0161] Step S347: Determine whether there is an overlap between the two projection intervals. If there is an overlap, it is determined that a collision has occurred between the end faces; otherwise, it is determined that no collision has occurred.
[0162] The final collision determination is made by comparing the parameter ranges of two projection intervals. The two closed intervals are denoted as [min1, max1] and [min2, max2]. The overlap of these intervals is determined by comparing their parameter values: if max1 is greater than or equal to min2 and max2 is greater than or equal to min1, then the two projection intervals overlap, indicating that the two end-face rings intersect in a straight line in space, and a collision occurs between the end faces; otherwise, no collision occurs. This criterion accurately reflects the spatial positional relationship between the end faces of the two cylinders.
[0163] Through the seven-step detection logic described above, a comprehensive and accurate assessment of collisions between the end faces of two cylinders is achieved. This method establishes a unified reference system through planar intersection calculation, quantifies the geometric relationship between the end-face annulus and the intersection line through half-chord length calculation, and finally completes collision detection by judging the overlap of projected intervals. The entire process is based on rigorous spatial geometry principles, effectively handling various complex relative positions of the end faces, providing reliable collision detection results, and meeting the needs of high-precision application scenarios.
[0164] Further, in step S346, based on the lengths of the first and second half-chords and the direction of the spatial straight line, the projection intervals of the first and second cylindrical end-face annulus rings onto the spatial straight line are obtained, including:
[0165] Step S3461: Establish a scalar parameter coordinate system for the spatial line, with a reference point on the spatial line as the origin and the direction vector of the spatial line as the base direction.
[0166] First, a specific reference point is selected on the spatial line. This point is usually a known point on the intersection line obtained in step S342. Using this reference point as the origin and the direction vector of the spatial line as the basis vector, a one-dimensional scalar parametric coordinate system is established. In this coordinate system, the position of any point on the line can be uniquely determined by a scalar parameter value, which represents the ratio of the directed distance from the origin to that point to the magnitude of the basis vector, thus mapping the line in three-dimensional space to one-dimensional parametric space.
[0167] Step S3462: Convert the coordinates of the two intersection points of the spatial straight line and the annulus on the end face of the first cylinder into corresponding first scalar parameter values and second scalar parameter values. Use the smaller value of the first scalar parameter value and the second scalar parameter value as the lower boundary of the first projection interval and the larger value as the upper boundary of the first projection interval to determine the first projection interval of the annulus on the spatial straight line.
[0168] First, determine the coordinates of the two intersection points between the spatial straight line and the annular end face of the first cylinder. These intersection points can be obtained by solving the equations of the intersection points of the straight line and the plane containing the end face, combined with the equation of the annular end face. Convert the three-dimensional coordinates of these two intersection points into parameter values in the scalar parameter coordinate system established in step S3461, obtaining the first scalar parameter value and the second scalar parameter value. Compare the magnitudes of these two parameter values, taking the smaller value as the lower bound of the first projection interval and the larger value as the upper bound of the first projection interval. This determines the projection interval of the annular end face of the first cylinder on the spatial straight line, which completely represents the projection range of the annular end face on the straight line.
[0169] Step S3463: Convert the coordinates of the two intersection points of the spatial straight line and the annulus on the end face of the second cylinder into the corresponding third scalar parameter value and fourth scalar parameter value. Use the smaller value of the third scalar parameter value and the fourth scalar parameter value as the lower boundary of the second projection interval and the larger value as the upper boundary of the second projection interval to determine the second projection interval of the annulus on the end face of the second cylinder on the spatial straight line.
[0170] Using the same processing method as in step S3462, the coordinates of the two intersection points between the spatial straight line and the second cylindrical end face annulus are determined, and these two intersection point coordinates are converted into parameter values in a scalar parameter coordinate system, obtaining the third and fourth scalar parameter values. The magnitudes of these two parameter values are compared, and the smaller value is taken as the lower bound of the second projection interval, and the larger value as the upper bound of the second projection interval. This determines the projection interval of the second cylindrical end face annulus on the spatial straight line. This interval completely describes the projection range of the second end face annulus on the straight line.
[0171] By establishing a scalar parametric coordinate system and transforming the geometric relationships in three-dimensional space into interval representations in one-dimensional parametric space, this method achieves precise quantization of the projection range of the end face annulus. This transformation simplifies the expression of geometric relationships, ensuring the accuracy and reliability of collision detection. Simultaneously, the parametric processing method improves computational efficiency, meeting the application requirements of real-time collision detection.
[0172] Accordingly, a second aspect of the present invention provides an electronic device, including: at least one processor and a memory connected to the at least one processor. The memory stores instructions executable by the at least one processor, which, when executed by the at least one processor, cause the at least one processor to perform the aforementioned cylinder-to-cylinder spatial collision detection method.
[0173] Accordingly, a third aspect of the present invention provides a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the above-described cylinder-to-cylinder spatial collision detection method.
[0174] The embodiments of the present invention aim to protect a method for detecting collisions between cylinders in space, which has the following effects:
[0175] 1. By constructing a hierarchical collaborative detection system, the spatial positional relationship between two cylinders is first determined (such as parallelism, axial distance, and distance between end face and axial line). The most suitable specialized detection logic (parallelism, wall-to-wall, ring-to-line, and plane cutting) is then selected and invoked, ensuring coverage of all possible collision types such as bottom-to-bottom, wall-to-wall, bottom-to-wall, and ring-to-ring. This overcomes the detection blind spots of existing single methods (such as the projection axis method) due to the complex geometric characteristics of cylinders, and greatly improves the completeness and reliability of collision detection.
[0176] 2. Based on preliminary spatial relationship judgments with relatively low computational cost, decisions are made on whether subsequent more complex and precise detections are needed, avoiding a large amount of unnecessary complex calculations. For example, once parallelism is determined, only parallel detection is called; if the axis distance is too far, wall-to-wall detection is skipped. In loop-to-line detection, optimization algorithms such as Newton's iteration method are used to quickly solve for extreme values. In planar cutting, a scalar parameter coordinate system is established to simplify interval judgment, significantly reducing the overall computational cost of the algorithm and enabling it to be applied to scenarios with high real-time requirements, such as real-time obstacle avoidance for robots.
[0177] 3. Based on rigorous mathematical modeling and geometric calculations, whether it is the determination of projection points in parallel detection, the verification of the foot of the common perpendicular in wall-to-wall detection, the determination of the precise minimum distance point through optimization algorithms in loop-to-line detection, or the determination of collision judgment based on half-chord length calculation and overlapping projection intervals in plane cutting detection, all ensure that collision judgment is based on precise geometric relationships rather than approximate estimations. The deterministic algorithm based on mathematical derivation effectively avoids misjudgment and omission, and the output results are accurate and reliable, providing technical support for precision applications where safety is critical.
[0178] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0179] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0180] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0181] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0182] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the specific implementation of the present invention. Any modifications or equivalent substitutions that do not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A method for detecting collisions between cylinders in space, characterized in that, Includes the following steps: Obtain the geometric parameters and real-time spatial position data of the first and second cylinders; Based on the geometric parameters and the real-time spatial position data, determine the spatial positional relationship between the first cylinder and the second cylinder; Based on the determination result of the spatial position relationship, at least one of parallel detection, wall-to-wall detection, loop-to-line distance detection and plane cutting detection is selectively performed to determine whether the first cylinder and the second cylinder collide. The step of determining the spatial relationship between the first cylinder and the second cylinder based on the geometric parameters and the real-time spatial position data includes: Based on the axial vectors of the first cylinder and the second cylinder, it is determined whether the axes of the first cylinder and the second cylinder are parallel, and a first determination result is obtained; Calculate the first shortest distance between the axes of the first cylinder and the second cylinder, determine whether the first shortest distance is greater than the sum of the radii of the first cylinder and the second cylinder, and obtain a second determination result; Calculate the second shortest distance from any point on the end face ring of the first cylinder to the axis of the second cylinder, determine whether the second shortest distance is less than the radius of the second cylinder, and obtain the third judgment result; Based on the determination result of the spatial positional relationship, selectively performing at least one of parallel detection, wall-to-wall detection, loop-to-line distance detection, and planar cutting detection to determine whether the first cylinder and the second cylinder collide includes: If the first judgment result is that the axes of the first cylinder and the second cylinder are parallel, then the parallel detection logic is executed to determine whether the first cylinder and the second cylinder collide. If the first judgment result is that the axes of the two cylinders are not parallel and the second judgment result is that the first shortest distance is less than or equal to the sum of the radii of the first cylinder and the second cylinder, then the wall-to-wall detection logic is executed to determine whether the sides of the first cylinder and the second cylinder collide. If no collision is detected after executing the wall-to-wall detection logic, or if the second judgment result is that the first shortest distance is greater than the sum of the radii of the first cylinder and the second cylinder, then a selection is made according to the third judgment result: if the third judgment result is that the second shortest distance is less than the radius of the second cylinder, then the loop-to-line detection logic is executed, and it is determined whether the second shortest distance is less than the radius of the second cylinder, and whether a collision occurs between the end ring of the first cylinder and the side of the second cylinder; If the third judgment result is that the second shortest distance is greater than or equal to the radius of the second cylinder, or if no collision is detected after executing the loop-line detection logic, then the plane cutting detection logic is finally executed. The intersection line is obtained by intersecting the plane where the end face of the first cylinder and the end face of the second cylinder are located, and the projection interval of the two cylinder end face rings on the intersection line is calculated to determine whether a collision occurs between the end faces of the first cylinder and the second cylinder. The execution of the planar cutting detection logic includes: Determine the spatial plane equations containing the first cylinder end face to be tested and the second cylinder end face to be tested; Calculate the equation of the intersection of the equations of two spatial planes to obtain a spatial straight line; Calculate the perpendicular distances from the center of the first cylinder and the center of the second cylinder to the spatial line, respectively; Based on the radius of the first cylinder and the distance from its center to the spatial straight line, calculate the length of the first half chord of the chord obtained by the spatial straight line intercepting the annulus on the end face of the first cylinder; Based on the radius of the second cylinder and the distance from its center to the spatial straight line, calculate the length of the second half chord of the chord obtained by the spatial straight line intercepting the annulus on the end face of the second cylinder; Based on the first half-chord length, the second half-chord length, and the direction of the spatial straight line, the projection intervals of the first cylindrical end face annulus and the second cylindrical end face annulus on the spatial straight line are obtained; Determine whether there is an overlap between the two projection intervals. If there is an overlap, it is determined that a collision has occurred between the end faces; otherwise, it is determined that no collision has occurred.
2. The method for detecting collisions between cylinders in space according to claim 1, characterized in that, The execution of the parallel detection logic includes: Calculate the vertical distance from the center of the bottom surface of the first cylinder to the axis of the second cylinder. If the vertical distance is greater than the sum of the radii of the first cylinder and the second cylinder, then it is determined that no collision has occurred. If the vertical distance is less than or equal to the sum of the radii of the first cylinder and the second cylinder, then obtain the first projection point position and the second projection point position of the center of the upper bottom surface and the center of the lower bottom surface of the first cylinder on the axis of the second cylinder, respectively. Determine whether the positions of the first projection point and the second projection point are within the range of the axis segment of the second cylinder. If at least one projection point is within the range of the axis segment, a collision is determined to have occurred; otherwise, no collision is determined to have occurred.
3. The method for detecting collisions between cylinders in space according to claim 1, characterized in that, The execution of the wall-to-wall detection logic includes: Obtain the common perpendicular line between the axis of the first cylinder and the axis of the second cylinder; Determine the position of the first perpendicular point between the common perpendicular line and the axis of the first cylinder, and determine whether the first perpendicular point is located within the range of the axis line segment of the first cylinder; Determine the position of the second perpendicular point between the common perpendicular line and the axis of the second cylinder, and determine whether the second perpendicular point is located within the range of the axis line segment of the second cylinder; If both the first perpendicular point and the second perpendicular point are within the range of the corresponding axis line segment, then a wall-to-wall collision is determined to have occurred; otherwise, no collision is determined to have occurred.
4. The method for detecting collisions between cylinders in space according to claim 1, characterized in that, The execution of the loop-to-line detection logic includes: Obtain the point with the minimum distance from the end face ring of the first cylinder to the axis of the second cylinder; Calculate the actual minimum distance from the minimum distance point to the axis of the second cylinder; Determine whether the actual minimum distance value is less than the radius value of the second cylinder. If so, determine that a collision has occurred between the end face ring of the first cylinder and the side face of the second cylinder; otherwise, determine that no collision has occurred.
5. The method for detecting collisions between cylinders in space according to claim 4, characterized in that, The calculation of the actual minimum distance value from the minimum distance point to the axis of the second cylinder includes: Based on the parameterized representation of the end face annulus of the first cylinder, construct a squared distance function from any point on the end face annulus to the axis of the second cylinder; Taking the derivative of the squared distance function with respect to the annular parameter angle and setting the derivative to zero, we obtain the equation for the extreme point. The extreme point equation is solved by Newton's iteration method. Initial iteration parameter angle values are selected and iterative calculations are performed until the parameter angle difference obtained from two adjacent iterations is less than a preset accuracy threshold. Substitute the parameter angle value obtained from the final iteration into the parameterized representation of the end face annulus to calculate the spatial coordinates of the minimum distance point.
6. The method for detecting collisions between cylinders in space according to claim 1, characterized in that, The projection intervals of the first cylindrical end face annulus and the second cylindrical end face annulus on the spatial straight line, based on the directions of the first half-chord length, the second half-chord length, and the spatial straight line, include: A scalar parameter coordinate system for the spatial line is established with a reference point on the spatial line as the origin and the direction vector of the spatial line as the base direction. The coordinates of the two intersection points of the spatial straight line and the annulus on the end face of the first cylinder are converted into corresponding first scalar parameter values and second scalar parameter values. The smaller value of the first scalar parameter value and the second scalar parameter value is used as the lower boundary of the first projection interval, and the larger value is used as the upper boundary of the first projection interval, thereby determining the first projection interval of the annulus on the spatial straight line. The coordinates of the two intersection points of the spatial straight line and the annulus on the end face of the second cylinder are converted into corresponding third and fourth scalar parameter values. The smaller of the third and fourth scalar parameter values is used as the lower boundary of the second projection interval, and the larger value is used as the upper boundary of the second projection interval, thereby determining the second projection interval of the annulus on the spatial straight line.
7. An electronic device, characterized in that, include: At least one processor; And a memory connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to cause the at least one processor to perform the cylinder-to-cylinder spatial collision detection method as described in any one of claims 1-6.