Collision detection method and device

By converting 3D obstacle surface information into 2D line segment combinations to generate scene collision data, the problem of collision detection relying on specific engines and consuming large amounts of computing resources in existing technologies is solved, achieving efficient collision detection with low resource consumption and cross-platform compatibility.

CN123059367APending Publication Date: 2026-11-10MIGU COMIC CO LTD +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610982489.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-02
Publication Date
2026-11-10

AI Technical Summary

Technical Problem

Existing collision detection technologies rely on specific 3D engines, resulting in high computational complexity, high resource consumption, and difficulty in migrating and reusing them between different engines. In particular, performance degrades when there are many obstacles and characters in the scene.

Method used

The obstacle surface information in the 3D scene is converted into a combination of line segments on a 2D plane to generate scene collision data. Collision is determined by the motion parameters and predicted position of the virtual target, reducing computational complexity and achieving collision detection with low resource consumption.

Benefits of technology

It achieves low-resource-consumption collision detection, can run efficiently on low-performance devices, is cross-platform portable, and ensures the realism and smoothness of collision response.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123059367A_ABST
    Figure CN123059367A_ABST
Patent Text Reader

Abstract

This application discloses a collision detection method and apparatus, relating to the field of data processing technology. By pre-generating the surface information of obstacles in a 3D scene as a combination of line segments on a 2D plane and constructing scene collision data, the collision detection process can be performed based on scene collision data without relying on the underlying collision interface of the 3D engine, thus decoupling the collision detection logic from the specific engine. At the same time, by transforming 3D spatial collision into the relationship calculation of line segments and points on a 2D plane, the collision determination process only involves vector operations, avoiding complex bounding box intersection tests or geometric calculations, reducing the computational load of a single collision detection, and thus reducing the overall consumption of computing resources. Furthermore, collision determination can be performed by querying the corresponding line segment data based on the current position and motion parameters of the virtual target, enabling low-energy real-time collision detection and efficient operation on low-performance devices.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to a collision detection method and apparatus. Background Technology

[0002] In virtual scene character control technology, to achieve a realistic movement experience for characters within the scene, collision detection of obstacles is typically required. Related technologies mainly employ bounding box-based hierarchical detection methods or geometric model-based fine-grained detection methods. These methods construct bounding boxes or geometric colliders within the scene, calculate the positional relationship between the character's bounding box and the scene colliders in real time, and thus determine whether a collision has occurred and respond accordingly.

[0003] The collision detection solutions in related technologies have the following problems in application: the construction and configuration of colliders depend on specific 3D engine technologies, and the implementation of collision detection algorithms is tightly coupled with the underlying interface of the engine, making it difficult to migrate and reuse the algorithms between different engines; in order to achieve high accuracy, the detection methods based on bounding boxes and geometry need to perform a lot of spatial calculations at runtime, which has high computational complexity and consumes a lot of processor computing resources; in addition, when the number of colliders in the scene is large or the number of characters increases, the amount of real-time collision calculation increases exponentially, resulting in a decrease in system performance.

[0004] Therefore, how to achieve collision detection with low resource consumption and without relying on a specific engine is an urgent problem to be solved. Summary of the Invention

[0005] This application provides a collision detection method and apparatus. Its main purpose is to solve the problem of how to achieve collision detection with low resource consumption and without relying on a specific engine.

[0006] According to a first aspect of this application, a collision detection method is provided, comprising:

[0007] Acquire surface information of obstacles in a 3D scene, convert the surface information into combinations of line segments on a 2D plane, and generate scene collision data based on the combinations of line segments; Obtain the current frame position information and motion parameters of the virtual target in the 3D scene, and calculate the predicted position information of the virtual target in the next frame based on the current frame position information and motion parameters; Collision determination is performed based on predicted location information and scene collision data to obtain the determination result; In response to the collision indication from the judgment result, the moving target point of the virtual target is calculated based on the relative positional relationship between the virtual target's motion direction and the collision point, and the virtual target is moved to the moving target point.

[0008] According to a second aspect of this application, a collision detection device is provided, comprising: The generation unit is used to acquire the surface information of obstacles in the 3D scene, convert the surface information into a combination of line segments on a 2D plane, and generate scene collision data based on the combination of line segments. The first calculation unit is used to obtain the current frame position information and motion parameters of the virtual target in the three-dimensional scene, and calculate the predicted position information of the virtual target in the next frame based on the current frame position information and motion parameters. The determination unit is used to perform collision determination processing based on the predicted location information and scene collision data to obtain the determination result; The second calculation unit is used to calculate the moving target point of the virtual target based on the relative positional relationship between the motion direction of the virtual target and the collision point in response to the judgment result indicating that a collision has occurred. The moving unit is used to move the virtual target to the moving target point.

[0009] According to a third aspect of this application, an electronic device is provided, comprising: At least one processor; and A memory that is communicatively connected to at least one processor; wherein, The memory stores instructions that can be executed by at least one processor, such that the at least one processor is able to perform the method described in the first aspect above.

[0010] According to a fourth aspect of this application, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are used to cause a computer to perform the method of the first aspect described above.

[0011] According to a fifth aspect of this application, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the method as described in the first aspect above.

[0012] The collision detection method and apparatus provided in this application pre-generate the surface information of obstacles in a 3D scene as combinations of line segments on a 2D plane and construct scene collision data. This allows the collision detection process to perform calculations based on scene collision data without relying on the underlying collision interface of the 3D engine, thus decoupling the collision detection logic from a specific engine. Furthermore, by transforming 3D spatial collision into the calculation of the relationship between line segments and points on a 2D plane, the collision determination process involves only vector operations, avoiding complex bounding box intersection tests or geometric calculations, reducing the computational load of a single collision detection, and consequently reducing overall computational resource consumption. Moreover, by querying the corresponding line segment data based on the current position and motion parameters of the virtual target for collision determination, low-energy real-time collision detection can be performed, enabling efficient operation on low-performance devices. Therefore, this application solves the problems of difficulty in migrating and reusing collision detection algorithms between different engines and high processor computational resource consumption, achieving low-resource-consumption collision detection that is not dependent on a specific engine.

[0013] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this application, nor is it intended to limit the scope of this application. Other features of this application will become readily apparent from the following description. Attached Figure Description

[0014] The accompanying drawings are provided for a better understanding of this solution and do not constitute a limitation of this application. Wherein: Figure 1 This is a schematic flowchart of a collision detection method provided in an embodiment of this application; Figure 2 This is a schematic diagram of a scene collision data generation process provided in an embodiment of this application; Figure 3 This is a schematic diagram of a scenario provided in an embodiment of this application; Figure 4 A schematic diagram illustrating the merging of lattice cells provided in an embodiment of this application; Figure 5 This is a schematic diagram of a line segment combination provided in an embodiment of this application; Figure 6 A schematic diagram illustrating the merging of line segments provided in an embodiment of this application; Figure 7 This is a schematic diagram illustrating the location information of a virtual target provided in an embodiment of this application; Figure 8 This is a schematic diagram of smoothness and rebound calculation provided in an embodiment of this application; Figure 9 This is a schematic diagram of a translation process provided in an embodiment of this application; Figure 10This is a schematic diagram of a secondary collision detection provided in an embodiment of this application; Figure 11 This is a schematic diagram of the structure of a collision detection device provided in an embodiment of this application; Figure 12 This is a schematic block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0015] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of this application, including various details to aid understanding. These should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this application. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0016] This application relates to the field of collision detection technology in virtual space, and in particular to a method for collision detection between virtual characters and three-dimensional scenes based on line segment data.

[0017] In interactive applications in virtual spaces, virtual targets (such as game characters, virtual figures, and digital humans) need to move freely in a three-dimensional scene. Collision detection technology is a means to ensure that virtual targets cannot pass through obstacles (such as walls, buildings, and terrain) in the scene. This application provides a collision detection method that preprocesses the surface information of obstacles in a three-dimensional scene into scene collision data in the form of two-dimensional line segment combinations. During real-time interaction, collision determination is performed based on the motion parameters and predicted position of the virtual target and the scene collision data. The actual moving target point of the virtual target is calculated based on the collision result, thereby achieving efficient and accurate collision detection and response.

