CN113384890B - Convex polygon collision detection method - Google Patents

Convex polygon collision detection method Download PDF

Info

Publication number
CN113384890B
CN113384890B CN202110713798.4A CN202110713798A CN113384890B CN 113384890 B CN113384890 B CN 113384890B CN 202110713798 A CN202110713798 A CN 202110713798A CN 113384890 B CN113384890 B CN 113384890B
Authority
CN
China
Prior art keywords
convex
convex polygons
polygon
potential separation
polygons
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110713798.4A
Other languages
Chinese (zh)
Other versions
CN113384890A (en
Inventor
苏庆
黎智洲
黄剑锋
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong University of Technology
Original Assignee
Guangdong University of Technology
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangdong University of Technology filed Critical Guangdong University of Technology
Priority to CN202110713798.4A priority Critical patent/CN113384890B/en
Publication of CN113384890A publication Critical patent/CN113384890A/en
Application granted granted Critical
Publication of CN113384890B publication Critical patent/CN113384890B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F13/00Video games, i.e. games using an electronically generated display having two or more dimensions
    • A63F13/55Controlling game characters or game objects based on the game progress
    • A63F13/57Simulating properties, behaviour or motion of objects in the game world, e.g. computing tyre load in a car race game
    • AHUMAN NECESSITIES
    • A63SPORTS; GAMES; AMUSEMENTS
    • A63FCARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
    • A63F13/00Video games, i.e. games using an electronically generated display having two or more dimensions
    • A63F13/50Controlling the output signals based on the game progress
    • A63F13/52Controlling the output signals based on the game progress involving aspects of the displayed game scene

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Theoretical Computer Science (AREA)
  • Human Computer Interaction (AREA)
  • Image Analysis (AREA)

Abstract

The invention discloses a method for detecting convex polygon collision, which comprises the following steps: calculating to obtain support points and potential separation axis sets of the two convex polygons according to the obtained centroid coordinate data of the two convex polygons and the relation between the polygon side normal and the centroid connecting line vector, calculating the support points and the potential separation axis sets of the convex polygons by using a hill climbing method to obtain projection overlapping lengths of the two convex polygons, comparing the size relation of the projection overlapping lengths to obtain a minimum moving distance, and determining whether the two convex polygons collide according to whether the value of the minimum moving distance is a positive value. According to the method for detecting the collision of the convex polygon, the collision of the convex polygon is quickly and accurately detected.

Description

Convex polygon collision detection method
Technical Field
The invention relates to the field of convex polygon collision detection, in particular to a convex polygon collision detection method.
Background
In the field of electronic games, in order to achieve sufficient reality and fit the logic of the real world, it is a very common requirement to correctly express the effect that two objects are in mutual contact or collision, and a player can be provided with a game experience closer to reality. In a game scene generated by computer software, objects are usually represented by abstract geometric models (such as vertex arrays or implicit functions), and these geometric models do not have physical attributes of the real world, so that when the objects move towards each other, the objects may penetrate each other due to the absence of "collision" behavior occurring in the real world, and the objects may not conform to the real world scene. Therefore, to simulate the real-world object collision situation in a computer, it is important to study the collision detection of objects (these objects are often abstracted to convex polygons) in a game scene.
In a game scenario where object movement occurs, since the object movement position is constantly changing, the collision detection algorithm needs to be run in each frame of the program to perform real-time detection, obtaining accurate and as true a result as possible. Therefore, the collision detection algorithm in the game scene has requirements on real-time performance and accuracy, and the time consumed for executing the collision detection algorithm in each frame has an important influence on the overall operation performance of the program, that is, the performance of the collision detection algorithm greatly influences the execution performance of the entire program.
At present, the solution of the collision detection problem in game development can be divided into two categories, image-based space and graphic-based space, according to space. The image space-based algorithm depends on hardware support, and the result accuracy depends on the resolution and sampling frequency of the image, so the development is slow. Algorithms based on the graphic space can be further divided into algorithms based on scene space subdivision, algorithms based on bounding volume trees and algorithms based on model topological structures. The collision detection algorithm based on scene space subdivision and on bounding volume trees reduces accuracy for performance and is difficult to meet requirements in game scenes requiring accurate detection. In the algorithm based on the model topological structure, the GJK algorithm can generate infinite circulation due to a certain special shape of an object under certain specific scenes, and can not reach a termination condition; however, the LC algorithm is not ideal for processing translational and rotary objects with variable speed, and has a certain probability of missing detection. The algorithm complexity of the conventional SAT algorithm is O (n) 2 ) The detection performance of the detection device is obviously reduced along with the increase of the number of the convex polygon edges.
Therefore, in order to rapidly and accurately perform collision detection on the convex polygon, and solve the technical problem that a large amount of computing resources are required to be consumed in the global collision detection on a plurality of dynamic objects in the game at present, a method for detecting the convex polygon collision needs to be constructed.
Disclosure of Invention
The invention provides a convex polygon collision detection method, which solves the technical problem that a large amount of computing resources are consumed in the process of carrying out global collision detection on a plurality of dynamic objects in a game at present.
In a first aspect, the present invention provides a method for detecting a convex polygon collision, including:
calculating to obtain support points and potential separation axis sets of the two convex polygons according to the obtained centroid coordinate data of the two convex polygons and the relation between the polygon edge normal and the centroid connecting line vector;
calculating the support points and the potential separation axis set of the convex polygons by using a hill climbing method to obtain the projection overlapping length of the two convex polygons;
comparing the size relationship of the projection overlapping lengths to obtain a minimum moving distance;
and determining whether the two convex polygons collide according to whether the numerical value of the minimum moving distance is a positive value.
Optionally, the calculating, according to the obtained centroid coordinate data of the two convex polygons and the relationship between the polygon edge normal and the centroid connecting line vector, a set of support points and potential separation axes of the two convex polygons is obtained, including:
based on the obtained centroid coordinate data of the two convex polygons, calculating to obtain a collision-capable vertex sequence of the two convex polygons by combining the relation between the polygon edge normal line and the centroid connecting line vector;
and traversing the sequence of the collidable vertexes to obtain the support points and the set of potential separation axes of the two convex polygons.
Optionally, based on the obtained centroid coordinate data of the two convex polygons, and in combination with a relationship between a polygon edge normal and a centroid connecting line vector, calculating a sequence of collision-able vertices of the two convex polygons, including:
calculating to obtain a centroid connecting line vector between the centroids of the two convex polygons according to the acquired centroid coordinate data of the two convex polygons;
and calculating by combining the relation between the polygon side normal and the centroid connecting line vector based on the centroid connecting line vector to obtain a collision vertex sequence of the two convex polygons.
Optionally, traversing the sequence of collidable vertices to obtain a set of support points and potential separation axes of the two convex polygons, including:
traversing the sequence of the collidable vertexes, and calculating Euclidean distances between all vertexes of the sequence of the collidable vertexes in the two convex polygons and the centroid of the other convex polygon to obtain two Euclidean distance combinations;
and respectively selecting a vertex with the minimum distance from the two Euclidean distance combinations as a support point of a convex polygon to which a collision-capable vertex of the Euclidean distance belongs, determining the normal lines of two adjacent edges of the support point as potential separation axes, and forming the potential separation axes into a potential separation axis set.
Optionally, calculating the support points and the potential separation axis set of the convex polygons by using a hill climbing method to obtain the projection overlap length of the two convex polygons, including:
calculating to obtain the upper limit of a projection overlapping interval of any one convex polygon on the latent separating axis based on the support points of the convex polygons and the latent separating axis set;
calculating the support points of the convex polygon and the potential separation axis set by using a hill climbing algorithm to obtain the lower limit of the projection overlapping interval of another polygon on the potential separation axis;
and calculating the projection overlap length of the two convex polygons based on the upper limit of the projection overlap interval of any one convex polygon on the belonged potential separation axis and the lower limit of the projection overlap interval of the other polygon on the belonged potential separation axis.
Optionally, determining whether the two convex polygons collide according to whether the value of the minimum moving distance is a positive value, includes:
judging whether the numerical value of the minimum moving distance is larger than 0;
if so, determining that the two convex polygons collide, and determining the potential separation axis to which the minimum moving distance belongs as a collision normal;
if not, determining that the two convex polygons do not collide.
In a second aspect, the present invention provides a convex polygon collision detection apparatus, comprising:
the calculation module is used for calculating and obtaining support points and potential separation axis sets of the two convex polygons according to the obtained centroid coordinate data of the two convex polygons and the relation between the polygon edge normal and the centroid connecting line vector;
the length module is used for calculating the support points and the potential separation axis set of the convex polygons by using a hill climbing method to obtain the projection overlapping length of the two convex polygons;
the minimum module is used for comparing the size relationship of the projection overlapping lengths to obtain the minimum moving distance;
and the determining module is used for determining whether the two convex polygons collide according to whether the numerical value of the minimum moving distance is a positive value.
Optionally, the calculation module comprises:
the sequence submodule is used for calculating to obtain a collision vertex sequence of the two convex polygons by combining the relation between the polygon side normal and the centroid connecting line vector based on the acquired centroid coordinate data of the two convex polygons;
and the traversal submodule is used for traversing the sequence of the collidable vertexes to obtain the support points and the potential separation axis set of the two convex polygons.
Optionally, the sequence submodule includes:
the phasor unit is used for calculating a centroid connecting line vector between the centroids of the two convex polygons according to the acquired centroid coordinate data of the two convex polygons;
and the sequence unit is used for calculating by combining the relation between the polygon edge normal and the centroid connecting line vector based on the centroid connecting line vector to obtain a collision vertex sequence of the two convex polygons.
Optionally, the traversal submodule includes:
the distance unit is used for traversing the sequence of the collidable vertexes, and calculating Euclidean distances between all vertexes of the sequence of the collidable vertexes in the two convex polygons and the centroid of the other convex polygon to obtain two Euclidean distance combinations;
and the selecting unit is used for selecting a vertex with the minimum distance from the two Euclidean distance combinations as a support point of a convex polygon to which a collision-capable vertex of the Euclidean distance belongs, determining the normals of two adjacent edges of the support point as potential separation axes, and forming the potential separation axes into a potential separation axis set.
Optionally, the length module comprises:
the upper limit submodule is used for calculating and obtaining the upper limit of a projection overlapping interval of any one convex polygon on the latent separating axis based on the support point of the convex polygon and the latent separating axis set;
the lower limit submodule is used for calculating the support points and the potential separation axis set of the convex polygon by utilizing a hill climbing algorithm to obtain the lower limit of a projection overlapping interval of another polygon on the potential separation axis;
and the length submodule is used for calculating the projection overlapping length of the two convex polygons based on the upper limit of the projection overlapping interval of any convex polygon on the belonged potential separation axis and the lower limit of the projection overlapping interval of the other polygon on the belonged potential separation axis.
Optionally, the determining module includes:
the judgment submodule is used for judging whether the numerical value of the minimum moving distance is larger than 0; if yes, executing a first determining submodule; if not, executing a second determining submodule;
a first determining submodule, configured to determine that the two convex polygons collide, and determine the potential separation axis as a collision normal;
a second determination submodule for determining that the two convex polygons have not collided.
According to the technical scheme, the invention has the following advantages: the invention provides a convex polygon collision detection method, which comprises the steps of obtaining support points and potential separation axis sets of two convex polygons by calculation according to obtained centroid coordinate data of the two convex polygons and the relation between a polygon edge normal line and a centroid connecting line vector, calculating the support points and the potential separation axis sets of the two convex polygons by using a hill climbing method to obtain projection overlapping lengths of the two convex polygons, comparing the size relation of the projection overlapping lengths to obtain a minimum moving distance, determining whether the two convex polygons collide according to the fact that the value of the minimum moving distance is a positive value, determining the support points and the potential separation axis according to the point multiplication relation between the normal line of the edge of the convex polygons and the centroid connecting line vector and the Euclidean distance between the points, finally using the same side property and monotonicity of the convex polygons to carry out projection simplification by using the support points, thereby reducing the calculation amount required by collision detection, improving the performance of an algorithm, and solving the technical problems that a large amount of collision calculation is required when a plurality of dynamic objects are detected in a global state in a game, and the collision is detected accurately.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without inventive exercise.
FIG. 1 is a flowchart illustrating a first embodiment of a method for detecting a convex polygon collision according to the present invention;
FIG. 2 is a flowchart illustrating a second embodiment of a method for detecting a convex polygon collision according to the present invention;
FIG. 3 is a schematic diagram of computing a sequence of collidable vertices in the method for detecting convex polygon collision of the present invention;
FIG. 4 is a schematic diagram of calculating a potential separation axis in the convex polygon collision detection method according to the present invention
FIG. 5 is a flowchart illustrating a normal filtering method of a convex polygon collision detection method according to the present invention;
FIG. 6 is a flowchart illustrating steps of selecting a projection method in the convex polygon collision detection method according to the present invention;
fig. 7 is a block diagram of an embodiment of a convex polygon collision detection apparatus according to the present invention.
Detailed Description
The embodiment of the invention provides a convex polygon collision detection method, which is used for solving the technical problem that a large amount of computing resources are required to be consumed when global collision detection is carried out on a plurality of dynamic objects in a game at present.
In order to make the objects, features and advantages of the present invention more obvious and understandable, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is obvious that the embodiments described below are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In a first embodiment, referring to fig. 1, fig. 1 is a flowchart illustrating a first flow step of a method for detecting a convex polygon collision according to a first embodiment of the present invention, including:
step S101, calculating support points and potential separation axis sets of the two convex polygons according to the obtained centroid coordinate data of the two convex polygons and the relation between the polygon edge normal and the centroid connecting line vector;
step S102, calculating support points and a potential separation axis set of the convex polygons by using a hill climbing method to obtain projection overlapping lengths of the two convex polygons;
step S103, comparing the size relationship of the projection overlapping lengths to obtain a minimum moving distance;
and step S104, determining whether the two convex polygons collide according to whether the numerical value of the minimum moving distance is a positive value.
According to the method for detecting the collision of the convex polygon, provided by the embodiment of the invention, the support points and the potential separation axis sets of the two convex polygons are obtained through calculation according to the obtained centroid coordinate data of the two convex polygons and the relation between the polygon side normal line and the centroid connecting line vector, the support points and the potential separation axis sets of the two convex polygons are calculated by using a hill climbing method, the projection overlapping lengths of the two convex polygons are obtained, the minimum moving distance is obtained by comparing the size relation of the projection overlapping lengths, whether the two convex polygons collide is determined according to the fact that the numerical value of the minimum moving distance is a positive value, the support points and the potential separation axis are determined according to the point multiplication relation between the normal line of the side of the convex polygon and the centroid connecting line vector and the Euclidean distance between the points, finally, the support points and the potential separation axis are simplified through projection by using the support points by using the homonymy and monotony of the convex polygons, the calculation amount of the collision is reduced, the algorithm performance is improved, and the problem that a large amount of resources are required for detecting the global collision in games due to a plurality of dynamic objects in the existing games is solved, and the problem that the collision is rapidly detected by using the supporting points and the technology.
In a second embodiment, referring to fig. 2, fig. 2 is a flowchart illustrating a method for detecting a convex polygon collision according to the present invention, including:
step S201, based on the obtained centroid coordinate data of the two convex polygons, and by combining the relation between the polygon side normal and the centroid connecting line vector, calculating to obtain a collision-capable vertex sequence of the two convex polygons;
it should be noted that the vertex order of the convex polygon is clockwise, and the normal lines point to the left side of the edge vector direction
In the embodiment of the invention, the centroid coordinate data of two convex polygons are obtained, and then the sequence of the collision-capable vertexes of the two convex polygons is obtained through calculation according to the centroid coordinate data and the relation between the polygon edge normal and the centroid connecting line vector.
In particular implementations, the structure of a convex polygon is typically stored using an array of vertices during game development, thus for polygon C i The centroid calculation formula can be expressed as:
Figure BDA0003133982920000071
wherein v is k Is the vertex in the convex polygon, | C i I is the number of vertices in, and thus the geometric meaning of the centroid is the average of all vertices in the polygon.
It should be noted that in most cases, the convex polygon does not undergo structural change during the game operationSince the centroid is converted (i.e., regarded as a rigid body), the relative position of the centroid does not change, and the centroid is not affected by the polygon rotation, and therefore, the centroid can be calculated only once. During the collision check, two detected polygons C need to be obtained i And C j The centroids of (1) are respectively marked as m i And m j
Referring to FIG. 3, FIG. 3 is a schematic diagram of computing a sequence of collision-enabled vertices in the method for detecting convex polygon collision according to the present invention, wherein a, b, C, d, e, and f are all vertices, and C i And C j Are all polygonal;
during collision detection, it is necessary to determine which vertices of the two convex polygons are likely to collide. All vertices that may collide constitute a sequence of collision-able vertices. Depending on the nature of the convex polygon, the separation axis will fall only on the sides where the two convex polygons are close to each other, and therefore only the normals of the sides where the vertex sequences can collide will be referred to as separation axes. Therefore, at this stage, by determining the sequence of collidable vertices, the normals that are not likely to become the separating axes can be eliminated, so as to reduce the number of normals that need to be subjected to projection test, and improve the efficiency of collision detection.
Taking any convex polygon in the convex polygon sum (without loss of generality, can assume C i ) The centroid link vector corresponding thereto is calculated using the following formula:
Figure BDA0003133982920000081
wherein m is i Is represented by C i Centroid, m j Is represented by C j The centroid, the vector connecting the centroids
Figure BDA0003133982920000082
Represents a slave m i Point direction m j The vector of (2).
For C in i Normal to each side
Figure BDA0003133982920000083
Computing normals
Figure BDA0003133982920000084
And
Figure BDA0003133982920000085
if the dot product result of (2) is less than or equal to 0, it indicates that
Figure BDA0003133982920000086
And
Figure BDA0003133982920000087
different directions; if the dot product result is greater than 0, it indicates that
Figure BDA0003133982920000088
And
Figure BDA0003133982920000089
substantially in the same direction, i.e.
Figure BDA00031339829200000810
The edge is not back to C to a certain extent j . At this moment, the
Figure BDA00031339829200000811
Two end points of the edge are added into C i Can collide vertex sequence S i In (1). Repeating the operation until the normal is detected completely to obtain a sequence S of collision-capable vertexes i . As shown in FIG. 5, the dot product of the normal lines of the sides (a, b), (b, c), (g, a) is greater than 0, so that the dots g, a, b, c constitute S i
For another polygon C j The same operation as above is performed to obtain C j Can collide vertex sequence S j
Step S202, traversing the sequence of the collision-capable vertexes to obtain support points and a potential separation axis set of the two convex polygons;
in the embodiment of the invention, the sequence of the collidable vertices of any convex polygon is traversed, and the support points and the potential separation axis set of two convex polygons are obtained through calculation.
In the implementation, please refer to fig. 4, fig. 4 is a schematic diagram illustrating a method for calculating a potential separation axis in a convex polygon collision detection method according to the present invention, wherein a, b, and C are all vertices, C i And C j Are all polygonal.
Resulting sequence of collisionable vertices S i Then, C needs to be further determined i Support point support of i Then obtain C i Potential separation axis assembly PSA i . Comparing all vertices in Si with another convex polygon centroid m j The Euclidean distance of (c) is taken as the vertex v with the minimum distance min Let v be min To be C i Support point support of i Cause of support i Is C i Middle and closest to C j Of the vertex, therefore in support i The normals of two adjacent sides which are common end points are the normals which are most likely to be separating axes, and the two normals form a potential separating axis set PSA i
First, for vertex v k ∈S i The distance is calculated by:
d k =||m i -v k ||
wherein represents d k Middle S i Vertex v of k To m j The distance of (c). For its minimum distance d min Its corresponding vertex v min Into a convex polygon C i Support points of (1), support i . At the same time, take support i Normal lines of adjacent sides at both sides, become C i Potential separation axis assembly PSA i . As shown in FIG. 6, vertex b is compared to the remaining points in the sequence of collidable vertices, and C j The centroid has the smallest euclidean distance and hence the vertex b becomes the support point, then the normals to the edges (a, b), (b, c) are the desired potential separation axes, i.e. the normals to (a, b) and (b, c) form the set of potential separation axes PSA i
The same for another convex polygon C j Executing the operation to obtain the corresponding support point support i And potential separation shaft pair PSA j
Step S203, calculating and obtaining the upper limit of the projection overlapping interval of any one convex polygon on the belonged potential separation axis based on the support points of the convex polygons and the potential separation axis set;
in the embodiment of the invention, the upper limit of the projection overlap interval of any convex polygon on the potential separation axis is calculated according to the support point of any convex polygon and the potential separation axis of the polygon.
In a particular implementation, the convex polygon C is based on the homonymy of the convex polygon i In that
Figure BDA0003133982920000091
Maximum of projection on
Figure BDA0003133982920000092
The dot product of the two end points of the edge is the value. However, because of
Figure BDA0003133982920000093
Is a potential axis of separation, therefore C i Support point support i Must be
Figure BDA0003133982920000094
One end of the edge. Therefore, for
Figure BDA0003133982920000095
Comprises the following steps:
Figure BDA0003133982920000096
step S204, calculating the support points of the convex polygon and the potential separation axis set by using a hill climbing algorithm to obtain the lower limit of the projection overlapping interval of another polygon on the corresponding potential separation axis;
in the embodiment of the invention, according to the support points and the potential separation axis of the convex polygon, a hill climbing algorithm is used for calculation to obtain the lower limit of the projection overlapping interval of another polygon on the potential separation axis.
In a specific implementation, for another convex polygon C j Due to its presence in
Figure BDA0003133982920000097
Vertex mpv with minimum projection on j Must collide with the vertex sequence S j Meanwhile, since the convex polygons are all monotone convex polygons, the vertex is at
Figure BDA0003133982920000098
The above local minimum is a global minimum, and by using this property, mpv can be obtained by using a hill-climbing method j
Due to support j Is a convex polygon of C j Nearest C i Vertex, hence support j Most likely mpv j Therefore, choose support j As the starting vertex of the hill climbing method. First, compute support j And
Figure BDA0003133982920000101
as an initial value of the hill climbing method:
Figure BDA0003133982920000102
then, from support j Initially, the vertices advance to both sides (clockwise and counterclockwise) of the convex polygon. Let V cw Is a sequence of vertices in a certain direction (cw is clockwise or counterclockwise). For the current vertex, its projection value is calculated:
Figure BDA0003133982920000103
comparing the current projection value with the previous vertex projection value, if:
d-d 0 ≥0
then it means that the projected value of v at p is not less than the previous vertex at
Figure BDA0003133982920000104
The projected value of (d) is updated at this time 0 D and continues to traverse in the current direction.
Otherwise, v is represented in
Figure BDA0003133982920000105
The last vertex of which the projection value is less than v is
Figure BDA0003133982920000106
The projection value of (2), at which point mpv is set j V is the minimum point mpv of the projection to be found j While stopping traversing in that direction.
Finally, since C is obtained j In
Figure BDA0003133982920000107
Projected minimum point mpv on j Thus obtaining
Figure BDA0003133982920000108
The values of (A) are:
Figure BDA0003133982920000109
step S205, calculating the projection overlap length of the two convex polygons based on the upper limit of the projection overlap interval of the arbitrary convex polygon on the belonged potential separation axis and the lower limit of the projection overlap interval of the other polygon on the belonged potential separation axis;
in the embodiment of the invention, the projection overlapping length of the two convex polygons is calculated according to the upper limit of the projection overlapping interval and the lower limit of the projection overlapping interval.
In a specific implementation, the maximum value of the projection overlap interval is subtracted from the minimum value of the projection overlap interval to obtain the value of the projection overlap interval on the potential separation axis
Figure BDA00031339829200001010
Projection overlap length overlap:
Figure BDA00031339829200001011
for convex polygon C i Only need to C i Support point support of i Projecting to obtain the upper limit of the projection overlapping interval; for convex polygon C j In the most ideal case, it supports point support j I.e. mpv j At this time, only the support is needed i And support j The lower limit of the projection overlap interval can be obtained by projecting the vertexes at two sides (because the support needs to be determined) j Whether it is mpv or not j And one projection size comparison with two sides is needed). At this time, the integration is performed only 4 times of dot product operation.
In the worst case, support j And mpv j Are respectively located at C j Both ends of (2) then need to be supported from support j Begin to go to both sides to find mpv j . At this moment, completely traverse C j All vertices of (1) are accumulated to make | C j I times the dot product operation. However, this is extremely unlikely to happen because support is defined according to the convex polygon support points j Sequence S of vertices falling in collision j Middle, i.e. support j Must be located facing C i In the vertex of (a). According to mpv j Is also necessarily located in the Ci-facing vertex, and is therefore support j And mpv j Must be located on the same side, and may even be the same vertex
Step S206, comparing the size relationship of the projection overlapping length to obtain the minimum moving distance;
in the embodiment of the present invention, the minimum value is selected from the projection overlap lengths of the two convex polygons as the minimum movement distance.
In a specific implementation, the projection overlap length set O is calculated according to steps S203, S204, and S205, and the minimum value is selected from the projection overlap length set O to obtain the minimum movement distance.
Step S207, judging whether the numerical value of the minimum moving distance is larger than 0; if so, determining that the two convex polygons collide, and determining the potential separation axis to which the minimum moving distance belongs as a collision normal; if not, determining that the two convex polygons do not collide;
in the embodiment of the present invention, when the value of the minimum moving distance is greater than 0, it is determined that the two convex polygons collide, and the potential separation axis is determined as a collision normal; and when the value of the minimum moving distance is less than or equal to 0, determining that the two convex polygons do not collide.
In a specific implementation, the projection overlap length set O is traversed, and the minimum value O is taken min As the minimum moving distance, if O min If the number of the convex polygons is less than or equal to 0, the convex polygons can be immediately deduced and no collision occurs; and if O min >0, then represents a collision with the engine, and O min To separate C i And C j Minimum distance required MTD for O to be obtained min Normal line
Figure BDA0003133982920000111
Become separable C i And C j The collision normal of (1).
According to the method for detecting the collision of the convex polygons, provided by the embodiment of the invention, the support points and the potential separation axis sets of the two convex polygons are obtained through calculation according to the obtained centroid coordinate data of the two convex polygons and the relation between the polygon side normal and the centroid connecting line vector, the support points and the potential separation axis sets of the two convex polygons are obtained through calculation by a hill climbing method, the projection overlapping lengths of the two convex polygons are obtained, the minimum moving distance is obtained through comparison of the size relation of the projection overlapping lengths, whether the two convex polygons collide is determined according to the fact that the numerical value of the minimum moving distance is a positive value, the support points and the potential separation axis are determined according to the point multiplication relation between the normal of the sides of the convex polygons and the centroid connecting line vector and the Euclidean distance between the points, finally, the support points are used for projection simplification by using the support points, the calculation amount required by collision detection is reduced, the algorithm performance is improved, and the problem that a great amount of collision is required by global collision detection technology when a plurality of dynamic objects in a game is used for detecting the collision is solved.
Referring to fig. 5, fig. 5 is a flowchart illustrating a normal filtering method in the convex polygon collision detection method according to the present invention, including:
step S501, according to the obtained centroid coordinate data of the two convex polygons, a centroid connecting line vector between the centroids of the two convex polygons is obtained through calculation;
step S502, based on the centroid connecting line vector, calculating by combining the relation between the polygon edge normal and the centroid connecting line vector to obtain a collision-capable vertex sequence of the two convex polygons;
step S503, traversing the sequence of the collidable vertexes, and calculating Euclidean distances between all vertexes of the sequence of the collidable vertexes of the two convex polygons and the centroid of the other convex polygon to obtain a combination of the two Euclidean distances;
step S504, respectively selecting a vertex with the smallest distance from the two combinations of euclidean distances as a support point of the convex polygon to which the collision-capable vertex of the euclidean distance belongs, determining normals of two adjacent edges of the support point as potential separation axes, and forming the potential separation axes into a potential separation axis set.
In the normal filtering method in the convex polygon collision detection method provided by the embodiment of the invention, the collision-capable vertex subsequence of the convex polygon is found out through the connecting line vector between the centroids of the two convex polygons, then in the collision-capable vertex subsequence, a vertex with the minimum distance is screened out according to the Euclidean distance between points, the vertex is made to be a support point, and finally, the normals of two adjacent sides taking the support point as a common endpoint are determined to be potential separation axes.
Referring to fig. 6, fig. 6 is a flowchart illustrating a normal filtering method for selecting a projection method in a convex polygon collision detection method according to the present invention, including:
step S601, calculating and obtaining the upper limit of a projection overlapping interval of any convex polygon on the belonged potential separation axis based on the support points of the convex polygons and the potential separation axis set;
step S602, calculating the support points of the convex polygon and the potential separation axis set by using a hill climbing algorithm to obtain the lower limit of the projection overlapping interval of another polygon on the corresponding potential separation axis;
step S603, calculating the projection overlap length of the two convex polygons based on the upper limit of the projection overlap interval of the arbitrary convex polygon on the belonging potential separation axis and the lower limit of the projection overlap interval of the other polygon on the belonging potential separation axis.
In the normal filtering method in the method for detecting collision of a convex polygon provided by the embodiment of the invention, the maximum value of the projection of the convex polygon on the potential separation axis is quickly obtained by utilizing the property that the projection values of the two end points of the side on the side normal are the maximum value of the projection of the convex polygon on the side normal, then the vertex with the minimum projection value on the potential separation axis is quickly obtained by using the property of a monotone convex polygon by using a hill climbing method and is recorded as the minimum projection point, and the minimum projection value is obtained at the same time, and finally the minimum projection value is subtracted from the maximum projection value to obtain the projection overlap length.
Referring to fig. 7, fig. 7 is a block diagram of a convex polygon collision detection apparatus according to an embodiment of the present invention, including:
a calculating module 701, configured to calculate support points and a potential separation axis set of the two convex polygons according to the obtained centroid coordinate data of the two convex polygons and a relationship between a polygon edge normal and a centroid connecting line vector;
a length module 702, configured to calculate support points and a potential separation axis set of the convex polygons by using a hill climbing method, to obtain projection overlap lengths of the two convex polygons;
a minimum module 703, configured to compare the size relationship of the projection overlap lengths to obtain a minimum moving distance;
a determining module 704, configured to determine whether the two convex polygons collide according to whether the value of the minimum moving distance is a positive value.
In one possible embodiment, the calculation module 701 includes:
the sequence submodule is used for calculating to obtain a collision vertex sequence of the two convex polygons by combining the relation between the polygon side normal and the centroid connecting line vector based on the acquired centroid coordinate data of the two convex polygons;
and the traversal submodule is used for traversing the sequence of the collidable vertexes to obtain the support points and the potential separation axis set of the two convex polygons.
In one embodiment, the sequence submodule includes:
the phasor unit is used for calculating and obtaining a centroid connecting line vector between the centroids of the two convex polygons according to the acquired centroid coordinate data of the two convex polygons;
and the sequence unit is used for calculating by combining the relation between the polygon edge normal and the centroid connecting line vector based on the centroid connecting line vector to obtain a collision vertex sequence of the two convex polygons.
In one embodiment, the traversal submodule includes:
the distance unit is used for traversing the sequence of the collidable vertexes, and calculating Euclidean distances between all vertexes of the sequence of the collidable vertexes in the two convex polygons and the centroid of the other convex polygon to obtain two Euclidean distance combinations;
and the selecting unit is used for selecting a vertex with the minimum distance from the two Euclidean distance combinations as a supporting point of a convex polygon to which a collision-capable vertex of the Euclidean distance belongs, determining the normal lines of two adjacent edges of the supporting point as potential separation axes, and forming the potential separation axes into a potential separation axis set.
In one possible embodiment, the length module 702 includes:
the upper limit submodule is used for calculating and obtaining the upper limit of a projection overlapping interval of any one convex polygon on the belonged potential separation axis based on the support point of the convex polygon and the potential separation axis set;
the lower limit submodule is used for calculating the support points and the potential separation axis set of the convex polygon by utilizing a hill climbing algorithm to obtain the lower limit of a projection overlapping interval of another polygon on the potential separation axis;
and the length submodule is used for calculating the projection overlapping length of the two convex polygons based on the upper limit of the projection overlapping interval of any convex polygon on the belonged potential separation axis and the lower limit of the projection overlapping interval of the other polygon on the belonged potential separation axis.
In one possible embodiment, the determining module 704 includes:
the judgment submodule is used for judging whether the numerical value of the minimum moving distance is larger than 0; if yes, executing a first determining submodule; if not, executing a second determining submodule;
a first determining submodule, configured to determine that the two convex polygons collide, and determine the potential separation axis as a collision normal;
a second determination submodule for determining that the two convex polygons have not collided.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the embodiments provided in the present application, it should be understood that the method disclosed in the present invention may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a readable storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned readable storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (5)

