Disclosure of Invention
The invention provides a collision detection method and device, aiming at the problem that misjudgment possibly exists during collision detection in the related art.
According to an aspect of the present invention, there is provided a collision detection method including: judging whether the first curved surface and the second curved surface collide or not according to the geometric information of the first curved surface and the second curved surface to be detected; and under the condition that the first curved surface and the second curved surface are judged not to collide, determining that the first group of triangular plates corresponding to the first curved surface and the second group of triangular plates corresponding to the second curved surface do not collide.
Optionally, if it cannot be determined whether the first curved surface and the second curved surface collide with each other according to the geometric information of the first curved surface and the second curved surface, the method further includes: and for each triangular plate in the first set of triangular plates, detecting whether the triangular plate and the second curved surface collide or not according to the vertex position information of the triangular plate and the geometric information of the second curved surface, and if not, determining that the triangular plate and all the triangular plates in the second set of triangular plates do not collide.
Optionally, for one of the triangular plates in the first set of triangular plates, if it cannot be determined whether the triangular plate collides with the second curved surface by detecting vertex position information of the triangular plate and geometric information of the second curved surface, the method further includes: and detecting whether the triangular plate in the first set of triangular plates collides with each triangular plate in the second set of triangular plates or not according to the vertex position information of the triangular plate in the first set of triangular plates and the vertex position information of each triangular plate in the second set of triangular plates.
Optionally, detecting whether the triangular plate collides with the second curved surface includes at least one of: the second curved surface is a plane, and if three vertexes of the triangular plate are positioned on the same side of the second curved surface, the triangular plate and the second curved surface cannot collide; the second curved surface is a cylindrical surface, and if the distances between the three vertexes of the triangular plate and the central axis of the second curved surface are smaller than the radius of the second curved surface, the triangular plate and the second curved surface cannot collide; the second curved surface is a spherical surface, and if the distances between the three top points of the triangular plate and the spherical center of the second curved surface are smaller than the radius of the second curved surface, the triangular plate and the second curved surface cannot collide.
Optionally, if the first curved surface and the second curved surface are parallel planes, determining whether a collision occurs between the first curved surface and the second curved surface includes at least one of: if the first curved surface and the second curved surface are not coplanar, the first curved surface and the second curved surface cannot collide; if the first curved surface and the second curved surface are coplanar and the normal vector direction of the first curved surface is opposite to the normal vector direction of the second curved surface, the first curved surface and the second curved surface cannot collide; and if the first curved surface and the second curved surface are coplanar, and the normal vector direction of the first curved surface is the same as that of the second curved surface, determining whether the first curved surface and the second curved surface collide with each other or not according to the geometric information of the first curved surface and the second curved surface.
Optionally, if the first curved surface and the second curved surface are coaxial cylindrical surfaces, determining whether the first curved surface and the second curved surface collide with each other includes at least one of the following: if the radiuses of the first curved surface and the second curved surface are not equal, collision between the first curved surface and the second curved surface cannot occur; if the radii of the first curved surface and the second curved surface are equal and the directions of the first curved surface and the second curved surface are opposite, collision cannot occur between the first curved surface and the second curved surface; and if the radius of the first curved surface is equal to that of the second curved surface and the direction of the first curved surface is the same as that of the second curved surface, determining whether the first curved surface and the second curved surface collide with each other or not according to the geometric information of the first curved surface and the second curved surface.
Optionally, if the first curved surface and the second curved surface are concentric spherical surfaces, determining whether a collision occurs between the first curved surface and the second curved surface includes at least one of: if the radiuses of the first curved surface and the second curved surface are not equal, the first curved surface and the second curved surface cannot collide with each other; if the radii of the first curved surface and the second curved surface are equal and the directions of the first curved surface and the second curved surface are opposite, the first curved surface and the second curved surface cannot collide; and if the radius of the first curved surface is equal to that of the second curved surface, and the direction of the first curved surface is the same as that of the second curved surface, determining whether the first curved surface and the second curved surface collide with each other or not.
According to another aspect of the present invention, there is provided a collision detection apparatus including: the judging module is used for judging whether the first curved surface and the second curved surface collide with each other or not according to the geometric information of the first curved surface and the second curved surface to be detected; and the determining module is used for determining that the first group of triangular plates corresponding to the first curved surface and the second group of triangular plates corresponding to the second curved surface do not collide under the condition that the judging module judges that the first curved surface and the second curved surface do not collide.
Optionally, the apparatus further comprises: and the first detection module is used for detecting whether the triangular plate and the second curved surface collide or not according to the vertex position information of the triangular plate and the geometric information of the second curved surface for each triangular plate in the first set of triangular plates when the judgment module cannot judge whether the first curved surface collides with the second curved surface according to the geometric information of the first curved surface and the second curved surface, and if not, determining that the triangular plate and all the triangular plates in the second set of triangular plates cannot collide.
Optionally, the apparatus further comprises: and the second detection module is used for detecting whether the triangular plate in the first group of triangular plates collides with each triangular plate in the second group of triangular plates or not according to the vertex position information of the triangular plate and the vertex position information of each triangular plate in the second group of triangular plates under the condition that the first detection module cannot judge whether the triangular plate collides with the second curved surface or not according to the vertex position information of one triangular plate in the first group of triangular plates and the geometric information of the second curved surface.
According to the invention, whether the two curved surfaces collide is judged according to the geometric information of the curved surfaces, and when the two curved surfaces do not collide, the triangular plate between the two curved surfaces is judged not to collide, so that the misjudgment probability is reduced, and the detection speed is improved.
Detailed Description
The invention will be described in detail hereinafter with reference to the accompanying drawings in conjunction with embodiments. It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict.
In the embodiment of the invention, geometric information of a standard curved surface (a plane, a cylindrical surface, a spherical surface and the like) is introduced into the calculation of collision detection on the basis of the prior art, and the curved surface and the triangular plate which are inevitably not collided are directly filtered out according to the shape characteristics of the curved surface, so that the collision detection efficiency is improved on one hand, and the misjudgment condition caused by the fact that the triangular plate cannot perfectly represent the shape of the curved surface is effectively avoided on the other hand.
According to an embodiment of the present invention, there is provided a collision detection method.
Fig. 3 is a flowchart of a collision detection method according to an embodiment of the present invention, and as shown in fig. 3, the method mainly includes the following steps (step S302-step S304):
step S302, judging whether the first curved surface and the second curved surface collide with each other according to the geometric information of the first curved surface and the second curved surface to be detected.
In the embodiment of the invention, before collision detection, not only the triangular plate information of each curved surface of the model to be detected is stored, but also the geometric information of each curved surface is stored. Wherein the geometric information is used to describe the shape of the curved surface. For example, for a plane, the position of a point on the plane and the normal vector direction of the plane can be recorded; for a cylindrical surface, the central axis (a point on the axis and the direction of the axis) of the cylindrical surface and the radius of the cylindrical surface can be recorded; for the spherical surface, the position of the center of the spherical surface, the radius of the spherical surface, and the like can be recorded.
Before step S302 is executed, whether the whole bounding boxes of the two models to be detected intersect or not may be determined by using a bounding box manner, and if the intersection is determined, whether the bounding boxes of the two curved surfaces (i.e. the first curved surface and the second curved surface) of the two models intersect or not may be determined, and if so, step S302 is executed again.
In practical application, most of the matched curved surfaces of objects with the assembly position relation are standard curved surfaces such as planes, cylindrical surfaces, spherical surfaces and the like. Therefore, in the collision detection process, only a limited number of standard curved surfaces need to be judged, and the detection accuracy can be greatly improved.
Therefore, in an alternative embodiment of the present invention, the geometric information of the standard surface may be used to filter the surface in step S304. And grouping the triangular plates of the model according to the curved surface. If the two curved surfaces cannot collide with each other necessarily, the collision condition of the two curved surfaces corresponding to the triangular plates does not need to be calculated, and the two groups of triangular plates cannot collide with each other directly. This is illustrated below by means of several standard surfaces.
(a) Two parallel planes
Two parallel planes, when they are not coplanar, will not collide with each other.
When the two parallel planes are coplanar, if the directions of the two planes (i.e. the normal vector directions of the planes) are opposite, the two planes will not collide with each other.
When the two parallel planes are coplanar, if the directions of the two planes (the normal vector direction of the planes) are the same, it cannot be determined whether the two planes collide, and the determination needs to be performed through the intersection condition of the triangular plates on the two planes.
(b) Two coaxial cylindrical surfaces
When the two coaxial cylindrical curved surfaces have unequal radiuses, the two cylindrical curved surfaces cannot collide with each other;
when the two coaxial cylindrical curved surfaces have equal radiuses, if the directions of the two cylindrical curved surfaces are opposite (the normal vector of a point on one curved surface points to the central axis, and the normal vector of a point on the other curved surface is far away from the central axis), the two cylindrical curved surfaces cannot collide with each other;
when the radii of the two coaxial cylindrical curved surfaces are equal, if the directions of the two cylindrical curved surfaces are the same, whether the two curved surfaces collide with each other cannot be judged, and judgment needs to be carried out through the intersection condition of the triangular plates on the two curved surfaces.
(c) Two concentric spherical surfaces
When the two concentric spherical surfaces have unequal radiuses, the two spherical surfaces cannot collide with each other;
when the two concentric spheres have equal radii, if the two spheres have opposite directions (the normal vector of a point on one sphere points to the center of the sphere and the normal vector of a point on the other sphere is far away from the center of the sphere), the two spheres will not collide;
when the radii of the two concentric spherical surfaces are equal, if the directions of the two spherical surfaces are the same, whether the two spherical surfaces collide with each other cannot be judged, and judgment needs to be performed through the intersection condition of the triangular plates on the two spherical surfaces.
Step S304, under the condition that the first curved surface and the second curved surface are not collided, determining that the first group of triangular plates corresponding to the first curved surface and the second group of triangular plates corresponding to the second curved surface are not collided.
In the specific implementation process, when the collision detection is carried out and the triangular plates are generated by each curved surface to be detected, the triangular plates are grouped according to the curved surface where each triangular plate is located.
In an optional implementation manner of the embodiment of the present invention, if it cannot be determined whether the first curved surface and the second curved surface collide with each other according to the geometric information of the first curved surface and the second curved surface in step S304, the method may further include: and for each triangular plate in the first set of triangular plates, detecting whether the triangular plate and the second curved surface collide or not according to the vertex position information of the triangular plate and the geometric information of the second curved surface, and if not, determining that the triangular plate and all the triangular plates in the second set of triangular plates do not collide.
If one triangular plate and one curved surface can not collide with each other, the collision condition of the triangular plate and all the triangular plates on the curved surface does not need to be calculated, and the triangular plate and all the triangular plates corresponding to the curved surface are directly judged to be not collided with each other. The second curved surface is exemplified by the following typical curved surfaces.
(a) Plane surface
When the three vertices of the triangle are located on the same side of the plane, the triangle and the plane are bound not to collide.
(b) Cylindrical surface
When the distances between the three vertexes of the triangular plate and the central axis of the cylindrical surface are smaller than the radius of the cylindrical surface, the triangular plate and the cylindrical surface cannot collide with each other necessarily.
(c) Spherical surface
When the distances between the three vertexes of the triangular plate and the spherical center of the spherical surface are smaller than the radius of the spherical surface, the triangular plate and the spherical surface are not collided necessarily.
In an optional implementation manner of the embodiment of the present invention, for one of the triangular plates in the first set of triangular plates, if it cannot be determined whether the triangular plate collides with the second curved surface by detecting vertex position information of the triangular plate and geometric information of the second curved surface, the method may further include: and detecting whether the triangular plate in the first set of triangular plates collides with each triangular plate in the second set of triangular plates or not according to the vertex position information of the triangular plate in the first set of triangular plates and the vertex position information of each triangular plate in the second set of triangular plates.
The technical solution provided by the embodiment of the present invention is explained by an alternative embodiment.
Fig. 4 is a collision detection flowchart of the embodiment. As shown in fig. 4, in an alternative embodiment of the present invention, the method for detecting a collision between two models mainly includes the following steps:
step S401, whether the whole bounding boxes of the two models are intersected or not is detected. If the models are not intersected, judging that the two models are not collided; if the two curved surfaces intersect, whether the curved surfaces of the two models collide is detected, and step S402 is executed for every two curved surfaces between the two models.
Step S402, whether the bounding boxes of the two curved surfaces intersect is detected. If the two curved surfaces do not intersect, judging that the two curved surfaces do not collide; if so, continuing to the next step.
In step S403, it is determined whether the two curved surfaces intersect with each other using the geometric information of the standard curved surface. If the two curved surfaces do not intersect, judging that the two curved surfaces do not collide; if so, continuing to the next step.
And S404, filtering triangular plates by using the geometric information of the standard curved surface. Traversing all the triangular plates on the curved surface, filtering out the triangular plates which cannot collide with another curved surface necessarily, and recording the rest triangular plates.
Step S405, whether the remaining triangular plates of the two curved surfaces are intersected or not is detected. If the situation that the triangular plates are intersected exists, judging that the two models collide; otherwise, judging that the two curved surfaces do not collide.
In step S406, if all the curved surfaces do not collide, it is determined that the two models do not collide.
According to the embodiment of the invention, the invention further provides a collision detection device.
Fig. 5 is a schematic structural diagram of a collision detection apparatus according to an embodiment of the present invention, and as shown in fig. 5, the apparatus mainly includes: the judging module 50 is configured to judge whether the first curved surface and the second curved surface collide with each other according to the geometric information of the first curved surface and the second curved surface to be detected; a determining module 52, configured to determine that no collision occurs between a first set of triangular plates corresponding to the first curved surface and a second set of triangular plates corresponding to the second curved surface when the determining module 50 determines that the first curved surface and the second curved surface do not collide with each other.
In a specific implementation process, the determining module 50 may filter the curved surface that does not collide with the standard curved surface according to the geometric information of the standard curved surface, and may specifically determine according to the manner described in the foregoing embodiment, which is not described herein again.
In an optional implementation manner of the embodiment of the present invention, the apparatus may further include: and the first detection module is configured to, when the judgment module 50 cannot judge whether the first curved surface collides with the second curved surface according to the geometric information of the first curved surface and the second curved surface, detect, for each triangular plate in the first set of triangular plates, whether the triangular plate collides with the second curved surface according to vertex position information of the triangular plate and the geometric information of the second curved surface, and if not, determine that the triangular plate does not collide with all the triangular plates in the second set of triangular plates.
In a specific implementation process, the first detection module may use the geometric information filtering triangle of the standard curved surface according to the manner described in the above embodiment, which is not described herein again.
In an optional implementation manner of the embodiment of the present invention, the apparatus may further include: and the second detection module is used for detecting whether the triangular plate in the first group of triangular plates collides with each triangular plate in the second group of triangular plates or not according to the vertex position information of the triangular plate and the vertex position information of each triangular plate in the second group of triangular plates under the condition that the first detection module cannot judge whether the triangular plate collides with the second curved surface or not according to the vertex position information of one triangular plate in the first group of triangular plates and the geometric information of the second curved surface. The second detection module may detect whether a collision occurs between two triangular plates according to a triangular plate detection method in the related art, and specific details of the embodiment of the present invention are not described again.
From the above description, it can be seen that, according to the technical solution provided by one of the above embodiments, geometric information of a curved surface (e.g., a plane, a cylindrical surface, a spherical surface, etc.) is introduced into the calculation of collision detection, and according to the shape characteristics of the curved surface, the curved surface and the triangular plate which are inevitably not collided are directly filtered out, so that on one hand, the efficiency of collision detection is improved, and on the other hand, the misjudgment caused by the fact that the triangular plate cannot perfectly represent the shape of the curved surface is effectively avoided.
It will be apparent to those skilled in the art that the modules or steps of the present invention described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of multiple computing devices, and alternatively, they may be implemented by program code executable by a computing device, such that they may be stored in a storage device and executed by a computing device, and in some cases, the steps shown or described may be performed in an order different than that described herein, or they may be separately fabricated into individual integrated circuit modules, or multiple ones of them may be fabricated into a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.