[0018] The collision detection method and apparatus of this application are described below with reference to the accompanying drawings.

[0019] Figure 1 This is a schematic flowchart of a collision detection method provided in an embodiment of this application.

[0020] like Figure 1 As shown, the method includes the following steps: Step 101: Obtain the surface information of obstacles in the 3D scene, convert the surface information into a combination of line segments on a 2D plane, and generate scene collision data based on the combination of line segments.

[0021] In the embodiments of this application, a three-dimensional scene refers to a virtual three-dimensional space constructed using computer graphics technology, which contains static or dynamic objects such as virtual terrain, buildings, and props. An obstacle refers to an object in the three-dimensional scene with a solid surface that can block the passage of a virtual target, such as walls, fences, trees, and boxes. Surface information refers to data used to characterize the outline, boundary position, and geometry of obstacles in three-dimensional space, which can be obtained through geometric analysis, edge extraction, or collider analysis of obstacle models in the three-dimensional scene.

[0022] Converting surface information into a combination of line segments on a two-dimensional plane refers to projecting or mapping the three-dimensional spatial surface contour of an obstacle onto a horizontal two-dimensional plane, and using multiple straight line segments (i.e., line segments) to describe the boundary shape of the contour on the plane. Each line segment is uniquely determined by the two-dimensional coordinates of its two endpoints, and multiple line segments together constitute a combination of line segments, which can completely reflect the horizontal extent and boundary orientation of the obstacle.

[0023] Scene collision data is structured data generated based on line segment combinations. This data includes at least the coordinates of each line segment in the combination and their relative positions. Furthermore, the scene collision data is stored in a computer-readable format for real-time retrieval during collision detection. It may also include mappings between line segments and scene spatial regions for rapid localization.

[0024] It should be noted that the scene collision data is stored in the form of a two-dimensional array, which contains information about each grid cell, including grid length, grid center point coordinates, array index of the grid cell, and a list of line segment indices occupied by the grid cell.

[0025] Step 102: Obtain the current frame position information and motion parameters of the virtual target in the 3D scene, and calculate the predicted position information of the virtual target in the next frame based on the current frame position information and motion parameters.

[0026] In the embodiments of this application, a virtual target refers to a virtual object that moves in a three-dimensional scene under user control or program control. Current frame position information refers to the spatial coordinates of the virtual target in the three-dimensional scene at the current display frame or the current physics simulation frame, including at least two-dimensional coordinates on the horizontal plane. Motion parameters refer to data characterizing the motion state of the virtual target in the current frame, specifically including the magnitude of the motion speed, the motion direction vector, and the time step of each frame of physics simulation.

[0027] Based on the current frame position information and motion parameters, the expected spatial position of the virtual target in the next frame can be calculated using a uniform linear motion model. This expected spatial position is the predicted position information. This predicted position information indicates the position the virtual target should reach in the next frame if it is not obstructed by any obstacles.

[0028] Step 103: Perform collision determination processing based on predicted location information and scene collision data to obtain the determination result.

[0029] In the embodiments of this application, collision determination processing refers to determining whether a virtual target will come into contact with the obstacle boundary represented by scene collision data during the process of moving from the current frame position to the predicted position.

[0030] In one possible embodiment of this application, the determination process is based on the predicted position information and the line segment combination in the scene collision data. Specifically, the current frame position and the predicted position of the virtual target can be connected to form a motion path line segment. Then, the motion path line segment is intersected with each line segment in the line segment combination. If an intersection point exists, a collision is determined to have occurred; if no intersection point exists, a collision is determined not to have occurred. The determination result is the conclusion of whether a collision has occurred.

[0031] Step 104: In response to the judgment result indicating that a collision has occurred, calculate the moving target point of the virtual target based on the relative positional relationship between the virtual target's motion direction and the collision point, and move the virtual target to the moving target point.

[0032] In the embodiments of this application, the collision point refers to the intersection point where the motion path line segment of the virtual target first intersects with the line segment in the scene collision data, that is, the first obstacle boundary point that the virtual target comes into contact with during its movement. The motion direction is the motion direction vector of the virtual target in the current frame. The relative positional relationship refers to the directional relationship of the motion direction relative to the obstacle boundary line segment where the collision point is located, specifically including the angle between the motion direction and the obstacle boundary line segment, the component of the motion direction in the normal direction of the boundary line segment, and the component in the tangential direction, etc., and other geometric relationships.

[0033] Based on the relative positional relationship, the motion response of the virtual target after a collision can be determined, such as smooth sliding along the obstacle surface or a rebound effect. This allows for the calculation of a reasonable motion target point, ensuring that the virtual target neither penetrates the obstacle nor remains in an unnatural position. Finally, the spatial position of the virtual target is set as the motion target point, thus completing the collision response and position update for the current frame.

[0034] This application uses pre-generated combinations of two-dimensional line segments as the basis for collision. In the real-time operation phase, only simple two-dimensional line segment intersection judgment and displacement calculation based on the relationship between the motion direction and the collision point are required. There is no need to perform complex three-dimensional geometric collision detection, thereby reducing the amount of computation required for single-frame collision detection and improving collision detection efficiency. This enables a large number of virtual targets to perform collision interaction at the same time on low-performance terminals, while ensuring the realism and smoothness of the collision response.

[0035] It should be noted that scene collision data can be pre-generated and stored during the scene loading phase, thus eliminating the need for repeated generation during actual operation and further reducing the time overhead of real-time computation. Furthermore, it does not rely on the collision interface of a specific 3D graphics engine, making it cross-platform portable.

[0036] In one possible implementation of this application embodiment, this application embodiment provides a schematic diagram of the scene collision data generation process, such as... Figure 2 As shown, when converting line segment combinations and generating scene collision data, 2D collision data is generated using the 3D scene, and the collision information is converted into line segment combinations. Intersection points are calculated based on the virtual target's current position, direction of motion, velocity, and line segments, while smoothing motion or collision feedback is performed based on the direction of motion.

[0037] In one feasible approach, the process of generating scene collision data can be implemented in, but is not limited to, the following ways: First, obtain the minimum coordinates of the axis-aligned bounding box of the 3D scene, and calculate the translation vector from the minimum coordinates to the origin of the world coordinate system. Then, translate all scene elements of the 3D scene according to the translation vector to obtain the 3D scene after zeroing.

[0038] In the embodiments of this application, an axis-aligned bounding box (AABB) refers to the smallest hexahedron used to enclose all scene elements in a 3D scene, with each face of the hexahedron parallel to the three coordinate axes of the 3D spatial coordinate system. The minimum coordinate of the axis-aligned bounding box refers to the coordinates of the vertex of the bounding box that have the smallest value along the X, Y, and Z axes in the 3D spatial coordinate system, such as the coordinates of the lower left vertex of the bounding box (x1, y1, z1). The origin of the world coordinate system refers to the zero point of the coordinate system in the 3D virtual space, usually represented as (0, 0, 0). The translation vector is the direction vector from the minimum coordinate to the origin of the world coordinate system, and its value is equal to the coordinate of the origin of the world coordinate system minus the minimum coordinate, such as: ( x1, y1, z1).

[0039] By translating all scene elements in the 3D scene according to this translation vector, the minimum coordinates of the original scene bounding box coincide with the origin of the world coordinate system, thus obtaining the zeroed-out 3D scene. After zeroing, the spatial coordinates of all scene elements in the 3D scene are referenced to the origin of the world coordinate system, and the coordinate values ​​of each point in the scene are all non-negative.

[0040] Then, the zeroed 3D scene is clipped in the top-down direction using the horizontal plane corresponding to the target height of the virtual target as the cross section to obtain the 2D detection scene.