1. A method for detecting convex polygon collision is characterized by comprising the following steps:
calculating to obtain support points and potential separation axis sets of the two convex polygons according to the obtained centroid coordinate data of the two convex polygons and the relation between the polygon edge normal and the centroid connecting line vector; the centroid connecting line vector is a vector between the centroids of the two convex polygons;
calculating the support points and the potential separation axis set of the convex polygons by using a hill climbing method to obtain the projection overlapping length of the two convex polygons; the support points are the vertexes with the shortest Euclidean distance between the centroids of the two convex polygons;
comparing the size relationship of the projection overlapping lengths to obtain a minimum moving distance;
determining whether the two convex polygons collide according to whether the numerical value of the minimum moving distance is a positive value;
calculating the support points and the potential separation axis set of the convex polygons by using a hill climbing method to obtain the projection overlapping length of the two convex polygons, wherein the method comprises the following steps:
calculating to obtain the upper limit of a projection overlapping interval of any one convex polygon on the latent separating axis based on the support points of the convex polygons and the latent separating axis set;
calculating the support points of the convex polygon and the potential separation axis set by using a hill climbing algorithm to obtain the lower limit of the projection overlapping interval of another polygon on the potential separation axis;
and calculating the projection overlap length of the two convex polygons based on the upper limit of the projection overlap interval of any one convex polygon on the belonged potential separation axis and the lower limit of the projection overlap interval of the other polygon on the belonged potential separation axis.
2. The convex polygon collision detection method according to claim 1, wherein a set of support points and potential separation axes of two convex polygons is obtained through calculation according to the obtained centroid coordinate data of the two convex polygons and the relation between a polygon edge normal line and a centroid connecting line vector, and the method comprises the following steps:
calculating to obtain a sequence of collision-capable vertexes of the two convex polygons by combining the relation between the polygon side normal and the centroid connecting line vector based on the obtained centroid coordinate data of the two convex polygons;
and traversing the sequence of the collidable vertexes to obtain the support points and the set of potential separation axes of the two convex polygons.
3. The method for detecting collision of convex polygons according to claim 2, wherein calculating a sequence of collision-able vertices of two convex polygons based on the obtained centroid coordinate data of the two convex polygons and the relationship between a polygon edge normal and a centroid connecting line vector comprises:
calculating to obtain a centroid connecting line vector between the centroids of the two convex polygons according to the acquired centroid coordinate data of the two convex polygons;
and calculating by combining the relation between the polygon edge normal and the centroid connecting line vector based on the centroid connecting line vector to obtain a collision vertex sequence of the two convex polygons.
4. The method for detecting convex polygon collisions according to claim 2, wherein traversing the sequence of collidable vertices to obtain a set of support points and potential separation axes for the two convex polygons comprises:
traversing the sequence of the collidable vertexes, and calculating Euclidean distances between all vertexes of the sequence of the collidable vertexes in the two convex polygons and the centroid of the other convex polygon to obtain two Euclidean distance combinations;
and respectively selecting a vertex with the minimum distance from the two Euclidean distance combinations as a support point of a convex polygon to which a collision-capable vertex of the Euclidean distance belongs, determining the normal lines of two adjacent edges of the support point as potential separation axes, and forming the potential separation axes into a potential separation axis set.
5. The method for detecting collision of convex polygons according to any one of claims 1-4, wherein determining whether the two convex polygons collide based on whether the value of the minimum moving distance is a positive value comprises:
judging whether the numerical value of the minimum moving distance is larger than 0;
if so, determining that the two convex polygons collide, and determining the potential separation axis to which the minimum moving distance belongs as a collision normal;
if not, determining that the two convex polygons do not collide.
CN202110713798.4A 2021-06-25 2021-06-25 Convex polygon collision detection method Active CN113384890B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110713798.4A CN113384890B (en) 2021-06-25 2021-06-25 Convex polygon collision detection method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110713798.4A CN113384890B (en) 2021-06-25 2021-06-25 Convex polygon collision detection method