[0041] In the embodiments of this application, the top-down direction refers to the direction of observation vertically downwards from above the 3D scene, that is, the viewing direction of the scene along the negative Z-axis or negative Y-axis direction (depending on the coordinate system definition) in the 3D spatial coordinate system. The target height of the virtual target refers to the height position of the virtual target in the 3D scene, such as the height of the virtual character's feet or center of mass. The horizontal plane corresponding to the target height refers to a plane parallel to the ground plane of the 3D scene and with a vertical height equal to the target height. The 3D scene after zeroing is clipped using this horizontal plane as a cross-section, that is, the cross-sectional shape and cross-sectional boundary of all obstacles in the 3D scene after zeroing are obtained at the height of this horizontal plane.

[0042] Regarding the transformation from a 3D scene to a 2D detection scene, this application provides a scene diagram, such as... Figure 3 As shown, the 3D scene view is adjusted to a top-down view, and the scene is cross-sectionally clipped with the character's height as the upper surface and the ground surface as the lower surface to obtain a new scene to be detected, namely the 2D detection scene O.

[0043] By clipping the cross-section of a 3D scene, the 3D obstacle information in three-dimensional space can be compressed onto a 2D horizontal plane, resulting in a 2D detection scene. The 2D detection scene contains the boundary information of the obstacle cross-sections faced by the virtual target as it moves at the target height.

[0044] Subsequently, based on the two-dimensional detection scene, the scene is divided into grids according to the projection size of the virtual target in the top-view direction, resulting in multiple grid units.

[0045] In the embodiments of this application, the projection size of the virtual target in the top-view direction refers to the circumscribed rectangle or circumscribed square size of the projection shape of the virtual target on the horizontal plane when viewed from the top direction. For example, when the projection of the virtual target in the top-view direction is approximately circular, the projection size can refer to the diameter of the circle or the side length of the circumscribed square. Grid division refers to using the projection size of the virtual target in the top-view direction as the basic size of the grid unit, and uniformly dividing the two-dimensional detection scene on the horizontal plane into multiple grid regions of the same size, each grid region being a grid unit.

[0046] By dividing the grid according to the projected size of the virtual target, the size of each grid cell is matched with the area occupied by the virtual target on the horizontal plane.

[0047] Then, the intersection information of each grid cell with the obstacle boundary in the two-dimensional detection scene is calculated, and the grid state of each grid cell is marked according to the intersection information.

[0048] In the embodiments of this application, the obstacle boundary refers to the edge line of the cross-sectional profile of the obstacle in the two-dimensional detection scene. Intersection information refers to the location data of the intersection points between the boundary lines of each grid cell (e.g., the four sides of the grid) and the obstacle boundary. By calculating whether there are intersection points between the four sides of each grid cell and the obstacle boundary, as well as the number, location, and distribution of the intersection points, the relative positional relationship between the grid cell and the obstacle can be determined.

[0049] Based on the intersection information, the grid state of each cell is marked as one of three states: inside the obstacle, at the obstacle edge, or without obstacles. Specifically, when a cell is completely inside the obstacle boundary, its state is marked as inside the obstacle; when at least one of the four edges of a cell intersects the obstacle boundary and the intersection point is located on different edges, its state is marked as at the obstacle edge; when a cell is completely outside the obstacle boundary, its state is marked as without obstacles. By marking the grid state of each cell, the spatial region in the 2D detection scene can be divided into three types: obstacle interior region, obstacle boundary region, and without obstacles, thus clarifying the positional relationship between each region and the obstacle.

[0050] Next, the grid cells are dynamically merged according to their grid status to obtain the merged grid data; In the embodiments of this application, dynamic merging processing refers to merging multiple adjacent grid units with the same grid state or meeting preset merging conditions into a larger grid region based on the grid state of each grid unit. The merged grid data refers to the updated grid information after the merging process, including the center point coordinates, length information, and position index information of each merged grid unit in the grid array. Through dynamic merging processing, originally fragmented grid units can be integrated into fewer but larger grid regions, thereby reducing the number of grid units that need to be processed subsequently, reducing data storage requirements, and improving the efficiency of line segment generation and processing.

[0051] Finally, line segment combinations are generated based on the merged grid data, and these line segment combinations are merged to obtain scene collision data.

[0052] In the embodiments of this application, generating line segment combinations based on the merged grid data refers to extracting the line segment portions on the boundary of each grid unit that coincide with the obstacle boundary based on the intersection information between each merged grid unit and its corresponding obstacle boundary, and organizing these line segments into line segment combinations according to their positional relationship on the two-dimensional plane. Merging line segment combinations refers to merging adjacent line segments in the line segment combination that meet the merging conditions. For example, multiple line segments located on the same straight line and adjacent at the beginning and end are merged into a longer line segment, or two line segments with an included angle of nearly 180 degrees and adjacent endpoints are merged into a single line segment.

[0053] By merging line segments, the number of line segments can be reduced while maintaining the basic shape of the obstacle boundary, thus minimizing the total number of line segments in the scene collision data. This reduces the number of line segments that need to participate in the intersection determination calculation during subsequent collision detection, further improving the calculation efficiency of collision determination and reducing the storage space occupied by scene collision data.

[0054] This application automatically converts the surface information of obstacles in a 3D scene into a combination of line segments on a 2D plane and generates scene collision data, reducing the production cost of scene collision data. At the same time, it reduces the amount of data through dynamic merging and line segment merging processing, making the final generated scene collision data structure compact and efficient to query, providing a data foundation for real-time collision detection.

[0055] In one possible implementation of this application embodiment, when dividing a two-dimensional detection scene into grids to obtain multiple grid units, the following methods can be used, but are not limited to: determining the minimum square side length covering the projection shape of the virtual target in the top-view direction; using half the side length of the minimum square as the side length of the grid unit, dividing the two-dimensional detection scene into grids to obtain multiple grid units.

[0056] In the embodiments of this application, the projection shape of a virtual target in the top-down direction refers to the projection outline formed on the horizontal plane when the virtual target is viewed vertically downward from above the three-dimensional scene. The specific shape of the projection depends on the shape design of the virtual target. For example, for a humanoid virtual character, its top-down projection shape can be approximately elliptical or rectangular; for a circular virtual object, its top-down projection shape can be approximately circular.

[0057] The smallest square covering the projected shape is the square with the smallest area that can completely enclose the projected shape. This means that the four sides of this square are parallel to or at a predetermined angle to the two coordinate axes on the horizontal plane, and the interior area of ​​this square completely contains the entire range of the projected shape. By determining the side length of the smallest square covering the projected shape, the spatial range occupied by the virtual target on the horizontal plane can be quantified into a square size parameter. This size parameter reflects the maximum area occupied by the virtual target in the horizontal direction.

[0058] The grid cell side length refers to the side length of the square within each grid cell on the horizontal plane. The grid cell side length is determined by half the side length of the smallest square; that is, half the side length of the smallest square is used to define the side length of each grid cell. Mesh generation refers to dividing the 2D detection scene on the horizontal plane into multiple identical square grid regions along two mutually perpendicular coordinate axes, using the grid cell side length as the basic unit. Each square grid region is a grid cell.

[0059] In one possible application scenario of this application, based on a new scene to be detected, namely a two-dimensional detection scene, the largest square packet occupied by the virtual target area is calculated from a top-down view to obtain the side length of the character square. A square with a side length of A / 2 is set to divide the scene O into grids, and the intersection points of the calculated square grids and the tangent planes of the scene O are obtained. The grids are marked as three states: inside the obstacle, at the edge of the obstacle, and without obstacles.

[0060] In one possible implementation of this application embodiment, when calculating the intersection information of each grid cell with the boundary of an obstacle in the two-dimensional detection scene, and marking the grid state of each grid cell according to the intersection information, it can be implemented in the following ways, but not limited to: calculating the intersection of each edge of each grid cell with the boundary of an obstacle in the two-dimensional detection scene to obtain the intersection information, and determining the positional relationship between each grid cell and the obstacle according to the intersection information; marking the grid state according to the positional relationship, the grid state includes the obstacle interior state, the obstacle boundary state, and the obstacle exterior state, the obstacle boundary state is that the grid cell has one to three edges that intersect with the obstacle boundary and the intersection points are not all located on the same obstacle boundary; after marking the grid state according to the positional relationship, it further includes: removing all intersection points of grid cells whose grid state is the obstacle interior state; retaining all intersection points of grid cells whose grid state is the obstacle boundary state.

[0061] In the embodiments of this application, the grid cell has four sides. It is determined whether each of the four sides of the grid cell intersects with the boundary line of the obstacle in the two-dimensional detection scene. If they intersect, the specific coordinate position of the intersection point is recorded to obtain the intersection point information corresponding to each grid cell. The intersection point information includes whether there is an intersection point on each side of the grid cell, the number of intersection points, and the coordinate position data of the intersection points.

[0062] An obstacle boundary refers to the edge line of the cross-sectional profile of an obstacle in a two-dimensional detection scene. It can be one or more line segments or curve segments. Based on the intersection information, the positional relationship between each grid cell and the obstacle can be determined, that is, whether the grid cell is located inside the obstacle, on the obstacle boundary, or outside the obstacle in space.

[0063] The obstacle interior state indicates that the entire grid cell is located within the obstacle's interior region, meaning the entire space covered by the grid cell is occupied by the obstacle. The obstacle exterior state indicates that the entire space covered by the grid cell is not occupied by the obstacle. The obstacle boundary state indicates that the grid cell is located within the obstacle's boundary region, meaning a portion of the grid cell's space is occupied by the obstacle, while another portion is not.

[0064] The specific conditions for determining the state of the obstacle boundary include: the total number of intersections between the grid cell and the obstacle boundary corresponds to one, two, or three edges, meaning that the edges of the grid cell intersect with the obstacle boundary, but not all four edges intersect with the obstacle boundary (if all four edges intersect, it may indicate that the obstacle covers the entire perimeter of the grid cell); the intersections are distributed on one, two, or three different edges, and the intersections are not all located on the same obstacle boundary, meaning that the obstacle boundary segments corresponding to the intersections are not limited to the same straight line segment or the same obstacle boundary line, thereby ensuring that the contact between the grid cell and the obstacle boundary is a true boundary crossing contact rather than a local tangent contact.

[0065] In the embodiments of this application, removing all intersections of grid cells whose grid state is inside an obstacle means deleting or discarding all intersection information corresponding to the grid cells marked as inside an obstacle. Retaining all intersections of grid cells whose grid state is the boundary of an obstacle means retaining all intersection information corresponding to the grid cells marked as the boundary of an obstacle, and using these intersections as valid basic data for subsequent line segment generation.

[0066] In one possible application scenario of this application, the lattice cell state determination includes: Inside the obstacle: This means the entire grid is inside the obstacle.

[0067] Obstacle edge: One to three of the four edges intersect with the obstacle, and the intersection points are not on the same edge.

[0068] Outside the barrier: The entire grid is outside the barrier.

[0069] If the current cell is inside an obstacle, discard all intersections of the edge containing it.

[0070] If the current cell is an obstacle edge, then retain the edge intersection.

[0071] In one possible implementation of this application embodiment, when dynamically merging each grid cell according to the grid state, it can be implemented in the following ways, but not limited to: traversing according to the row direction of the grid cell, merging the grid cells that are continuously in the obstacle boundary state in the same row to obtain a horizontally merged grid; updating the center point data and length of the merged grid cell to obtain the merged grid data.

[0072] In the embodiments of this application, the row direction of a grid cell refers to the direction in which multiple grid cells extend along the horizontal coordinate axis on the horizontal plane within the grid array formed after meshing; that is, the horizontal arrangement direction in the grid array. In a two-dimensional grid, grid cells are arranged according to a row and column rule. Each row contains multiple grid cells arranged sequentially along the row direction, and each column contains multiple grid cells arranged sequentially along the column direction (i.e., the direction perpendicular to the row direction). Traversing according to the row direction of the grid cells means processing row by row, starting from the first row of the grid array, and sequentially detecting and judging each grid cell in each row along the row direction.

[0073] A series of cells in a barrier boundary state refers to multiple cells that are consecutively arranged along the row direction in the currently traversed row and are all marked as barrier boundary states. For example, when the i-th cell, the (i+1)-th cell, to the j-th cell (j > i) are arranged adjacently along the row direction, and each of these cells is in a barrier boundary state, then these cells constitute a series of cells in a barrier boundary state. A consecutive arrangement means that there are no other states between any two adjacent cells; that is, all cells from the first boundary state cell to the last boundary state cell are in a barrier boundary state.

[0074] By lateral merging, consecutive obstacle boundary state grid cells in the same row are integrated, so that a large number of fragmented grid cells in the obstacle boundary area of ​​the 2D detection scene are aggregated into fewer and larger horizontal strip grid areas, thereby effectively reducing the number of grid cells to be processed.

[0075] The merged grid cell refers to the new grid region formed after horizontal merging. This includes horizontally merged grids formed by combining multiple original grid cells, as well as original grid cells that have not undergone merging. The center point data refers to the coordinates of the geometric center point of the merged grid cell on a two-dimensional plane. For horizontally merged grids formed by combining multiple grid cells, the center point coordinates need to be recalculated based on the original center point coordinates of the merged grid cells. Specifically, the geometric center point position of the horizontally merged grid cell can be calculated based on the span of the merged grid cells in the row direction. The length refers to the extension length of the merged grid cell in the row direction. For horizontally merged grids, its length is equal to the sum of the side lengths of the merged grid cells; for unmerged grid cells, its length is equal to the side length of the original grid cell.

[0076] The merged grid data is stored as an updated dataset, which includes the center point coordinates, length information, and position index information of each merged grid cell in the grid array. Compared to the original grid data, the merged grid data has fewer data entries, and each data entry corresponds to a larger grid area with a wider coverage.

[0077] In one possible application scenario of this application, an embodiment of this application provides a schematic diagram of lattice cell merging, such as... Figure 4 As shown, horizontal cells are dynamically merged, while vertical cells remain unchanged. The cells are traversed sequentially from left to right. If a cell is an obstacle edge, all cells from the starting cell to the current cell are merged, and the cell center point data and length information are updated (if the starting cell is an obstacle edge, the current cell is not modified). If there are no obstacles until the end, a merge operation is performed, and the cell center data and length information are updated. This merging operation is performed on all rows containing cells sequentially, resulting in the merged cell data.

[0078] In one possible implementation of this application embodiment, when merging line segment combinations to obtain scene collision data, the following methods can be used, but are not limited to: obtaining the adjacent line segment combinations of the target grid cell and adjacent grid cells, wherein the target grid cell is any grid cell in the merged grid data, and the adjacent line segments in the adjacent line segment combinations share a common endpoint; in response to the distance between other endpoints of the adjacent line segments being less than a preset distance threshold, merging the adjacent line segment combinations to obtain merged line segments, wherein the other endpoints are the endpoints of the adjacent line segments excluding the common endpoints; determining scene collision data based on the merged line segments; merging adjacent line segment combinations includes: in response to the horizontal coordinate distance between other endpoints being less than a preset horizontal distance threshold and the included angle between adjacent line segments at the common vertex being greater than a preset angle threshold, using the other endpoints as the endpoints of the new line segments to generate merged line segments.

[0079] In the embodiments of this application, the target cell refers to any cell in the merged cell data. Adjacent cell refers to a cell in the cell array of the merged cell data that is spatially adjacent to the target cell, including but not limited to cells adjacent to the target cell in the row direction, column direction, and diagonal direction. In the embodiments of this application, adjacent cell units may include those located above, below, to the left, and to the right of the target cell.

[0080] A pair of adjacent line segments refers to a pair of line segments belonging to the target grid cell and the adjacent grid cell, respectively, where the two line segments in the pair share a common endpoint. Each line segment is defined by its two endpoints; a shared endpoint is the same endpoint shared by both line segments, meaning that endpoint serves as the endpoint of both line segments. When line segments in two adjacent grid cells are spatially connected end-to-end or intersect at the same point, these two line segments can be identified as adjacent line segments with a shared endpoint, thus forming a pair of adjacent line segments.

[0081] Other endpoints refer to the other endpoint of each of the two line segments in an adjacent line segment combination, excluding the shared endpoint. For example, when an adjacent line segment combination includes line segment A and line segment B, line segment A has a shared endpoint and a first other endpoint, and line segment B has a shared endpoint and a second other endpoint. The first and second other endpoints are collectively referred to as other endpoints. The distance between other endpoints refers to the geometric distance between the first and second other endpoints, i.e., the Euclidean distance between the two endpoints in a two-dimensional plane. The preset distance threshold is a pre-set distance value that can be set according to actual application requirements or the size parameters of the virtual target.

[0082] When the distance between other endpoints is less than a preset distance threshold, it indicates that the two adjacent line segments are spatially close enough to be merged. Therefore, these two line segments are merged to obtain a merged line segment. The merged line segment is a newly generated line segment that replaces two line segments in the original combination of adjacent line segments.

[0083] Determining scene collision data based on merged line segments means taking all line segments obtained after merging (including merged line segments generated after merging and original line segments that did not participate in merging) as the updated line segment combination, and using this updated line segment combination as the line segment component in the scene collision data.

[0084] Furthermore, horizontal coordinate distance refers to the absolute value of the coordinate difference between other endpoints on a two-dimensional horizontal plane, or the distance in the horizontal direction, i.e., the projected distance between two endpoints in the direction of the horizontal coordinate axis. The preset horizontal distance threshold is a pre-set critical value for horizontal distance, which can be set according to actual application requirements or the size parameters of the virtual target.

[0085] The angle between adjacent line segments at a common vertex refers to the angle formed by two line segments in a combination of adjacent line segments at a common endpoint. That is, the angle formed by extending along the directions of the two line segments from the common endpoint. The preset angle threshold is a pre-set angle critical value, which can be set according to actual application needs, such as 135 degrees or 150 degrees.

[0086] Generating a merged line segment by using other endpoints as the endpoints of a new line segment means taking the first and second other endpoints from the combination of adjacent line segments as the two endpoints of the newly generated line segment, and constructing a new line segment with these two endpoints as its starting and ending points. This new line segment is the merged line segment. Through this operation, the original two line segments are replaced by a new line segment extending from the first other endpoint to the second other endpoint. This new line segment discards the original shared endpoints and directly connects the two other endpoints.

[0087] In one possible application scenario, this application provides a schematic diagram of line segment combinations, such as... Figure 5 As shown, line segment information, i.e., line segment combinations, is generated based on grid and intersection data. The line segments are stored in an array, recording the start and end points, while the grid is bound to the line segment index.

[0088] When merging line segments, this application provides a schematic diagram of line segment combination, such as... Figure 6 As shown, the process involves collecting line segment data from the four adjacent cells of the current cell and merging the line segments according to rules.

[0089] If the endpoints of adjacent line segments lie on the same side and the distance between them is less than A / 4 of the side length of the square, then the endpoints are connected to form a new line segment, such as... Figure 6 Line segment 3 in the diagram. Its characteristics are explained in detail below: The specific formula process is as follows: Let the side length of the square be A, and the endpoints of the adjacent line segments be respectively... and Both must satisfy: Same-side determination:

[0090] Distance determination:

[0091] Connection operation:

[0092] Next, we will perform line segment smoothing: Select adjacent grid segments, and for shared vertices, for example... Figure 6 For line segments 1 and 2, and line segments 4 and 7, if the horizontal coordinate distance between their endpoints is less than A / 2 and the included angle is greater than 135 degrees, then the original line segments are discarded, and new line segments are generated using the two ends of the original line segments as the endpoints. The specific formula process is as follows: Let Vc be the common vertex of adjacent line segments La and Lb, and Va and Vb be their endpoints.

[0093] Horizontal distance determination:

[0094] Angle determination:

[0095] Line segment reconstruction operation:

[0096] If line segments connect to form a triangle, determine if the edge is inside the scene; if so, cull the line segment. For example... Figure 6 The middle segments 5 and 7 are determined to be invalid segments.

[0097] That is, when the reconstructed line segment and another line segment form a triangular closed region, it is determined whether the triangular closed region is located inside the obstacle. If it is located inside the obstacle, at least one of the reconstructed line segment or the other line segment is removed.

[0098] In one possible implementation of this application embodiment, when calculating the predicted position information of the virtual target in the next frame based on the current frame position information and motion parameters, it can be implemented in the following ways, but not limited to: determining the current frame position coordinates, motion velocity vector, motion direction vector, and physical duration of each frame of the virtual target based on the current frame position information and motion parameters; calculating the predicted position information based on the current frame position coordinates, motion velocity vector, motion direction vector, and physical duration of each frame; determining the predicted grid cell where the predicted position information of the virtual target in the next frame is located based on the predicted position information; and generating the predicted motion line segment based on the current frame position coordinates and the predicted position information.

[0099] In the embodiments of this application, the current frame position coordinates refer to the spatial position coordinates of the virtual target in the 3D scene at the current display frame or the current physical simulation frame. The motion velocity vector refers to data representing the magnitude and direction of the virtual target's motion velocity in the current frame. The motion direction vector is a vector extracted from the motion velocity vector to represent the direction of the virtual target's motion in the current frame. Its direction is consistent with the direction of the motion velocity vector, and its magnitude is normalized to a unit length, i.e., the motion direction vector is a unit vector used to indicate the direction of the virtual target's movement in the current frame, without including information about the velocity magnitude. The physical duration per frame refers to the physical simulation time step corresponding to each frame during the virtual scene's operation, which is used to convert the virtual target's velocity parameters into displacement within each frame.

[0100] The predicted position information is calculated by multiplying the motion velocity vector by the motion direction vector and then by the physical duration of each frame to obtain the displacement vector of the virtual target during the period from the current frame to the next frame. Then, the position coordinates of the current frame are added to the displacement vector to obtain the coordinates of the predicted position information.

[0101] A prediction grid cell refers to a grid cell in the merged grid data that contains the coordinates of the predicted location information. Since each grid cell in the merged grid data has a definite coverage area on a two-dimensional plane, the grid cell in which the predicted location information falls can be determined by comparing the coordinates of the predicted location information with the coverage areas of each grid cell; this grid cell is the prediction grid cell.

[0102] A predicted motion segment is a line segment constructed with the current frame position coordinates as the starting point and the predicted position information as the ending point. This predicted motion segment represents the path trajectory of the virtual target as it moves from the current frame position to the predicted position.

[0103] In one possible application scenario of this application, an embodiment of this application provides a schematic diagram of the location information of a virtual target, such as... Figure 7 As shown, the center point of the character (i.e., the virtual target) is used as the motion coordinate point. Since the scene has been zeroed out, the character's coordinates are always positive during the movement. Knowing the center point and width / length of each grid, the character's current grid position can be obtained through the coordinate range. Line segment information is then derived from the grid. Collision calculations are performed using points, motion vectors, velocities, and line segments to obtain the target point. Assuming P0 is the starting character point, the possible points P0 that the character can reach in the next frame are... That is, the target point.

[0104] When calculating the target point of the next frame: Based on the current character's position, movement speed, direction, and physics time per frame, the target point P0 can be calculated. (x, y), the grid cell G0 where the target point is located. Current point P0 and P0 Line segment L0 with endpoints .

[0105] When determining whether a collision has been triggered: Calculate L0 With grid G0 The system calculates the intersection points of all line segments. If there are no intersection points, the target point is applied directly. The character can move directly; if there are intersection points, collision feedback calculation continues.

[0106] Therefore, in one possible implementation of this application embodiment, when performing collision determination processing based on predicted position information and scene collision data to obtain a determination result, it can be implemented in the following ways, but not limited to: obtaining the line segment combination corresponding to the predicted grid cell; calculating the intersection point of the predicted motion line segment with each line segment in the line segment combination corresponding to the predicted grid cell; in response to the fact that there is no intersection point between the predicted motion line segment and each line segment in the line segment combination corresponding to the predicted grid cell, determining that no collision has occurred, and using the predicted position information as the motion target point; in response to the fact that there is an intersection point between the predicted motion line segment and each line segment in the line segment combination corresponding to the predicted grid cell, determining that a collision has occurred, and selecting the intersection point closest to the current frame position coordinates as the collision point.

[0107] In one possible implementation of this application embodiment, when calculating the moving target point of the virtual target based on the relative positional relationship between the virtual target's motion direction and the collision point, the following methods can be used, but are not limited to: Determine the tangent and normal vectors of the line segment where the collision point is located; calculate the tangent projection point of the predicted position information on the tangent vector, and calculate the smooth motion point based on the tangent projection point, the collision point, and the preset friction coefficient; calculate the normal projection point of the predicted position information on the normal vector, and calculate the rebound motion point based on the normal projection point, the collision point, and the preset rebound coefficient; translate the smooth motion point along the normal vector by a preset distance to obtain the smooth translation point, and use the smooth translation point as the candidate motion target point; use the collision point as the starting point and the candidate motion target point as the predicted position information, and repeat the collision determination process and motion target point calculation process until it is determined that no collision has occurred, and use the candidate motion target point obtained in the last iteration as the motion target point.

[0108] In the embodiments of this application, the line segment where the collision point is located refers to the line segment in the scene collision data that intersects with the predicted motion line segment and whose intersection point is determined to be the collision point. The tangent direction vector is a direction vector parallel to the direction of the line segment where the collision point is located. The normal direction vector is a direction vector perpendicular to the line segment where the collision point is located. In the embodiments of this application, the normal direction vector can be taken as the normal direction pointing to the side of the virtual target's movement direction.

[0109] The tangent projection point refers to the projected position of the predicted position information coordinates along the normal direction vector onto the tangent direction of the line segment containing the collision point. Specifically, starting from the collision point, the position vector of the predicted position information relative to the collision point is calculated. Then, this position vector is projected onto the tangent direction vector to obtain the projection distance along the tangent direction. The position reached by moving this projection distance along the tangent direction from the collision point is the tangent projection point.

[0110] The preset friction coefficient is a pre-defined numerical parameter used to characterize the degree to which the obstacle surface hinders the virtual target from sliding along the surface. The smooth motion point is calculated as follows: calculate the displacement vector of the tangent projection point relative to the collision point, multiply this displacement vector by the preset friction coefficient to obtain the smooth displacement, and then add the collision point position to the smooth displacement to obtain the smooth motion point.

[0111] The normal projection point refers to the projected position of the coordinate point of the predicted position information along the tangent direction vector onto the normal direction of the line segment where the collision point is located. Specifically, starting from the collision point, the position vector of the predicted position information relative to the collision point is calculated. Then, this position vector is projected onto the normal direction vector to obtain the projection distance along the normal direction. The position reached by moving this projection distance along the normal direction from the collision point is the normal projection point.

[0112] The preset rebound coefficient is a pre-defined numerical parameter used to characterize the intensity of the rebound of the virtual target from the obstacle surface along the normal direction. The rebound motion point is calculated as follows: calculate the displacement vector of the normal projection point relative to the collision point, with the direction of this displacement vector pointing outward from the obstacle. Then, starting from the collision point, move along the normal direction vector by multiplying the preset rebound coefficient by the magnitude of this displacement vector to obtain the rebound motion point.

[0113] The preset distance can be the magnitude of the position vector of the normal projection point relative to the collision point, that is, the projection distance of the virtual target in the normal direction. The smooth translation point refers to the position coordinates obtained by translating the smooth motion point along the normal direction vector by a preset distance.

[0114] In real-world complex obstacle environments, a virtual target may encounter other obstacle segments along its smooth movement path, resulting in secondary or even multiple collisions. To address this, an iterative calculation method is employed: the collision point determined in the current collision assessment is used as the new starting point, and the candidate moving target point obtained in this calculation is used as the new predicted position information. The collision assessment process is then repeated to determine whether the moving line segment from the collision point to the candidate moving target point collides with other obstacle segments. If a collision is determined again, the moving target point is recalculated based on the new collision point to obtain a new candidate moving target point, and the next iteration begins. If no collision is determined, the iteration stops, and the candidate moving target point obtained in the last iteration is determined as the final moving target point.

[0115] In one possible application scenario of this application, the calculation of the moving target point can be implemented in, but is not limited to, the following ways: First, this application provides the following: Figure 8 The diagram shown illustrates a calculation of smoothness and rebound, as follows: Figure 9 The diagram shows a translation process, and as shown in the figure. Figure 10 The diagram shown illustrates a secondary collision detection method.

[0116] Let Pa be the collision point, v be the velocity before the collision, n be the normal vector of the line segment (unit vector), and t be the tangent vector (unit vector). The target point calculation is a combination of components in two directions.

[0117] 1) Smooth movement direction: The predicted location information P0 is calculated using the projection formula. Project P0 onto the tangent direction of the line segment at the intersection point. The smooth point is obtained. The coefficient of friction is set between s=(0,1) based on the type of object in the scene. The final smooth motion point is: P0 顺滑 =Pa+s(P0 -Pa) 2) Collision bounce: Similarly, calculate P0 Projecting along the normal direction of the intersection point, we get P0n. The bounce coefficient is set between (0, 1) based on the object type in the scene where the straight line is located, and the final bounce coordinate point is P0. 反弹 =Pa+w(Pa- P0n ) 3) Translation processing: P0 顺滑Make a translation in the direction of the rebound, and the translation distance is the perpendicular distance to the line segment, and finally obtain the candidate motion target point.

[0118] 4) Secondary collision calculation: Based on the candidate moving target point P obtained after the smoothing process following the first collision, the collision point is used as the starting point, and target P is set as the target point for the next frame. Collision feedback calculations are performed again until no intersection points are found, at which point the moving target point is successfully set. For example: Figure 10 In the diagram, P1 is the candidate target point obtained from the first calculation, and it intersects with line segment 2 to obtain P2.

[0119] Corresponding to the collision detection method described above, this application also proposes a collision detection device. Since the device embodiment of this application corresponds to the method embodiment described above, details not disclosed in the device embodiment can be referred to in the method embodiment described above, and will not be repeated here.

[0120] Figure 11 This is a schematic diagram of the structure of a collision detection device provided in an embodiment of this application, as shown below. Figure 11 As shown, it includes: The generation unit 1101 is used to acquire surface information of obstacles in a three-dimensional scene, convert the surface information into a combination of line segments on a two-dimensional plane, and generate scene collision data based on the combination of line segments. The first calculation unit 1102 is used to obtain the current frame position information and motion parameters of the virtual target in the three-dimensional scene, and calculate the predicted position information of the virtual target in the next frame based on the current frame position information and motion parameters. The determination unit 1103 is used to perform collision determination processing based on the predicted position information and scene collision data to obtain the determination result; The second calculation unit 1104 is used to calculate the moving target point of the virtual target based on the relative positional relationship between the motion direction of the virtual target and the collision point in response to the judgment result indicating that a collision has occurred. The moving unit 1105 is used to move the virtual target to the moving target point.

[0121] Furthermore, in one possible implementation of this application embodiment, the generation unit 1101 is specifically used for: Obtain the minimum coordinates of the axis-aligned bounding box of the 3D scene, calculate the translation vector from the minimum coordinates to the origin of the world coordinate system, and translate all scene elements of the 3D scene according to the translation vector to obtain the 3D scene after zeroing. In the top-down direction, the cross-section of the zeroed 3D scene is clipped using the horizontal plane corresponding to the target height of the virtual target as the cross section to obtain the 2D detection scene; Based on the two-dimensional detection scene, the two-dimensional detection scene is divided into grids according to the projection size of the virtual target in the top view direction, resulting in multiple grid units; Calculate the intersection information of each grid cell with the boundary of obstacles in the two-dimensional detection scene, and mark the grid state of each grid cell based on the intersection information; The grid cells are dynamically merged based on their state to obtain the merged grid data. Line segment combinations are generated based on the merged grid data, and these line segment combinations are then merged to obtain scene collision data.

[0122] Furthermore, in one possible implementation of this application embodiment, the generation unit 1101 is specifically used for: Based on the projection shape of the virtual target in the top-view direction, determine the minimum side length of the square covering the projection shape; The two-dimensional detection scene is divided into multiple grid units by using half the side length of the smallest square as the side length of the grid unit.

[0123] Furthermore, in one possible implementation of this application embodiment, the generation unit 1101 is specifically used for: Calculate the intersection points of each edge of each grid cell with the boundary of the obstacle in the 2D detection scene to obtain the intersection point information, and determine the positional relationship between each grid cell and the obstacle based on the intersection point information; The grid state is marked according to the positional relationship. The grid state includes the obstacle interior state, obstacle boundary state and obstacle exterior state. The obstacle boundary state is when a grid cell has one to three edges that intersect with the obstacle boundary and not all of the intersections are located on the same obstacle boundary. After marking the grid state according to the positional relationship, the process also includes: removing all intersections of grid cells whose grid state is the interior state of an obstacle; and retaining all intersections of grid cells whose grid state is the boundary state of an obstacle.

[0124] Furthermore, in one possible implementation of this application embodiment, the generation unit 1101 is specifically used for: Traverse the grid cells along the row direction and merge the grid cells that are consecutively in the obstacle boundary state in the same row to obtain a horizontally merged grid. Update the center point data and length of the merged grid cells to obtain the merged grid data.

[0125] Furthermore, in one possible implementation of this application embodiment, the generation unit 1101 is specifically used for: Obtain the combination of adjacent line segments of the target cell and adjacent cell, where the target cell is any cell in the merged cell data, and the adjacent line segments in the combination of adjacent line segments have common endpoints; In response to the distance between other endpoints of adjacent line segments being less than a preset distance threshold, the adjacent line segments are combined and merged to obtain a merged line segment, where the other endpoints are the endpoints of the adjacent line segments excluding the shared endpoints; Determine scene collision data based on the merged line segments; Merging adjacent line segments includes: In response to situations where the horizontal coordinate distance between other endpoints is less than a preset horizontal distance threshold and the angle between adjacent line segments at a shared vertex is greater than a preset angle threshold, the other endpoints are used as the endpoints of the new line segment to generate the merged line segment.

[0126] Furthermore, in one possible implementation of this application embodiment, the first computing unit 1102 is specifically used for: The current frame position coordinates, motion velocity vector, motion direction vector, and physical duration of each frame of the virtual target are determined based on the current frame position information and motion parameters. The predicted position information is calculated based on the current frame position coordinates, motion velocity vector, motion direction vector, and physical duration of each frame; The predicted position cell of the virtual target in the next frame is determined based on the predicted position information, and the predicted motion line segment is generated based on the current frame position coordinates and the predicted position information.

[0127] Furthermore, in one possible implementation of this application embodiment, the determination unit 1103 is specifically used for: Obtain the line segment combination corresponding to the predicted grid cell; Calculate the intersection points of each line segment in the combination of the predicted motion line segment and the line segment corresponding to the predicted grid cell; In response to the fact that there are no intersections between the line segments in the predicted motion line segment and the line segment combination corresponding to the predicted grid cell, it is determined that no collision has occurred, and the predicted position information is used as the motion target point; In response to the existence of intersections between the predicted motion line segments and the line segments corresponding to the predicted grid cells, a collision is determined, and the intersection point closest to the current frame position coordinates is selected as the collision point.

[0128] Furthermore, in one possible implementation of this application embodiment, the second computing unit 1104 is specifically used for: Determine the tangent and normal vectors of the line segment where the collision point is located; Calculate the tangent projection point of the predicted position information on the tangent direction vector, and calculate the smooth motion point based on the tangent projection point, the collision point and the preset friction coefficient; Calculate the normal projection point of the predicted position information on the normal direction vector, and calculate the rebound motion point based on the normal projection point, the collision point and the preset rebound coefficient; The smooth motion point is translated by a preset distance along the normal direction vector to obtain the smooth translation point, and the smooth translation point is used as the candidate motion target point; Using the collision point as the starting point and the candidate moving target point as the predicted position information, the collision determination process and the moving target point calculation process are repeatedly executed until it is determined that no collision has occurred. The candidate moving target point obtained in the last iteration is then used as the moving target point.

[0129] It should be noted that the foregoing explanation of the method embodiments also applies to the apparatus of the embodiments of this application, and the principle is the same. Therefore, the embodiments of this application are not limited thereto.

[0130] According to embodiments of this application, this application also provides an electronic device, a readable storage medium, and a computer program product.

[0131] Figure 12 A schematic block diagram of an example electronic device 1200 that can be used to implement embodiments of this application is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the application described and / or claimed herein.

[0132] like Figure 12 As shown, device 1200 includes a computing unit 1201, which can perform various appropriate actions and processes based on a computer program stored in ROM (Read-Only Memory) 1202 or loaded from storage unit 1208 into RAM (Random Access Memory) 1203. RAM 1203 may also store various programs and data required for the operation of device 1200. The computing unit 1201, ROM 1202, and RAM 1203 are interconnected via bus 1204. I / O (Input / Output) interface 1205 is also connected to bus 1204.

[0133] Multiple components in device 1200 are connected to I / O interface 1205, including: input unit 1206, such as keyboard, mouse, etc.; output unit 1207, such as various types of monitors, speakers, etc.; storage unit 1208, such as disk, optical disk, etc.; and communication unit 1209, such as network card, modem, wireless transceiver, etc. Communication unit 1209 allows device 1200 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0134] The computing unit 1201 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 1201 include, but are not limited to, CPUs (Central Processing Units), GPUs (Graphics Processing Units), various special-purpose AI (Artificial Intelligence) computing chips, various computing units running machine learning model algorithms, DSPs (Digital Signal Processors), and any suitable processor, controller, microcontroller, etc. The computing unit 1201 performs the various methods and processes described above, such as collision detection methods. For example, in some embodiments, the collision detection method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 1208. In some embodiments, part or all of the computer program may be loaded and / or installed on device 1200 via ROM 1202 and / or communication unit 1209. When the computer program is loaded into RAM 1203 and executed by the computing unit 1201, one or more steps of the methods described above may be performed. Alternatively, in other embodiments, the computing unit 1201 may be configured to perform the aforementioned collision detection method by any other suitable means (e.g., by means of firmware).

[0135] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, FPGAs (Field Programmable Gate Arrays), ASICs (Application-Specific Integrated Circuits), ASSPs (Application-Specific Standard Products), SOCs (System-on-Chips), CPLDs (Complex Programmable Logic Devices), computer hardware, firmware, software, and / or combinations thereof. These various implementations may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0136] The program code used to implement the methods of this application may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0137] In the context of this application, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, RAM, ROM, EPROM (Electrically Programmable Read-Only Memory) or flash memory, optical fiber, CD-ROM (Compact Disc Read-Only Memory), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0138] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (Cathode-Ray Tube) or LCD (Liquid Crystal Display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0139] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include LANs (Local Area Networks), WANs (Wide Area Networks), the Internet, and blockchain networks.

[0140] Computer systems can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. A server can be a cloud server, also known as a cloud computing server or cloud host, a hosting product within the cloud computing service system that addresses the shortcomings of traditional physical hosts and VPS (Virtual Private Server) services, such as high management difficulty and weak business scalability. Servers can also be servers for distributed systems or servers incorporating blockchain technology.

[0141] It's important to note that artificial intelligence (AI) is the study of enabling computers to simulate certain human thought processes and intelligent behaviors (such as learning, reasoning, thinking, and planning). It encompasses both hardware and software technologies. AI hardware technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, and big data processing. AI software technologies primarily include computer vision, speech recognition, natural language processing, machine learning / deep learning, big data processing, and knowledge graph technologies.

[0142] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this application can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this application can be achieved, and this is not limited herein.

[0143] The specific embodiments described above do not constitute a limitation on the scope of protection of this application. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this application should be included within the scope of protection of this application.

Claims

1. A collision detection method, characterized in that, include: The surface information of obstacles in a 3D scene is acquired, the surface information is converted into a combination of line segments on a 2D plane, and scene collision data is generated based on the combination of line segments. Obtain the current frame position information and motion parameters of the virtual target in the three-dimensional scene, and calculate the predicted position information of the virtual target in the next frame based on the current frame position information and the motion parameters; Based on the predicted location information and the scene collision data, a collision determination process is performed to obtain the determination result; In response to the determination result indicating a collision, the motion target point of the virtual target is calculated based on the relative positional relationship between the motion direction of the virtual target and the collision point, and the virtual target is moved to the motion target point.

2. The method according to claim 1, characterized in that, The process of acquiring surface information of obstacles in a 3D scene, converting the surface information into combinations of line segments on a 2D plane, and generating scene collision data based on the combinations of line segments includes: Obtain the minimum coordinates of the axis-aligned bounding box of the 3D scene, calculate the translation vector from the minimum coordinates to the origin of the world coordinate system, and translate all scene elements of the 3D scene according to the translation vector to obtain the 3D scene after zeroing. In the top-down direction, the zeroed 3D scene is clipped using the horizontal plane corresponding to the target height of the virtual target as the cross section to obtain the 2D detection scene; Based on the two-dimensional detection scene, the two-dimensional detection scene is divided into grids according to the projection size of the virtual target in the top-view direction to obtain multiple grid units; Calculate the intersection information of each grid cell with the boundary of the obstacle in the two-dimensional detection scene, and mark the grid state of each grid cell according to the intersection information; The grid cells are dynamically merged according to their grid states to obtain merged grid data. The line segment combination is generated based on the merged grid data, and the line segment combination is merged to obtain the scene collision data.

3. The method according to claim 2, characterized in that, The step of dividing the two-dimensional detection scene into grids according to the projection size of the virtual target in the top-view direction to obtain multiple grid units includes: Based on the projection shape of the virtual target in the top-view direction, determine the minimum side length of the square that covers the projection shape; Using half the side length of the smallest square as the side length of the grid unit, the two-dimensional detection scene is divided into grids to obtain the multiple grid units.

4. The method according to claim 2, characterized in that, The step of calculating the intersection information of each grid cell with the boundary of the obstacle in the two-dimensional detection scene, and marking the grid state of each grid cell according to the intersection information, includes: Calculate the intersection points of each edge of each grid cell with the boundary of the obstacle in the two-dimensional detection scene to obtain the intersection point information, and determine the positional relationship between each grid cell and the obstacle based on the intersection point information; The grid state is marked according to the positional relationship. The grid state includes the obstacle interior state, the obstacle boundary state, and the obstacle exterior state. The obstacle boundary state is that the grid cell has one to three edges that intersect with the obstacle boundary, and the intersection points are not all located on the same obstacle boundary. After marking the grid state according to the positional relationship, the method further includes: removing all intersections of grid cells whose grid state is the interior state of an obstacle; and retaining all intersections of grid cells whose grid state is the boundary state of an obstacle.

5. The method according to claim 2, characterized in that, The step of dynamically merging each grid cell according to the grid state to obtain merged grid data includes: Traverse the grid cells along their row direction and merge grid cells that are consecutively in the obstacle boundary state in the same row to obtain a horizontally merged grid. Update the center point data and length of the merged grid cell to obtain the merged grid data.

6. The method according to claim 2, characterized in that, The process of merging the line segment combinations to obtain the scene collision data includes: Obtain the adjacent line segment combinations of the target grid cell and adjacent grid cells, wherein the target grid cell is any grid cell in the merged grid data, and the adjacent line segments in the adjacent line segment combinations have common endpoints; In response to the fact that the distance between other endpoints of the adjacent line segments is less than a preset distance threshold, the adjacent line segments are combined and merged to obtain a merged line segment, wherein the other endpoints are the endpoints of the adjacent line segments other than the shared endpoints; The scene collision data is determined based on the merged line segments; The process of merging the adjacent line segments includes: In response to the horizontal coordinate distance between the other endpoints being less than a preset horizontal distance threshold and the included angle between the adjacent line segments at the shared vertex being greater than a preset angle threshold, the merged line segment is generated using the other endpoints as the endpoints of the new line segment.

7. The method according to claim 2, characterized in that, The step of calculating the predicted position information of the virtual target in the next frame based on the current frame position information and the motion parameters includes: Based on the current frame position information and the motion parameters, the current frame position coordinates, motion velocity vector, motion direction vector, and physical duration of each frame of the virtual target are determined. The predicted position information is calculated based on the current frame position coordinates, the motion velocity vector, the motion direction vector, and the physical duration of each frame; Based on the predicted position information, the predicted grid cell in which the virtual target is located in the next frame is determined, and a predicted motion segment is generated based on the current frame position coordinates and the predicted position information.

8. The method according to claim 7, characterized in that, The collision determination process performed based on the predicted location information and the scene collision data yields the following results: Obtain the line segment combination corresponding to the predicted grid unit; Calculate the intersection points of each line segment in the combination of the predicted motion line segment and the line segment corresponding to the predicted grid cell; In response to the fact that there are no intersections between the line segments in the combination of the predicted motion line segment and the line segment corresponding to the predicted grid cell, it is determined that no collision has occurred, and the predicted position information is used as the motion target point; In response to the existence of intersection points between the predicted motion line segment and each line segment in the combination corresponding to the predicted grid cell, a collision is determined, and the intersection point closest to the current frame position coordinates is selected as the collision point.

9. The method according to claim 8, characterized in that, The step of calculating the motion target point of the virtual target based on the relative positional relationship between the motion direction of the virtual target and the collision point includes: Determine the tangent direction vector and normal direction vector of the line segment where the collision point is located; Calculate the tangent projection point of the predicted position information on the tangent direction vector, and calculate the smooth motion point based on the tangent projection point, the collision point, and the preset friction coefficient; Calculate the normal projection point of the predicted position information on the normal direction vector, and calculate the rebound motion point based on the normal projection point, the collision point, and the preset rebound coefficient; The smooth motion point is translated by a preset distance along the normal direction vector to obtain a smooth translation point, and the smooth translation point is used as a candidate motion target point; Using the collision point as the starting point and the candidate moving target point as the predicted position information, the collision determination process and the moving target point calculation process are repeatedly executed until it is determined that no collision has occurred. The candidate moving target point obtained in the last iteration is then used as the moving target point.

10. A collision detection device, characterized in that, include: The generation unit is used to acquire surface information of obstacles in a three-dimensional scene, convert the surface information into a combination of line segments on a two-dimensional plane, and generate scene collision data based on the combination of line segments. The first calculation unit is used to obtain the current frame position information and motion parameters of the virtual target in the three-dimensional scene, and calculate the predicted position information of the virtual target in the next frame based on the current frame position information and the motion parameters. The determination unit is used to perform collision determination processing based on the predicted position information and the scene collision data to obtain a determination result. The second calculation unit is used to calculate the moving target point of the virtual target based on the relative positional relationship between the motion direction of the virtual target and the collision point in response to the determination result indicating that a collision has occurred; A moving unit is used to move the virtual target to the moving target point.