Publications (2)

Publication Number Publication Date
CN113384890A CN113384890A (en) 2021-09-14
CN113384890B true CN113384890B (en) 2023-03-14

Family

ID=77624146

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110713798.4A Active CN113384890B (en) 2021-06-25 2021-06-25 Convex polygon collision detection method

Country Status (1)

Country Link
CN (1) CN113384890B (en)

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
"The Research of Collision Detection Algorithm Based on Separating axis Theorem";Cheng Liang et al.;《International Journal of Science》;20151231;第110-114页 *

Also Published As

Publication number Publication date
CN113384890A (en) 2021-09-14

Similar Documents

Publication Publication Date Title
US11301954B2 (en) Method for detecting collision between cylindrical collider and convex body in real-time virtual scenario, terminal, and storage medium
CN112771573B (en) Depth estimation method and device based on speckle images and face recognition system
CN101231761B (en) Graticule model simplification method for keeping external appearance characteristic
US20200410688A1 (en) Image Segmentation Method, Image Segmentation Apparatus, Image Segmentation Device
CN111598986B (en) Virtual fluid surface rendering method, device, equipment and storage medium
EP2817783A1 (en) Method and apparatus for mesh simplification
KR20220051162A (en) Visual positioning methods, training methods for related models, and related devices and devices
CN115018992A (en) Method and device for generating hair style model, electronic equipment and storage medium
CN112825199B (en) Collision detection method, device, equipment and storage medium
CN114998433A (en) Pose calculation method and device, storage medium and electronic equipment
JP7262530B2 (en) Location information generation method, related device and computer program product
CN109377552B (en) Image occlusion calculating method, device, calculating equipment and storage medium
US8264487B2 (en) Method for converting polygonal surfaces to levelsets
CN113384890B (en) Convex polygon collision detection method
CN113034582A (en) Pose optimization device and method, electronic device and computer readable storage medium
US8847954B1 (en) Methods and systems to compute 3D surfaces
Phalak et al. DeepPerimeter: Indoor boundary estimation from posed monocular sequences
CN111161289A (en) Method, device and computer program product for improving contour precision of object in image
CN111951348A (en) Method and device for determining frame selection area and electronic equipment
US9858710B2 (en) Method and apparatus for representing cordinate values of bounding box of object
JP2022064506A (en) Image processing device, image processing method, and program
CN108605113B (en) Methods, systems, and non-transitory computer-readable media for self-motion compensation
CN115063299B (en) Image preprocessing method and device, electronic equipment and storage medium
US11508083B2 (en) Image processing apparatus, image processing method, and non-transitory computer-readable storage medium
CN117635875B (en) Three-dimensional reconstruction method, device and terminal

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant