WO2024027684A1 - Geofence detection method and apparatus and electronic device - Google Patents

Geofence detection method and apparatus and electronic device Download PDF

Info

Publication number
WO2024027684A1
WO2024027684A1 PCT/CN2023/110485 CN2023110485W WO2024027684A1 WO 2024027684 A1 WO2024027684 A1 WO 2024027684A1 CN 2023110485 W CN2023110485 W CN 2023110485W WO 2024027684 A1 WO2024027684 A1 WO 2024027684A1
Authority
WO
WIPO (PCT)
Prior art keywords
target
vector
geofence
position point
boundary
Prior art date
Application number
PCT/CN2023/110485
Other languages
French (fr)
Chinese (zh)
Inventor
匡运生
Original Assignee
维沃移动通信有限公司
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 维沃移动通信有限公司 filed Critical 维沃移动通信有限公司
Publication of WO2024027684A1 publication Critical patent/WO2024027684A1/en

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W4/00Services specially adapted for wireless communication networks; Facilities therefor
    • H04W4/02Services making use of location information
    • H04W4/021Services related to particular areas, e.g. point of interest [POI] services, venue services or geofences
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/953Querying, e.g. by the use of web search engines
    • G06F16/9537Spatial or temporal dependent retrieval, e.g. spatiotemporal queries
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W4/00Services specially adapted for wireless communication networks; Facilities therefor
    • H04W4/02Services making use of location information
    • H04W4/025Services making use of location information using location based information parameters

Definitions

  • This application belongs to the field of communication technology, and specifically relates to a geofence detection method, device and electronic equipment.
  • Geofencing uses a virtual fence to enclose a virtual geographical boundary.
  • an electronic device enters or leaves a specific geographical area, or is active within this area, it can receive automatic notifications such as information reminders.
  • the real geographic point of interest (POI) boundary is often a closed irregular polygon composed of some discrete location points and their corresponding connections.
  • the Crossing Number method is usually used to determine whether a location point is inside a polygonal geofence. The principle is to calculate the number of times a ray starting from point P passes through the polygon boundary. If it is an odd number, then point P is within Inside the polygon, or outside the polygon if it's even.
  • this method involves the problem of judging whether the ray intersects with the line segment, that is, it involves the inversion operation of the matrix, and the calculation amount of this operation is relatively large, and it also requires at least two rays starting from point P. Perform operations on all polygon boundaries one by one, which increases the amount of calculation. It can be seen that the geofence detection method in related technologies has a problem of huge calculation amount.
  • the purpose of the embodiments of the present application is to provide a geofence detection method, device and electronic equipment, which can solve the problem of huge calculation amount of geofence detection methods in related technologies.
  • embodiments of the present application provide a geofence detection method, which method includes:
  • the positional relationship between the first position point and the target geofence is determined according to the dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector, wherein the target boundary vertex is the For some or all boundary vertices in the target geofence, the target normal vector is a normal vector perpendicular to the edge vector at the target boundary vertex.
  • a geofence detection device including:
  • the acquisition module is used to acquire the first position point where the electronic device is currently located
  • the first determination module is used to determine each normal vector of the target geographical fence, wherein the target geographical fence is formed by connecting N boundary vertices in a preset order, and the normal vector is perpendicular to the edge vector of the target geographical fence.
  • the edge vector is a vector formed by connecting two adjacent boundary vertices of the target geofence, and N is an integer greater than 2;
  • the second determination module is used to determine the positional relationship between the first position point and the target geofence according to the dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector, wherein,
  • the target boundary vertex is part or all of the boundary vertices in the target geofence, and the target normal vector is a normal vector perpendicular to an edge vector at the target boundary vertex.
  • inventions of the present application provide an electronic device.
  • the electronic device includes a processor and a memory.
  • the memory stores programs or instructions that can be run on the processor.
  • the programs or instructions are processed by the processor.
  • the processor is executed, the steps of the geofence detection method described in the first aspect are implemented.
  • embodiments of the present application provide a readable storage medium that stores programs or instructions. When the programs or instructions are executed by a processor, the geofence detection as described in the first aspect is implemented. Method steps.
  • inventions of the present application provide a chip.
  • the chip includes a processor and a communication interface.
  • the communication interface is coupled to the processor.
  • the processor is used to run programs or instructions to implement the first aspect.
  • the geofence detection method is used to run programs or instructions to implement the first aspect.
  • embodiments of the present application provide a computer program product.
  • the computer program product is stored in a storage medium.
  • the computer program product is executed by at least one processor to implement the geofence detection method as described in the first aspect.
  • the first location point where the electronic device is currently located is obtained; each normal vector of the target geofence is determined respectively, wherein the target geofence is formed by connecting N boundary vertices in a preset order, and the The normal vector is perpendicular to the edge vector of the target geofence, the edge vector is a vector formed by connecting two adjacent boundary vertices of the target geofence, and N is an integer greater than 2; according to the first position point and The dot product of the vector formed by connecting the target boundary vertices and the target normal vector determines the positional relationship between the first position point and the target geofence, wherein the target boundary vertex is part or all of the target geofence.
  • the target normal vector is a normal vector perpendicular to the edge vector at the target boundary vertex.
  • the vector method is used to detect geofences on electronic devices, avoiding the complex operations involved in the traditional cross number method, and only using four simple arithmetic operations, which can effectively reduce the computational complexity of fence detection and greatly reduce calculations. quantity and improve detection efficiency.
  • Figure 1 is a schematic diagram of a polygonal geofence of a POI provided by an embodiment of the present application
  • Figure 2 is a schematic diagram of geofence detection using the cross number method in related technologies
  • Figure 3 is a schematic diagram of splitting a polygonal geofence into multiple circular fences in the related art
  • Figure 4 is one of the flow charts of the geofence detection method provided by the embodiment of the present application.
  • Figure 5 is a schematic diagram of the edge vectors and corresponding normal vectors of a polygonal geofence provided by an embodiment of the present application
  • Figure 6 is an algorithm flow chart for polygon geofence detection using the vector method provided by the embodiment of the present application.
  • Figure 7 is the second flow chart of the geofence detection method provided by the embodiment of the present application.
  • Figure 8 is a schematic diagram of the movement direction vector and the corresponding normal dividing the fence area in the polygonal geofence provided by the embodiment of the present application;
  • Figure 9 is a schematic diagram of the movement direction vector and normal coordinate rotation provided by the embodiment of the present application.
  • Figure 10 is the third flow chart of the geofence detection method provided by the embodiment of the present application.
  • Figure 11 is a schematic diagram of the distance of a point in various directions within a polygonal geofence provided by an embodiment of the present application.
  • Figure 12 is the fourth flow chart of the geofence detection method provided by the embodiment of the present application.
  • Figure 13 is a schematic structural diagram of a geofence detection device provided by an embodiment of the present application.
  • Figure 14 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
  • Figure 15 is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present application.
  • first, second, etc. in the description and claims of this application are used to distinguish similar objects and are not used to describe a specific order or sequence. It is to be understood that the terms so used are interchangeable under appropriate circumstances so that the embodiments of the application can be practiced in sequences other than those illustrated or described herein, and that "first,” “second,” etc. are distinguished Objects are usually of one type, and the number of objects is not limited. For example, the first object can be one or multiple.
  • “and/or” in the description and claims indicates at least one of the connected objects, and the character “/" generally indicates that the related objects are in an "or” relationship.
  • Wireless Fidelity is a wireless LAN access technology and one of the ways for mobile phones and other electronic devices to connect to the network wirelessly;
  • AP Access Point
  • WiFi Wireless Fidelity
  • All WiFi devices must be connected to the AP device to access the Internet.
  • wireless routers and gateways are common AP devices, and smartphones can also become AP devices when turning on WiFi hotspots;
  • GPS Global Positioning System
  • smartphones generally integrate GPS chip modules, which can receive and interpret signals broadcast by GPS satellites to determine their location;
  • Point of Interest in geographic information systems, a point of interest represents a geographical unit, such as a shop, a house, a bus stop, etc.
  • Geofence detection is an important function integrated in the framework layer of intelligent electronic devices. It is a bridge that converts the underlying geographical location information into the user's space and context. It is used for users' situation awareness, user portraits, important information reminders and other services. Plays an important supporting role.
  • An actual polygonal geofence 10 of a shopping mall POI can be shown in Figure 1 .
  • the Crossing Number method also known as the parity check method, is mainly used to determine whether a point is inside a polygonal geofence. As shown in Figure 2, it is used to determine whether a ray starting from point P passes through the polygonal geofence boundary. If it is an odd number, it is determined that point P is inside the polygonal geofence; if it is an even number, it is determined that point P is outside the polygonal geofence.
  • the amount of calculation is huge:
  • the intersection number method involves the problem of judging whether the ray and the line segment intersect, and judging this problem involves the inversion operation of the matrix.
  • the amount of calculation of this operation is relatively large, and it also needs to start from point P. At least two starting rays and all boundaries of the polygonal geofence must be calculated one by one, which increases the calculation amount.
  • fence detection is basically done on the terminal side, which means that this calculation must also be performed on the terminal side, and the huge amount of calculation will inevitably cause the terminal to Large power consumption overhead;
  • intersection number method has limited application in actual polygon geofence detection, and developers need to use optimized alternative algorithms for detection.
  • the improved replacement algorithm of the traditional cross number method usually uses the split approximation method to split a complete polygonal geofence into several simple-shaped geofences for approximate replacement, thereby reducing the computational complexity of the geofence detection algorithm.
  • a complete polygonal geofence is generated into multiple circular geofences to cover the geographical area defined by the polygonal geofence, and the multiple circular geofences are monitored to detect entry into any describe The current location of the user's device that bounds the circular geofence.
  • this application designs a polygonal geofence detection method.
  • the vector calculation method is used to determine whether point P is located inside the polygonal geofence.
  • the vector method for detecting polygonal geofences avoids the complex operations involved in the traditional intersection number method, and can effectively reduce the computational complexity of fence detection, improve detection efficiency, and reduce equipment power consumption.
  • the vector method for polygonal fence detection is calculated and judged strictly according to the real boundary of the polygon, thus avoiding the problem of inconsistency between the fence boundary and the actual polygonal fence boundary during the approximation simulation using a circular fence or a rectangular fence in the split approximation method.
  • Figure 4 is a flow chart of a geofence detection method provided by an embodiment of the present application. As shown in Figure 4, the method includes the following steps:
  • Step 401 Obtain the first location point where the electronic device is currently located.
  • the current location information of the electronic device can be obtained, such as by locating the electronic device.
  • the position of the device is to obtain the position point where the electronic device is located at the current moment, that is, the first position point.
  • Step 402 Determine each normal vector of the target geofence respectively, wherein the target geofence is formed by connecting N boundary vertices in a preset order, the normal vector is perpendicular to the edge vector of the target geofence, and the edge The vector is a vector formed by connecting two adjacent boundary vertices of the target geofence, and N is an integer greater than 2.
  • the above-mentioned target geofence may be a geofence of a certain POI, for example, it may be a geofence of a certain POI near the electronic device.
  • the target geofence may be a polygonal geofence, including N boundary vertices, which is a closed polygonal area formed by connecting the N boundary vertices in a certain order.
  • the N boundary vertices are P 1 and P respectively.
  • the N boundary vertices can be connected in positive order, that is, P 1 is connected to P 2 , P 2 is connected to P 3 ,...P N-1 is connected to PN , and P N is connected to P 1 Connect, or you can also connect the N boundary vertices in reverse order, that is, connect P 1 to PN , connect PN to PN-1 ,...P 3 to P 2 , and connect P 2 to P 1. , thus obtaining a closed polygonal geofence.
  • the edge vector of the target geofence may refer to the connection shape of two adjacent boundary vertices of the target geofence.
  • two adjacent boundary vertices can be connected in a counterclockwise direction to form an edge vector:
  • two adjacent boundary vertices can also be connected in a clockwise direction to form an edge vector.
  • Each normal vector of the target geofence may refer to a vector perpendicular to each edge vector of the target geofence, and the direction of each normal vector may be counterclockwise or clockwise to the direction of the corresponding edge vector. Obtained by rotating 90°. Therefore, the above-mentioned determination of each normal vector of the target geofence may be to determine each edge vector of the target geofence, and perform coordinate transformation on each edge vector according to the coordinate transformation formula, thereby obtaining each corresponding normal vector, The coordinate transformation formula is determined based on the rotation angle. For example, if the object is rotated 90° counterclockwise, the angle of rotation is 90°, and if rotated 90° clockwise, the angle of rotation is -90°.
  • Step 403 Determine the positional relationship between the first position point and the target geofence according to the dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector, wherein the target boundary vertex is part or all of the boundary vertices in the target geofence, and the target normal vector is a normal vector perpendicular to the edge vector at the target boundary vertex.
  • the angle between the target vector formed by connecting the first location point and any boundary vertex in the target geofence and the normal vector corresponding to the edge vector where the boundary vertex is located can be determined.
  • the positional relationship between the first position point and the target geofence that is, determining whether the first position point is located inside or outside the target geofence. For example, if the normal vector points to the inside of the target geofence, then The target vector is a vector whose boundary vertex points to the first location point. Then, for the location point located inside the target geographical fence, the angle between the target vector and the normal vector is an acute angle, and the angle between the target vector and the normal vector is an acute angle.
  • the angle between the target vector and the normal vector is an obtuse angle; or, if the normal vector points outside the target geofence, the target vector is the boundary vertex pointing to the first position point vector, then for a position point located inside the target geofence, the angle between the target vector and the normal vector is an obtuse angle; for a position point located outside the target geofence, the target vector and the normal vector
  • the angle between the normal vectors is an acute angle. In order to determine whether the angle between two vectors is an acute angle, it can be determined based on whether the dot product of the two vectors is greater than 0. If the dot product is greater than 0, it can be determined that the angle between the two vectors is an acute angle, and vice versa.
  • the vector formed by connecting the first position point and the target boundary vertex can be determined according to the dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector. Whether the angle between the first position point and the target normal vector is an acute angle, and then combined with the direction of the vector formed by connecting the first position point and the target boundary vertex and the direction of the target normal vector, determine the relationship between the first position point and the The positional relationship of the target geofence, that is, determining whether the first location point is located inside or outside the target geofence.
  • the target boundary vertices may include all boundary vertices of the target geofence, or may only include part of the boundary vertices of the target geofence. That is, in one embodiment, the target boundary vertices may be determined according to the first location point and the target geofence. The dot product of the vector formed by connecting each boundary vertex of the target geofence and the target normal vector determines the positional relationship between the first position point and the target geofence.
  • the first location point can be The dot product of the vector formed by connecting the target boundary vertex of the target geofence that meets certain conditions (such as the boundary vertex on the same side as the first location point) and the target normal vector determines the relationship between the first location point and Regarding the positional relationship of the target geofence, this embodiment is applicable to the situation where the electronic device has entered the target geofence and subsequently determines whether the electronic device is still inside the target geofence based on real-time positioning.
  • the edge vector at the target boundary vertex may refer to an edge vector starting from the target boundary vertex.
  • the normal vector points to the interior of the target geofence
  • the step 403 includes:
  • each edge vector of the target geofence when two adjacent boundary vertices are connected in a counterclockwise direction, each edge vector can be rotated 90° counterclockwise to obtain the corresponding normal vectors, so that each normal vector points to the inside of the target geofence; or, When each edge vector of the target geofence is formed by connecting two adjacent boundary vertices in a clockwise direction, each edge vector can be rotated 90° clockwise to obtain the corresponding normal vectors, so that each normal vector points to the described Inside the target geofence.
  • the vector formed by connecting the first location point and the target boundary vertex may be a first vector pointing from the target boundary vertex to the first location point.
  • the angle between the first vector and the target normal vector is an acute angle, that is, less than 90°.
  • the dot product of the first vector and the target normal vector is greater than 0. If the first vector If the location point is located outside the target geofence, then the angle between the first vector and the target normal vector is an obtuse angle, that is, greater than 90°.
  • the dot product of the first vector and the target normal vector is Less than 0.
  • the dot product of the first vector and the target normal vector by calculating the dot product of the first vector and the target normal vector and comparing it with 0, it can be determined whether the first location point is located inside or outside the target geofence. , specifically, when the dot product of the first vector and the target normal vector is greater than 0, it can be determined that the first location point is located inside the target geofence. When the dot product of the target normal vector is less than 0, it can be determined that the first location point is located outside the target geofence.
  • the electronic device is located at the boundary of the target geofence, that is, the angle between the first vector and the target normal vector is a right angle, which is equal to 90°. , therefore, it can be determined that the first location point is located at the boundary of the target geofence when the dot product of the first vector and the target normal vector is equal to 0.
  • the core invention of this application is to use the vector method to detect polygonal geofences.
  • the following is a detailed introduction to the algorithm principle of using the vector method to determine whether point P is located inside a polygonal geofence.
  • the boundary of the polygonal geofence can be specified in the technical solution of this application
  • the vertex array is arranged in a counterclockwise direction; if it is arranged in a clockwise direction, the same function can be achieved through equivalent transformation;
  • POI geofence data basically meets the above two conditions.
  • edge vector The corresponding normal vector can be recorded as Since the boundary vertex array of the polygonal geofence is arranged in counterclockwise order, the normal vector can be considered It is obtained by rotating 90° counterclockwise based on the coordinate system where the boundary vertex data is located.
  • the coordinate transformation formula is:
  • (x′, y′) is the coordinate value in the new coordinate system after coordinate rotation, and ⁇ is the rotation angle.
  • the edge vectors and corresponding normal vectors of the polygonal geofence can be shown in Figure 5. It can be seen from Figure 5 that the normal vectors corresponding to all the edge vectors of the polygonal geofence point to the inside of the polygonal geofence.
  • the dot product can determine whether point P is in the polygon geofence internal.
  • the whole process of vector method calculation only uses four simple arithmetic operations and does not involve complex calculation modes, which greatly reduces the amount of calculation and improves the performance of polygonal geofence detection.
  • step 401 and before step 403 the method further includes:
  • the step 403 includes:
  • the first position point is determined based on the dot product of the connecting vector between the first position point and the target boundary vertex and the target normal vector. The location relationship to the target geofence.
  • the determination can be made based on the circumscribed rectangle of the polygonal geofence. If the positioning point is outside the circumscribing rectangle, there is no need to detect the polygonal geofence, and it can be directly determined that the positioning point is located outside the polygonal geofence.
  • the maximum and minimum values of take the maximum and minimum values of longitude and the maximum and minimum values of latitude, and form the boundary of the circumscribed rectangle based on these four points.
  • the positional relationship between the first location point and the circumscribed rectangular area can be determined first, that is, it is determined whether the first location point is located in the circumscribed rectangle. Outside the area, if the first location point is located outside the circumscribed rectangular area, it can be directly determined that the first location point is located outside the target geofence, if the first location point is not located in the circumscribed rectangular area Externally, if the first position point is located inside the circumscribed rectangular area or at the boundary of the circumscribed rectangular area, then the subsequent step 403 can be continued, that is, further based on the connection vector between the first position point and the target boundary vertex. The dot product with the target normal vector determines the positional relationship between the first location point and the target geofence.
  • point P For the current location point P, you can first determine whether point P is outside the circumscribed rectangle of the polygonal geofence. If the longitude of point P exceeds the maximum or minimum longitude of the circumscribed rectangle, or the latitude of point P exceeds the circumscribed rectangle. If the maximum or minimum value of the latitude of the rectangle is determined, it can be determined that point P is located outside the polygonal geofence; otherwise, whether point P is outside the polygonal geofence can be determined according to the aforementioned vector method.
  • the coordinate system used for the position coordinates of the boundary vertices of the polygonal geofence is a non-geodestic coordinate system such as GCJ02, BD09, etc.
  • the coordinates of each boundary vertex of the polygonal geofence need to be transformed. It is the internationally adopted geocentric coordinate system (World Geodetic System - 1984 Coordinate System, WGS84). Because only the WGS84 coordinate system is a linear coordinate system, it meets the prerequisites for polygon geofence detection through the vector method. That is, before generating the bounding rectangle of the polygonal geofence, the step of transforming the coordinates of the boundary vertices of the polygonal geofence can be performed.
  • this step is not required.
  • converting the GCJ02 or BD09 coordinate system to the WGS84 coordinate system can be done directly through the open source conversion plug-in.
  • Step 701 Transform the coordinates of the vertices of the polygonal geofence boundary.
  • Step 702 Generate the bounding rectangle of the polygonal geofence.
  • Step 703 Determine whether point P is outside the enclosing rectangle.
  • step 704 is entered for the next step of determination.
  • Step 704 Determine whether point P is outside the polygonal geofence according to the vector method.
  • the polygonal geofence detection algorithm can be simplified, the amount of calculation is reduced, the detection efficiency is improved, and the power consumption is reduced.
  • the method further includes:
  • the electronic device When the electronic device is located inside the target geofence at the first time, store the second location point of the electronic device at the first time, and the first time is the time before the current time. ;
  • step 401 and before step 403 the method further includes:
  • coordinate transformation is performed on the boundary vertex of the target geofence to obtain the ordinate value of the boundary vertex of the target geofence in a second coordinate system, where the second coordinate system is The coordinate system after rotating the first included angle counterclockwise from the Cartesian coordinate system;
  • the target boundary vertex is determined according to the ordinate value of the boundary vertex of the target geofence in the second coordinate system and the ordinate value of the second location point in the second coordinate system, where, The target boundary vertex is located on a first side of a first normal line, the first normal line is perpendicular to the second vector, and the first position point is located on a first side of the first normal line.
  • This vector represents the user's movement direction from time t 0 to time t 1 , and can be called a movement direction vector.
  • a vector perpendicular to the direction of motion can be drawn through point P (t 0 )
  • the straight line L is called the normal of the motion direction vector. Since point P(t 0 ) is inside the polygonal geofence, this normal line L will divide the entire polygonal geofence into two parts. Correspondingly, the vertices on the boundary of the polygonal geofence will also be divided into two parts by this normal line.
  • one part of the vertices is located on the same side of the point P(t 1 ), which is called the same-side vertex; the part of the vertex is located on different sides of the point P(t 1 ), which is called the different-side vertex (such as Vertices marked with “ ⁇ ” in Figure 8).
  • point P(t 0 ) is already located inside the polygonal geofence, it means that point P(t 0 ) is already located inside the polygonal geofence compared with these vertices on opposite sides, and point P (t 1 ) is farther away from the vertices on the opposite side than point P (t 0 ). From the perspective of these vertices on the opposite side, point P (t 1 ) is more likely to be located inside the polygonal geofence.
  • Step 1001 Cache the position point P(t 0 ) located inside the polygonal geofence.
  • Step 1002 The electronic device initiates positioning at time t 1 and obtains the positioning position P(t 1 ) at that time.
  • the positioning method can be determined according to the specific environment of the target geofence. For example, if the geofence is outdoors, GPS can be used for positioning; if it is an indoor environment, network positioning can be initiated and positioned through WiFi or base station signals.
  • Step 1003 Calculate the motion direction vector and the corresponding angle.
  • the motion direction vector be The angle between the movement direction vector and the negative half-axis of the y-axis of the Cartesian coordinate system can be calculated as:
  • Step 1004 According to the coordinate conversion formula and the included angle ⁇ , perform coordinate transformation on all vertices of the polygonal geofence boundary, and calculate the ordinate value y′ under the new coordinates.
  • Step 1005 Calculate the ordinate value y t0 of point P(t 0 ) under the new coordinates. Compare the values of y′ and y t0 . If y′>y t0 , the corresponding vertex is determined to be a vertex on the opposite side; otherwise, the corresponding vertex is determined to be a vertex on the same side.
  • Step 1006 Use the vector method to determine whether point P(t 1 ) is located inside the polygonal geofence using vertices on the same side.
  • the origin of the second coordinate system is the second position point, and the ordinate value of the second position point in the second coordinate system is 0;
  • the step 401 includes:
  • the first boundary vertex is determined to be the target boundary vertex, wherein the first boundary vertex is the Any boundary vertex in the target geofence;
  • the second position point at the previous moment can be used as the origin of the Cartesian coordinate system, and the Cartesian coordinate system is rotated counterclockwise to obtain the converted second coordinate system, so that the origin of the second coordinate system is the second position point, so the ordinate value of the second position point in the second coordinate system is 0.
  • the position point P(t 0 ) at time t 0 can be the origin of the new coordinate system after transformation, so that the ordinate value of P(t 0 ) in the new coordinate system is 0.
  • each boundary vertex is When it is the target boundary vertex (that is, whether it is a vertex on the same side), it is only necessary to compare the ordinate value of each boundary vertex in the second coordinate system with 0. Specifically, if a certain boundary vertex is in the If the ordinate value in the second coordinate system is greater than 0, it can be determined that the boundary vertex is a vertex on the opposite side, that is, it is not the target boundary vertex. On the contrary, if the ordinate value of a boundary vertex in the second coordinate system is less than or If equal to 0, it can be determined that the boundary vertex is the vertex on the same side, that is, it is the target boundary vertex.
  • the method further includes:
  • the second time is the time before the current time
  • a spatial environment table is generated, wherein the spatial environment table stores a corresponding relationship between directions and distances.
  • M is equal to 360 degrees divided by the preset angle;
  • step 401 and before step 403 the method further includes:
  • the step 403 includes:
  • the distance between the first position point and the target is determined based on the dot product of the connecting vector between the first position point and the target boundary vertex and the target normal vector. Geofence location relationships.
  • a user After a user enters a geofence, he or she usually stays for a while and does not leave the geofence immediately. For example, a user is shopping in a shopping mall, and the user has been inside the polygonal geofence corresponding to the shopping mall during the shopping period. If the polygonal geofence detection algorithm is used for each positioning, each detection will consume a lot of time. Large amount of calculation. If the user calls applications such as indoor navigation while shopping, the frequency of positioning will increase, and the amount of calculation and power consumption will increase. Therefore, in this implementation, a simpler algorithm is proposed to cover this scenario.
  • the method designed in this embodiment is a method of exchanging space for time. Specifically, the user constructs the spatial environment of the polygonal geofence when entering the polygonal geofence for the first time, so that each time the user is positioned, only A simple calculation is required to determine whether you are still inside the polygonal geofence. Therefore, the core of this implementation is how to construct a spatial environment of polygonal geofences.
  • a spatial environment table of the polygonal geofence can be generated, which records the distance of the current point in all direction vectors.
  • the angle between two adjacent direction vectors can be set according to actual needs. For example, the angle between two adjacent direction vectors can be set to 15°, then the entire polygonal geofence space can be divided into 24 direction vectors. .
  • the spatial environment table of the geofence can be shown in Table 1 below.
  • the method further includes:
  • the spatial environment table is updated according to the distance change value in each of the M directions.
  • the spatial environment table can be updated so that subsequent positioning positions can be based on the updated spatial environment table. Make more accurate judgments.
  • Step 1201 Generate a spatial environment table.
  • Step 1202 Obtain the positioning position and calculate the modulus and direction of the user's motion direction vector.
  • Step 1203 Query the vector interval number in the direction of the motion direction vector from the space environment table.
  • Step 1204 Query the distance corresponding to the vector interval number.
  • Step 1205 Determine whether the modulus value of the motion direction vector is less than the distance queried in the spatial environment table. If so, directly determine that the point is located inside the polygonal geofence; otherwise, proceed to step 1206.
  • Step 1206 Start the vector method to detect polygonal geofences.
  • Step 1207 Update the space environment table.
  • the geofence detection method in the embodiment of the present application obtains the first location point where the electronic device is currently located; respectively determines each normal vector of the target geofence, wherein the target geofence is connected by N boundary vertices in a preset order Formed, the normal vector is perpendicular to the edge vector of the target geographical fence, the edge vector is a vector formed by connecting two adjacent boundary vertices of the target geographical fence, and N is an integer greater than 2; according to the first The dot product of the vector formed by connecting a position point and the target boundary vertex and the target normal vector determines the positional relationship between the first position point and the target geofence, wherein the target boundary vertex is in the target geofence.
  • the target normal vector is a normal vector perpendicular to the edge vector at the target boundary vertex.
  • the vector method is used to detect geofences on electronic devices, avoiding the complex operations involved in the traditional cross number method, and only using four simple arithmetic operations, which can effectively reduce the computational complexity of fence detection and greatly reduce calculations. quantity and improve detection efficiency.
  • the execution subject may be a geofence detection device.
  • the geofence detection method performed by the geofence detection device is used as an example to illustrate the geofence detection device provided by the embodiments of this application.
  • FIG 13 is a schematic structural diagram of a geofence detection device provided by an embodiment of the present application.
  • the geofence detection device 1300 includes:
  • the acquisition module 1301 is used to acquire the first location point where the electronic device is currently located;
  • the first determination module 1302 is used to determine each normal vector of the target geographical fence, wherein the target geographical fence is formed by connecting N boundary vertices in a preset order, and the normal vector is the same as the edge vector of the target geographical fence.
  • the edge vector is a vector formed by connecting two adjacent boundary vertices of the target geofence, and N is an integer greater than 2;
  • the second determination module 1303 is configured to determine the positional relationship between the first position point and the target geofence based on the dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector, where, The target boundary vertex is part or all of the boundary vertices in the target geofence, and the target normal vector is a normal vector perpendicular to an edge vector at the target boundary vertex.
  • the geofence detection device 1300 also includes:
  • a third determination module configured to determine the circumscribed rectangular area of the target geofence, wherein all boundary vertices of the target geofence are located within the circumscribed rectangular area;
  • the fourth determination module is used to determine the positional relationship between the first position point and the circumscribed rectangular area
  • the second determination module is configured to determine based on the dot product of the connection vector between the first position point and the target boundary vertex and the target normal vector when it is determined that the first position point is not located outside the circumscribed rectangular area. , determine the positional relationship between the first location point and the target geofence.
  • the normal vector points to the interior of the target geofence
  • the second determination module 1303 includes:
  • a first determination unit configured to determine that the first location point is located inside the target geofence when the dot product of the first vector and the target normal vector is greater than 0, wherein the first vector is A vector from the target boundary vertex pointing to the first position point;
  • a second determination unit configured to determine that the first location point is located outside the target geofence when the dot product of the first vector and the target normal vector is less than 0.
  • the geofence detection device 1300 also includes:
  • a first storage module configured to store the second location point of the electronic device at the first time when the electronic device is located inside the target geofence at the first time, the first The time is the time before the current time;
  • the fifth determination module is used to determine the second vector and the first included angle, wherein the second vector is a vector from the second position point to the first position point, and the first included angle is the The angle between the second vector and the -y axis in the Cartesian coordinate system;
  • a coordinate conversion module configured to perform coordinate conversion on the boundary vertex of the target geofence according to the first included angle to obtain the ordinate value of the boundary vertex of the target geofence in the second coordinate system, wherein:
  • the second coordinate system is a coordinate system obtained by rotating the rectangular coordinate system counterclockwise by the first included angle;
  • the sixth determination module is used to determine the ordinate value of the boundary vertex of the target geofence in the second coordinate system and the ordinate value of the second location point in the second coordinate system.
  • the target boundary vertex wherein the target boundary vertex is located on a first side of a first normal line, the first normal line is perpendicular to the second vector, and the first position point is located on the first side of the first normal line First side.
  • the origin of the second coordinate system is the second position point, and the ordinate value of the second position point in the second coordinate system is 0;
  • the sixth determination module includes:
  • a third determination unit configured to determine that the first boundary vertex is the target boundary vertex when the ordinate value of the first boundary vertex in the second coordinate system is less than or equal to 0, wherein, The first boundary vertex is any boundary vertex in the target geofence;
  • a fourth determination unit configured to determine that the first boundary vertex is not the target boundary vertex when the ordinate value of the first boundary vertex in the second coordinate system is greater than 0.
  • the geofence detection device 1300 also includes:
  • a second storage module configured to store the third location point of the electronic device at the second time when the electronic device is located inside the target geofence at the second time.
  • the time is the time before the current time
  • a generation module configured to generate a spatial environment table according to the distances between the third location point and the boundary of the target geofence along the preset M directions, wherein the spatial environment table stores directions and distances.
  • the spatial environment table stores directions and distances.
  • two adjacent directions among the M directions are separated by a preset angle, and M is equal to 360 degrees divided by the preset angle.
  • a seventh determination module used to determine the first distance and the first direction of the first position point relative to the third position point
  • a query module used to query the second distance corresponding to the first direction from the spatial environment table
  • the second determination module 1303 is configured to determine the first distance based on the dot product of the connection vector between the first position point and the target boundary vertex and the target normal vector when the first distance is greater than the second distance. The positional relationship between a location point and the target geofence.
  • the geofence detection device 1300 also includes:
  • An eighth determination module configured to determine the angle between the third vector and each of the M directions respectively when it is determined that the first location point is located inside the target geofence, wherein the third vector The vector is a vector from the third position point to the first position point;
  • a ninth determination module configured to determine the distance change value in each of the M directions according to the angle between the third vector and each of the M directions and the modulus of the third vector;
  • An update module configured to update the spatial environment table according to the distance change value in each of the M directions.
  • the geofence detection device 1300 in the embodiment of the present application obtains the first location point where the electronic device is currently located; and determines each normal vector of the target geofence, wherein the target geofence consists of N boundary vertices in a preset order
  • the connection is formed, the normal vector is perpendicular to the edge vector of the target geographical fence, the edge vector is a vector formed by connecting two adjacent boundary vertices of the target geographical fence, and N is an integer greater than 2; according to the The dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector determines the positional relationship between the first position point and the target geofence, wherein the target boundary vertex is the target geofence At some or all of the boundary vertices in , the target normal vector is a normal vector perpendicular to the edge vector at the target boundary vertex.
  • the vector method is used to detect geofences on electronic devices, avoiding the complex operations involved in the traditional cross number method, and only using four simple arithmetic operations, which can effectively reduce the computational complexity of fence detection and greatly reduce calculations. quantity and improve detection efficiency.
  • the geofence detection device in the embodiment of the present application may be an electronic device or a component of the electronic device, such as an integrated circuit or chip.
  • the electronic device may be a terminal or other devices other than the terminal.
  • the electronic device can be a mobile phone, a tablet computer, a notebook computer, a handheld computer, a vehicle-mounted electronic device, a mobile Internet device (MID), or an augmented reality (Augmented Reality, AR)/virtual reality (Virtual Reality, VR) ) equipment, robots, wearable devices, ultra-mobile personal computers (Ultra-Mobile Personal Computer, UMPC), netbooks or personal digital assistants (Personal Digital Assistant, PDA), etc., and can also be servers, network attached storage (Network Attached Storage, NAS), personal computer (Personal Computer, PC), television (Television, TV), teller machine or self-service machine, etc., the embodiments of this application are not specifically limited.
  • the geofence detection device in the embodiment of the present application may be a device with an operating system.
  • the operating system can be an Android operating system, an ios operating system, or other possible operating systems, which are not specifically limited in the embodiments of this application.
  • the geofence detection device provided by the embodiment of the present application can implement various processes implemented by the embodiments of Figures 4 to 12. To avoid duplication, they will not be described again here.
  • this embodiment of the present application also provides an electronic device 1400, including a processor 1401 and a memory 1402.
  • the memory 1402 stores programs or instructions that can be run on the processor 1401.
  • each step of the above geofence detection method embodiment is implemented and the same technical effect can be achieved. To avoid duplication, the details will not be described here.
  • the electronic devices in the embodiments of the present application include the above-mentioned mobile electronic devices and non-mobile electronic devices.
  • Figure 15 is a schematic diagram of the hardware structure of an electronic device that implements an embodiment of the present application.
  • the electronic device 1500 includes but is not limited to: radio frequency unit 1501, network module 1502, audio output unit 1503, input unit 1504, sensor 1505, display unit 1506, user input unit 1507, interface unit 1508, memory 1509, processor 1510, etc. part.
  • the electronic device 1500 may also include a power supply (such as a battery) that supplies power to various components.
  • the power supply may be logically connected to the processor 1510 through a power management system, thereby managing charging, discharging, and function through the power management system. Consumption management and other functions.
  • the structure of the electronic device shown in Figure 15 does not constitute a limitation of the electronic device.
  • the electronic device may include more or less components than shown in the figure, or combine certain components, or arrange different components, which will not be described again here. .
  • processor 1510 is used for:
  • each normal vector of the target geofence is formed by connecting N boundary vertices in a preset order, the normal vector is perpendicular to the edge vector of the target geofence, and the edge vector is The vector formed by connecting two adjacent boundary vertices of the target geofence, N is an integer greater than 2;
  • the positional relationship between the first position point and the target geofence is determined according to the dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector, wherein the target boundary vertex is the For some or all boundary vertices in the target geofence, the target normal vector is a normal vector perpendicular to the edge vector at the target boundary vertex.
  • processor 1510 is also used to:
  • the first position point is determined based on the dot product of the connecting vector between the first position point and the target boundary vertex and the target normal vector. The location relationship to the target geofence.
  • the normal vector points to the interior of the target geofence
  • Processor 1510 also used for:
  • the dot product of the first vector and the target normal vector is greater than 0, it is determined that the first location point is located inside the target geofence, wherein the first vector points from the target boundary vertex to the target geofence. Describe the direction of the first position point quantity;
  • processor 1510 is also used to:
  • the electronic device When the electronic device is located inside the target geofence at the first time, store the second location point of the electronic device at the first time, and the first time is the time before the current time. ;
  • coordinate transformation is performed on the boundary vertex of the target geofence to obtain the ordinate value of the boundary vertex of the target geofence in a second coordinate system, where the second coordinate system is The coordinate system after rotating the first included angle counterclockwise from the Cartesian coordinate system;
  • the target boundary vertex is determined according to the ordinate value of the boundary vertex of the target geofence in the second coordinate system and the ordinate value of the second location point in the second coordinate system, where, The target boundary vertex is located on a first side of a first normal line, the first normal line is perpendicular to the second vector, and the first position point is located on a first side of the first normal line.
  • the origin of the second coordinate system is the second position point, and the ordinate value of the second position point in the second coordinate system is 0;
  • Processor 1510 also used for:
  • the first boundary vertex is determined to be the target boundary vertex, wherein the first boundary vertex is the Any boundary vertex in the target geofence;
  • processor 1510 is also used to:
  • a spatial environment table is generated, wherein the spatial environment table stores a corresponding relationship between directions and distances.
  • M is equal to 360 degrees divided by the preset angle;
  • the distance between the first position point and the target is determined based on the dot product of the connecting vector between the first position point and the target boundary vertex and the target normal vector. Geofence location relationships.
  • processor 1510 is also used to:
  • the spatial environment table is updated according to the distance change value in each of the M directions.
  • the electronic device in the embodiment of the present application obtains the first position point where the electronic device is currently located; and determines each normal vector of the target geofence, wherein the target geofence is formed by connecting N boundary vertices in a preset order,
  • the normal vector is perpendicular to the edge vector of the target geofence, the edge vector is a vector formed by connecting two adjacent boundary vertices of the target geofence, and N is an integer greater than 2; according to the first position
  • the dot product of the vector formed by connecting the point and the target boundary vertex and the target normal vector determines the positional relationship between the first position point and the target geofence, wherein the target boundary vertex is part of the target geofence.
  • the target normal vector is a normal vector perpendicular to the edge vector at the target boundary vertex.
  • the vector method is used to detect geofences on electronic devices, avoiding the complex operations involved in the traditional cross number method, and only using four simple arithmetic operations, which can effectively reduce the computational complexity of fence detection and greatly reduce calculations. quantity and improve detection efficiency.
  • the input unit 1504 may include a graphics processor (Graphics Processing Unit, GPU) 15041 and a microphone 15042.
  • the graphics processor 15041 is responsible for the image capture device (GPU) in the video capture mode or the image capture mode. Process the image data of still pictures or videos obtained by cameras (such as cameras).
  • the display unit 1506 may include a display panel 15061, which may be configured in the form of a liquid crystal display, an organic light emitting diode, or the like.
  • the user input unit 1507 includes a touch panel 15071 and at least one of other input devices 15072 .
  • Touch panel 15071 also known as touch screen.
  • the touch panel 15071 may include two parts: a touch detection device and a touch controller.
  • Other input devices 15072 may include but are not limited to physical keyboards, function keys (such as volume control keys, switch keys, etc.), trackballs, mice, and joysticks, which will not be described again here.
  • Memory 1509 may be used to store software programs as well as various data.
  • the memory 1509 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, Image playback function, etc.) etc.
  • memory 1509 may include volatile memory or nonvolatile memory, or memory 1509 may include both volatile and nonvolatile memory.
  • the non-volatile memory can be read-only memory (Read-Only Memory, ROM), programmable read-only memory (Programmable ROM, PROM), erasable programmable read-only memory (Erasable PROM, EPROM), electrically removable memory.
  • Volatile memory can be random access memory (Random Access Memory, RAM), static random access memory (Static RAM, SRAM), dynamic random access memory (Dynamic RAM, DRAM), synchronous dynamic random access memory (Synchronous DRAM, SDRAM), double data rate synchronous dynamic random access memory (Double Data Rate SDRAM, DDRSDRAM), enhanced synchronous dynamic random access memory (Enhanced SDRAM, ESDRAM), synchronous link dynamic random access memory (Synch link DRAM) , SLDRAM) and direct memory bus random access memory (Direct Rambus RAM, DRRAM).
  • RAM Random Access Memory
  • SRAM static random access memory
  • DRAM dynamic random access memory
  • synchronous dynamic random access memory Synchronous DRAM, SDRAM
  • Double data rate synchronous dynamic random access memory Double Data Rate SDRAM, DDRSDRAM
  • Enhanced SDRAM, ESDRAM synchronous link dynamic random access memory
  • Synch link DRAM synchronous link dynamic random access memory
  • SLDRAM direct memory bus random access memory
  • the processor 1510 may include one or more processing units; optionally, the processor 1510 integrates an application processor and a modem processor, where the application processor mainly handles operations related to the operating system, user interface, application programs, etc., Modem processors mainly process wireless communication signals, such as baseband processors. It can be understood that the above modem processor may not be integrated into the processor 1510.
  • Embodiments of the present application also provide a readable storage medium.
  • Programs or instructions are stored on the readable storage medium.
  • the program or instructions are executed by a processor, each process of the above geofence detection method embodiment is implemented, and can achieve The same technical effects are not repeated here to avoid repetition.
  • the processor is the processor in the electronic device described in the above embodiment.
  • the readable storage medium includes computer readable storage media, such as computer read-only memory ROM, random access memory RAM, magnetic disk or optical disk, etc.
  • An embodiment of the present application further provides a chip.
  • the chip includes a processor and a communication interface.
  • the communication interface is coupled to the processor.
  • the processor is used to run programs or instructions to implement the above embodiments of the geofence detection method. Each process can achieve the same technical effect. To avoid repetition, we will not go into details here. It should be understood that the chips mentioned in the embodiments of this application may also be called system-on-chip, system-on-a-chip, system-on-a-chip or system-on-chip, etc.
  • Embodiments of the present application provide a computer program product.
  • the program product is stored in a storage medium.
  • the program product is executed by at least one processor to implement each process of the above geofence detection method embodiment, and can achieve the same technology. The effect will not be described here to avoid repetition.
  • the computer software product is stored in a storage medium (such as ROM/RAM, magnetic disc, optical disk), including several instructions to cause a terminal (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in various embodiments of this application.
  • a storage medium such as ROM/RAM, magnetic disc, optical disk
  • a terminal which can be a mobile phone, computer, server, or network device, etc.
  • the embodiments of the present application have been described above in conjunction with the accompanying drawings. However, the present application is not limited to the above-mentioned specific implementations. The above-mentioned specific implementations are only illustrative and not restrictive. Those of ordinary skill in the art will inspired by this application, many forms can be made without departing from the purpose of this application and the scope protected by the claims, all of which fall within the protection of this application.

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Position Fixing By Use Of Radio Waves (AREA)
  • Navigation (AREA)

Abstract

The present application relates to the technical field of communication. Disclosed are a geofence detection method and apparatus and an electronic device. The method comprises: acquiring a first position point where an electronic device is currently located; respectively determining normal vectors of a target geofence, wherein the target geofence is formed by connecting N boundary vertexes in a preset order, each normal vector is perpendicular to each edge vector of the target geofence, the edge vector is a vector formed by connecting two adjacent boundary vertexes of the target geofence, and N is an integer greater than 2; and according to a dot product of a vector formed by connecting the first position point and target boundary vertexes and a target normal vector, determining a position relationship between the first position point and the target geofence, wherein the target boundary vertexes are some or all of the boundary vertexes in the target geofence, and the target normal vector is a normal vector perpendicular to edge vectors at the target boundary vertexes.

Description

地理围栏检测方法、装置和电子设备Geofence detection method, device and electronic equipment
相关申请的交叉引用Cross-references to related applications
本申请主张在2022年8月4日在中国提交的中国专利申请No.202210931542.5的优先权,其全部内容通过引用包含于此。This application claims priority from Chinese Patent Application No. 202210931542.5 filed in China on August 4, 2022, the entire content of which is incorporated herein by reference.
技术领域Technical field
本申请属于通信技术领域,具体涉及一种地理围栏检测方法、装置和电子设备。This application belongs to the field of communication technology, and specifically relates to a geofence detection method, device and electronic equipment.
背景技术Background technique
地理围栏是用一个虚拟的栅栏围出一个虚拟地理边界。当电子设备进入或离开某个特定地理区域,或在该区域内活动时,可以接收自动通知如信息提醒。Geofencing uses a virtual fence to enclose a virtual geographical boundary. When an electronic device enters or leaves a specific geographical area, or is active within this area, it can receive automatic notifications such as information reminders.
在实际应用场景中,真实的地理兴趣点(Point of Interest,POI)边界往往是由一些离散的位置点及其对应的连线所构成的闭合的不规则多边形。相关技术中,通常采用交叉数法(Crossing Number)来判断位置点是否在多边形地理围栏内部,其原理是计算从点P开始出发的射线穿过多边形边界的次数,如果为奇数,则点P在多边形内部,如果为偶数,则在多边形外部。In actual application scenarios, the real geographic point of interest (POI) boundary is often a closed irregular polygon composed of some discrete location points and their corresponding connections. In related technologies, the Crossing Number method is usually used to determine whether a location point is inside a polygonal geofence. The principle is to calculate the number of times a ray starting from point P passes through the polygon boundary. If it is an odd number, then point P is within Inside the polygon, or outside the polygon if it's even.
但由于该方法涉及到判断射线与线段是否相交的问题,也即涉及到矩阵的求逆运算,而这种运算的计算量是比较大的,而且还要对从点P出发的至少两条射线与多边形所有边界一一进行运算,更加大了计算量。可见,相关技术中地理围栏检测方法存在计算量巨大的问题。However, since this method involves the problem of judging whether the ray intersects with the line segment, that is, it involves the inversion operation of the matrix, and the calculation amount of this operation is relatively large, and it also requires at least two rays starting from point P. Perform operations on all polygon boundaries one by one, which increases the amount of calculation. It can be seen that the geofence detection method in related technologies has a problem of huge calculation amount.
发明内容Contents of the invention
本申请实施例的目的是提供一种地理围栏检测方法、装置和电子设备,能够解决相关技术中地理围栏检测方法计算量巨大的问题。The purpose of the embodiments of the present application is to provide a geofence detection method, device and electronic equipment, which can solve the problem of huge calculation amount of geofence detection methods in related technologies.
第一方面,本申请实施例提供了一种地理围栏检测方法,该方法包括:In a first aspect, embodiments of the present application provide a geofence detection method, which method includes:
获取电子设备当前所处的第一位置点;Obtain the first location point where the electronic device is currently located;
分别确定目标地理围栏的各个的法向量,其中,所述目标地理围栏由N个边界顶点按预设顺序连接形成,所述法向量与所述目标地理围栏的边向量垂直,所述边向量为所述目标地理围栏的相邻两个边界顶点连接形成的向量,N为大于2的整数;Determine the normal vectors of each target geofence respectively, wherein the target geofence is formed by connecting N boundary vertices in a preset order, the normal vector is perpendicular to the edge vector of the target geofence, and the edge vector is The vector formed by connecting two adjacent boundary vertices of the target geofence, N is an integer greater than 2;
根据所述第一位置点与目标边界顶点连接形成的向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,其中,所述目标边界顶点为所述目标地理围栏中的部分或全部边界顶点,所述目标法向量为与所述目标边界顶点处的边向量垂直的法向量。The positional relationship between the first position point and the target geofence is determined according to the dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector, wherein the target boundary vertex is the For some or all boundary vertices in the target geofence, the target normal vector is a normal vector perpendicular to the edge vector at the target boundary vertex.
第二方面,本申请实施例提供了一种地理围栏检测装置,包括: In a second aspect, embodiments of the present application provide a geofence detection device, including:
获取模块,用于获取电子设备当前所处的第一位置点;The acquisition module is used to acquire the first position point where the electronic device is currently located;
第一确定模块,用于分别确定目标地理围栏的各个法向量,其中,所述目标地理围栏由N个边界顶点按预设顺序连接形成,所述法向量与所述目标地理围栏的边向量垂直,所述边向量为所述目标地理围栏的相邻两个边界顶点连接形成的向量,N为大于2的整数;The first determination module is used to determine each normal vector of the target geographical fence, wherein the target geographical fence is formed by connecting N boundary vertices in a preset order, and the normal vector is perpendicular to the edge vector of the target geographical fence. , the edge vector is a vector formed by connecting two adjacent boundary vertices of the target geofence, and N is an integer greater than 2;
第二确定模块,用于根据所述第一位置点与目标边界顶点连接形成的向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,其中,所述目标边界顶点为所述目标地理围栏中的部分或全部边界顶点,所述目标法向量为与所述目标边界顶点处的边向量垂直的法向量。The second determination module is used to determine the positional relationship between the first position point and the target geofence according to the dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector, wherein, The target boundary vertex is part or all of the boundary vertices in the target geofence, and the target normal vector is a normal vector perpendicular to an edge vector at the target boundary vertex.
第三方面,本申请实施例提供了一种电子设备,该电子设备包括处理器和存储器,所述存储器存储可在所述处理器上运行的程序或指令,所述程序或指令被所述处理器执行时实现如第一方面所述的地理围栏检测方法的步骤。In a third aspect, embodiments of the present application provide an electronic device. The electronic device includes a processor and a memory. The memory stores programs or instructions that can be run on the processor. The programs or instructions are processed by the processor. When the processor is executed, the steps of the geofence detection method described in the first aspect are implemented.
第四方面,本申请实施例提供了一种可读存储介质,所述可读存储介质上存储程序或指令,所述程序或指令被处理器执行时实现如第一方面所述的地理围栏检测方法的步骤。In the fourth aspect, embodiments of the present application provide a readable storage medium that stores programs or instructions. When the programs or instructions are executed by a processor, the geofence detection as described in the first aspect is implemented. Method steps.
第五方面,本申请实施例提供了一种芯片,所述芯片包括处理器和通信接口,所述通信接口和所述处理器耦合,所述处理器用于运行程序或指令,实现如第一方面所述的地理围栏检测方法。In a fifth aspect, embodiments of the present application provide a chip. The chip includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the first aspect. The geofence detection method.
第六方面,本申请实施例提供一种计算机程序产品,该计算机程序产品被存储在存储介质中,该计算机程序产品被至少一个处理器执行以实现如第一方面所述的地理围栏检测方法。In a sixth aspect, embodiments of the present application provide a computer program product. The computer program product is stored in a storage medium. The computer program product is executed by at least one processor to implement the geofence detection method as described in the first aspect.
在本申请实施例中,获取电子设备当前所处的第一位置点;分别确定目标地理围栏的各个法向量,其中,所述目标地理围栏由N个边界顶点按预设顺序连接形成,所述法向量与所述目标地理围栏的边向量垂直,所述边向量为所述目标地理围栏的相邻两个边界顶点连接形成的向量,N为大于2的整数;根据所述第一位置点与目标边界顶点连接形成的向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,其中,所述目标边界顶点为所述目标地理围栏中的部分或全部边界顶点,所述目标法向量为与所述目标边界顶点处的边向量垂直的法向量。这样,通过向量法来对电子设备进行地理围栏检测,避免了传统交叉数法中涉及的复杂运算,而只用到了简单的四则运算,从而能够有效降低围栏检测的计算复杂度,极大减少计算量,提升检测效率。In this embodiment of the present application, the first location point where the electronic device is currently located is obtained; each normal vector of the target geofence is determined respectively, wherein the target geofence is formed by connecting N boundary vertices in a preset order, and the The normal vector is perpendicular to the edge vector of the target geofence, the edge vector is a vector formed by connecting two adjacent boundary vertices of the target geofence, and N is an integer greater than 2; according to the first position point and The dot product of the vector formed by connecting the target boundary vertices and the target normal vector determines the positional relationship between the first position point and the target geofence, wherein the target boundary vertex is part or all of the target geofence. Boundary vertex, the target normal vector is a normal vector perpendicular to the edge vector at the target boundary vertex. In this way, the vector method is used to detect geofences on electronic devices, avoiding the complex operations involved in the traditional cross number method, and only using four simple arithmetic operations, which can effectively reduce the computational complexity of fence detection and greatly reduce calculations. quantity and improve detection efficiency.
附图说明Description of the drawings
图1是本申请实施例提供的POI的多边形地理围栏的示意图;Figure 1 is a schematic diagram of a polygonal geofence of a POI provided by an embodiment of the present application;
图2是相关技术中采用交叉数法进行地理围栏检测的示意图;Figure 2 is a schematic diagram of geofence detection using the cross number method in related technologies;
图3是相关技术中拆分多边形地理围栏成多个圆形围栏的示意图;Figure 3 is a schematic diagram of splitting a polygonal geofence into multiple circular fences in the related art;
图4是本申请实施例提供的地理围栏检测方法的流程图之一;Figure 4 is one of the flow charts of the geofence detection method provided by the embodiment of the present application;
图5是本申请实施例提供的多边形地理围栏的边向量和对应法向量的示意图; Figure 5 is a schematic diagram of the edge vectors and corresponding normal vectors of a polygonal geofence provided by an embodiment of the present application;
图6是本申请实施例提供的采用向量法进行多边形地理围栏检测的算法流程图;Figure 6 is an algorithm flow chart for polygon geofence detection using the vector method provided by the embodiment of the present application;
图7是本申请实施例提供的地理围栏检测方法的流程图之二;Figure 7 is the second flow chart of the geofence detection method provided by the embodiment of the present application;
图8是本申请实施例提供的多边形地理围栏中运动方向向量与对应法线分割围栏区域的示意图;Figure 8 is a schematic diagram of the movement direction vector and the corresponding normal dividing the fence area in the polygonal geofence provided by the embodiment of the present application;
图9是本申请实施例提供的运动方向向量与法线坐标旋转示意图;Figure 9 is a schematic diagram of the movement direction vector and normal coordinate rotation provided by the embodiment of the present application;
图10是本申请实施例提供的地理围栏检测方法的流程图之三;Figure 10 is the third flow chart of the geofence detection method provided by the embodiment of the present application;
图11是本申请实施例提供的多边形地理围栏内一点沿各个方向的距离示意图;Figure 11 is a schematic diagram of the distance of a point in various directions within a polygonal geofence provided by an embodiment of the present application;
图12是本申请实施例提供的地理围栏检测方法的流程图之四;Figure 12 is the fourth flow chart of the geofence detection method provided by the embodiment of the present application;
图13是本申请实施例提供的地理围栏检测装置的结构示意图;Figure 13 is a schematic structural diagram of a geofence detection device provided by an embodiment of the present application;
图14是本申请实施例提供的电子设备的结构示意图;Figure 14 is a schematic structural diagram of an electronic device provided by an embodiment of the present application;
图15是本申请实施例提供的电子设备的硬件结构示意图。Figure 15 is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present application.
具体实施方式Detailed ways
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员获得的所有其他实施例,都属于本申请保护的范围。The technical solutions in the embodiments of the present application will be clearly described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, but not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art fall within the scope of protection of this application.
本申请的说明书和权利要求书中的术语“第一”、“第二”等是用于区别类似的对象,而不用于描述特定的顺序或先后次序。应该理解这样使用的术语在适当情况下可以互换,以便本申请的实施例能够以除了在这里图示或描述的那些以外的顺序实施,且“第一”、“第二”等所区分的对象通常为一类,并不限定对象的个数,例如第一对象可以是一个,也可以是多个。此外,说明书以及权利要求中“和/或”表示所连接对象的至少其中之一,字符“/”,一般表示前后关联对象是一种“或”的关系。The terms "first", "second", etc. in the description and claims of this application are used to distinguish similar objects and are not used to describe a specific order or sequence. It is to be understood that the terms so used are interchangeable under appropriate circumstances so that the embodiments of the application can be practiced in sequences other than those illustrated or described herein, and that "first," "second," etc. are distinguished Objects are usually of one type, and the number of objects is not limited. For example, the first object can be one or multiple. In addition, "and/or" in the description and claims indicates at least one of the connected objects, and the character "/" generally indicates that the related objects are in an "or" relationship.
为使本申请实施例更为清楚,下面先对本申请涉及的相关技术知识进行如下介绍:In order to make the embodiments of this application clearer, the relevant technical knowledge involved in this application is first introduced as follows:
无线保真(Wireless Fidelity,WiFi)是一种无线局域网接入技术,是手机等电子设备无线连接网络的方式之一;Wireless Fidelity (WiFi) is a wireless LAN access technology and one of the ways for mobile phones and other electronic devices to connect to the network wirelessly;
接入点(Access Point,AP)是WiFi构建的无线局域网络的核心设备,用于桥接局域网和互联网,所有WiFi设备必须连接AP设备才能上网。在日常生活中,无线路由器、网关是常见的AP设备,智能手机开启WiFi热点也可变成AP设备;Access Point (AP) is the core device of the wireless LAN built by WiFi. It is used to bridge the LAN and the Internet. All WiFi devices must be connected to the AP device to access the Internet. In daily life, wireless routers and gateways are common AP devices, and smartphones can also become AP devices when turning on WiFi hotspots;
全球定位系统(Global Positioning System,GPS)属于卫星定位体系的一种。目前智能手机普遍集成GPS芯片模块,可以接收和解算GPS卫星广播的信号,从而确定位置;Global Positioning System (GPS) is a type of satellite positioning system. Currently, smartphones generally integrate GPS chip modules, which can receive and interpret signals broadcast by GPS satellites to determine their location;
兴趣点(Point of Interest,POI),在地理信息系统中,一个兴趣点代表一个地理单元,例如一个商铺、一栋房子、一个公交站等等。Point of Interest (POI), in geographic information systems, a point of interest represents a geographical unit, such as a shop, a house, a bus stop, etc.
地理围栏检测是智能电子设备架构(Framework)层集成的一项重要功能,是将底层的地理位置信息转化为用户的空间和情景的桥梁,对于用户的情景感知、用户画像、重要信息提醒等业务起着重要的支撑业务。 Geofence detection is an important function integrated in the framework layer of intelligent electronic devices. It is a bridge that converts the underlying geographical location information into the user's space and context. It is used for users' situation awareness, user portraits, important information reminders and other services. Plays an important supporting role.
目前,大部分的地理围栏都被设计成圆形围栏,即地理围栏的边界是一个圆形,由中心位置坐标加半径组成。圆形围栏的优势是简单,尤其是围栏检测算法,只需判断当前定位位置与围栏中心位置的距离是否小于围栏半径即可判别是否进入围栏。但是圆形围栏也有其固有的弊端,其主要弊端就是不能与真实的地理POI的边界重合,导致在真实的应用场景中经常出现误判或漏判,影响了地理围栏检测的准确性。在实际的应用场景中,真实的地理POI边界往往是由一些离散的位置点以及其对应的连线所构成的一个闭合的不规则多边形,为了提升了地理围栏检测本身的准确性,更好地支撑与之相关的上层业务,对于多边形地理围栏的检测变得十分重要。At present, most geofences are designed as circular fences, that is, the boundary of the geofence is a circle, consisting of the center position coordinates and the radius. The advantage of the circular fence is that it is simple, especially the fence detection algorithm. It only needs to determine whether the distance between the current position and the center of the fence is less than the radius of the fence to determine whether to enter the fence. However, circular fences also have their inherent drawbacks. The main drawback is that they cannot coincide with the boundaries of real geographical POIs, resulting in frequent misjudgments or missed determinations in real application scenarios, affecting the accuracy of geofence detection. In actual application scenarios, the real geographic POI boundary is often a closed irregular polygon composed of some discrete location points and their corresponding connections. In order to improve the accuracy of geofence detection itself, it is better to Supporting related upper-layer services has become very important for the detection of polygonal geofences.
多边形的地理围栏由一个位置点的数列{Pn}组成,{Pn}={P1,P2,…,PN},其中,P1、P2…PN都代表多边形边界的顶点,它们按照一定的顺序排列(通常是按照逆时针顺序排列),这个数列的第一项和最后一项代表的是同一个点,即P1=PN。这样,这些离散点集构成的数列就组成了一个闭合的多边形,而相邻两点所组成的边PiPi+1(i=1,2,…,N-1)就代表多边形地理围栏的一条边。一个实际商超POI的多边形地理围栏10可如图1所示。The polygonal geofence consists of a sequence of position points {P n }, {P n } = {P 1 , P 2 ,..., P N }, where P 1 , P 2 ...P N all represent the vertices of the polygon boundary , they are arranged in a certain order (usually in counterclockwise order), and the first and last items of this sequence represent the same point, that is, P 1 =P N . In this way, the sequence composed of these discrete point sets forms a closed polygon, and the edge P i P i+1 (i=1,2,...,N-1) formed by two adjacent points represents the polygonal geofence. an edge of. An actual polygonal geofence 10 of a shopping mall POI can be shown in Figure 1 .
目前,判断点是否在多边形地理围栏内部主要采用交叉数法(Crossing Number),也称为奇偶校验法,如图2所示,其是判断从点P开始出发的射线穿过多边形地理围栏边界的次数,如果为奇数,则确定点P在多边形地理围栏内部;如果为偶数,则确定点P在多边形地理围栏外部。Currently, the Crossing Number method, also known as the parity check method, is mainly used to determine whether a point is inside a polygonal geofence. As shown in Figure 2, it is used to determine whether a ray starting from point P passes through the polygonal geofence boundary. If it is an odd number, it is determined that point P is inside the polygonal geofence; if it is an even number, it is determined that point P is outside the polygonal geofence.
然而,采用交叉数法判断点是否在多边形地理围栏内部的技术存在如下缺陷:However, the technology that uses the intersection number method to determine whether a point is inside a polygonal geofence has the following shortcomings:
1)计算量巨大:交叉数法涉及到判断射线与线段是否相交的问题,而要判断这个问题涉及到矩阵的求逆运算,这种运算的计算量是比较大的,而且还要从点P出发的至少两条射线与多边形地理围栏的所有边界都要一一进行运算,这就更加大了计算量。而地理围栏这类业务,由于隐私保护的限制,围栏的检测基本上都是放在终端侧进行的,这就意味着这种运算也要在终端侧进行,而巨大的计算量势必会引起终端较大的功耗开销;1) The amount of calculation is huge: The intersection number method involves the problem of judging whether the ray and the line segment intersect, and judging this problem involves the inversion operation of the matrix. The amount of calculation of this operation is relatively large, and it also needs to start from point P. At least two starting rays and all boundaries of the polygonal geofence must be calculated one by one, which increases the calculation amount. For services such as geofencing, due to privacy protection restrictions, fence detection is basically done on the terminal side, which means that this calculation must also be performed on the terminal side, and the huge amount of calculation will inevitably cause the terminal to Large power consumption overhead;
2)计算结果不稳定:如上所述,交叉数法中判断射线与线段是否相交涉及到矩阵的求逆运算,而一旦所求矩阵是病态矩阵,条件数很大,那么在数据上一点小小的扰动就会引起计算结果巨大的波动,导致计算结果的错误;2) The calculation results are unstable: As mentioned above, judging whether the ray and the line segment intersect in the cross number method involves the inversion operation of the matrix. Once the matrix required is an ill-conditioned matrix and the condition number is very large, then there will be a small problem in the data. The disturbance will cause huge fluctuations in the calculation results, leading to errors in the calculation results;
3)不适用于某些特殊情况:例如,如果从点P出发的射线正好与多边形边界的某一条边重合,那么交叉数法的结论将不再适用。但是,在现实的应用场景中,这种特殊情况并不能完全避免。3) Not applicable to some special cases: for example, if the ray starting from point P happens to coincide with a certain edge of the polygon boundary, then the conclusion of the intersection number method will no longer apply. However, in real application scenarios, this special situation cannot be completely avoided.
鉴于此,传统的交叉数法在实际的多边形地理围栏检测中应用受限,开发者需要采用优化的替代算法进行检测。In view of this, the traditional intersection number method has limited application in actual polygon geofence detection, and developers need to use optimized alternative algorithms for detection.
传统交叉数法的改进替代算法通常采用拆分近似的方法,将一个完整的多边形地理围栏拆分成若干个简单形状的地理围栏进行近似替代,从而降低地理围栏检测算法的计算复杂度。例如,如图3所示,将一个完整的多边形地理围栏生成多个圆形地理围栏以覆盖多边形地理围栏定义的地理区域,对所述多个圆形地理围栏进行监控,以检测进入任一所述 圆形地理围栏的边界的用户设备的当前位置。The improved replacement algorithm of the traditional cross number method usually uses the split approximation method to split a complete polygonal geofence into several simple-shaped geofences for approximate replacement, thereby reducing the computational complexity of the geofence detection algorithm. For example, as shown in Figure 3, a complete polygonal geofence is generated into multiple circular geofences to cover the geographical area defined by the polygonal geofence, and the multiple circular geofences are monitored to detect entry into any describe The current location of the user's device that bounds the circular geofence.
然而,图3所示的技术方案也存在其固有的缺陷,具体有以下几点:However, the technical solution shown in Figure 3 also has its inherent flaws, specifically the following points:
1)将多边形地理围栏拆分成多个圆形围栏同样需要较大的计算量,该技术方案是采用内部插值的方式选择圆形围栏的中心点以及计算对应的半径,这同样涉及较为复杂的算法。另外,拆分出来的圆形围栏的数量与多边形围栏的面积成正比,这对于那些占地面积较大,但边界较为简单(或者说多边形围栏边界顶点数量较少)的多边形地理围栏来说反而增大了计算量,变得得不偿失;1) Splitting a polygonal geofence into multiple circular fences also requires a large amount of calculation. The technical solution is to use internal interpolation to select the center point of the circular fence and calculate the corresponding radius, which also involves relatively complex calculations. algorithm. In addition, the number of split circular fences is proportional to the area of the polygonal fence, which is the opposite for those polygonal geofences that occupy a larger area but have simpler boundaries (or a smaller number of vertices on the polygonal fence boundary). The amount of calculation is increased and the gain outweighs the gain;
2)用圆形围栏模拟多边形地理围栏仍然无法完全的拟合出多边形地理围栏的准确边界,虽然在围栏边界上的圆形围栏的半径通常比较小,但仍有一定概率跑到多边形地理围栏的边界范围之外,这在一定程度上也会影响多边形地理围栏的准确性。2) Using a circular fence to simulate a polygonal geofence still cannot completely fit the accurate boundary of the polygonal geofence. Although the radius of the circular fence on the boundary of the fence is usually relatively small, there is still a certain probability that it will reach the polygonal geofence. Outside the bounds, this will also affect the accuracy of polygon geofencing to some extent.
为解决上述技术方案中存在的技术问题,本申请设计一种多边形地理围栏的检测方法,具体来说是采用向量计算的方法判断点P是否位于多边形地理围栏内部。向量法检测多边形地理围栏避免了传统交叉数法中涉及的复杂运算,能够有效降低围栏检测的计算复杂度,提升检测的效率以及降低设备功耗。另外,向量法进行多边形围栏检测是严格按照多边形的真实边界进行计算判断,从而避免了拆分近似法中用圆形围栏或者矩形围栏进行近似模拟过程中围栏边界与实际多边形围栏边界不一致的问题。In order to solve the technical problems existing in the above technical solution, this application designs a polygonal geofence detection method. Specifically, the vector calculation method is used to determine whether point P is located inside the polygonal geofence. The vector method for detecting polygonal geofences avoids the complex operations involved in the traditional intersection number method, and can effectively reduce the computational complexity of fence detection, improve detection efficiency, and reduce equipment power consumption. In addition, the vector method for polygonal fence detection is calculated and judged strictly according to the real boundary of the polygon, thus avoiding the problem of inconsistency between the fence boundary and the actual polygonal fence boundary during the approximation simulation using a circular fence or a rectangular fence in the split approximation method.
下面结合附图,通过具体的实施例及其应用场景对本申请实施例提供的地理围栏检测方法进行详细地说明。The geofence detection method provided by the embodiments of the present application will be described in detail below with reference to the accompanying drawings through specific embodiments and application scenarios.
请参见图4,图4为本申请实施例提供的地理围栏检测方法的流程图,如图4所示,该方法包括以下步骤:Please refer to Figure 4. Figure 4 is a flow chart of a geofence detection method provided by an embodiment of the present application. As shown in Figure 4, the method includes the following steps:
步骤401、获取电子设备当前所处的第一位置点。Step 401: Obtain the first location point where the electronic device is currently located.
本申请实施例中,在需要对电子设备进行地理围栏检测,以判断所述电子设备用户是否进入目标地理围栏内部时,可以获取所述电子设备当前所处的位置信息,如通过定位所述电子设备的位置,获取所述电子设备在当前时刻所处的位置点,即第一位置点。In the embodiment of the present application, when it is necessary to perform geofence detection on an electronic device to determine whether the user of the electronic device has entered the target geofence, the current location information of the electronic device can be obtained, such as by locating the electronic device. The position of the device is to obtain the position point where the electronic device is located at the current moment, that is, the first position point.
步骤402、分别确定目标地理围栏的各个法向量,其中,所述目标地理围栏由N个边界顶点按预设顺序连接形成,所述法向量与所述目标地理围栏的边向量垂直,所述边向量为所述目标地理围栏的相邻两个边界顶点连接形成的向量,N为大于2的整数。Step 402: Determine each normal vector of the target geofence respectively, wherein the target geofence is formed by connecting N boundary vertices in a preset order, the normal vector is perpendicular to the edge vector of the target geofence, and the edge The vector is a vector formed by connecting two adjacent boundary vertices of the target geofence, and N is an integer greater than 2.
上述目标地理围栏可以是某个POI的地理围栏,例如,可以是所述电子设备附近的某个POI的地理围栏。所述目标地理围栏可以为一多边形地理围栏,包括N个边界顶点,是由所述N个边界顶点按一定顺序连接形成的闭合多边形区域,例如,所述N个边界顶点分别为P1、P2…PN,则可以将所述N个边界顶点按序号正序连接,即将P1与P2连接,P2与P3连接,…PN-1与PN连接,PN与P1连接,或者,也可以将所述N个边界顶点按序号反序连接,即将P1与PN连接,PN与PN-1连接,…P3与P2连接,P2与P1连接,从而得到一闭合的多边形地理围栏。The above-mentioned target geofence may be a geofence of a certain POI, for example, it may be a geofence of a certain POI near the electronic device. The target geofence may be a polygonal geofence, including N boundary vertices, which is a closed polygonal area formed by connecting the N boundary vertices in a certain order. For example, the N boundary vertices are P 1 and P respectively. 2 ...P N , then the N boundary vertices can be connected in positive order, that is, P 1 is connected to P 2 , P 2 is connected to P 3 ,...P N-1 is connected to PN , and P N is connected to P 1 Connect, or you can also connect the N boundary vertices in reverse order, that is, connect P 1 to PN , connect PN to PN-1 ,...P 3 to P 2 , and connect P 2 to P 1. , thus obtaining a closed polygonal geofence.
所述目标地理围栏的边向量可以是指所述目标地理围栏的相邻两个边界顶点连接形 成的向量,例如,如图5所示,相邻两个边界顶点可以按逆时针方向连接形成边向量: 当然,相邻两个边界顶点也可以按顺时针方向连接形成边向量 The edge vector of the target geofence may refer to the connection shape of two adjacent boundary vertices of the target geofence. For example, as shown in Figure 5, two adjacent boundary vertices can be connected in a counterclockwise direction to form an edge vector: Of course, two adjacent boundary vertices can also be connected in a clockwise direction to form an edge vector.
所述目标地理围栏的各个法向量,则可以是指对所述目标地理围栏的各个边向量分别作与之垂直的向量,并且各法向量的方向可以是对应边向量的方向逆时针或顺时针旋转90°得到。因此,上述分别确定目标地理围栏的各个法向量,可以是确定所述目标地理围栏的各个边向量,并根据坐标变换公式,对所述各个边向量进行坐标转换,从而得到对应的各个法向量,其中,所述坐标变换公式基于旋转角度确定,如逆时针旋转90°则旋转角度为90°,顺时针旋转90°则旋转角度为-90°。Each normal vector of the target geofence may refer to a vector perpendicular to each edge vector of the target geofence, and the direction of each normal vector may be counterclockwise or clockwise to the direction of the corresponding edge vector. Obtained by rotating 90°. Therefore, the above-mentioned determination of each normal vector of the target geofence may be to determine each edge vector of the target geofence, and perform coordinate transformation on each edge vector according to the coordinate transformation formula, thereby obtaining each corresponding normal vector, The coordinate transformation formula is determined based on the rotation angle. For example, if the object is rotated 90° counterclockwise, the angle of rotation is 90°, and if rotated 90° clockwise, the angle of rotation is -90°.
步骤403、根据所述第一位置点与目标边界顶点连接形成的向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,其中,所述目标边界顶点为所述目标地理围栏中的部分或全部边界顶点,所述目标法向量为与所述目标边界顶点处的边向量垂直的法向量。Step 403: Determine the positional relationship between the first position point and the target geofence according to the dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector, wherein the target boundary vertex is part or all of the boundary vertices in the target geofence, and the target normal vector is a normal vector perpendicular to the edge vector at the target boundary vertex.
本申请实施例中,可根据所述第一位置点与所述目标地理围栏中的任一边界顶点连接形成的目标向量,与该边界顶点所在边向量对应的法向量的夹角,确定所述第一位置点与所述目标地理围栏的位置关系,也即确定所述第一位置点是位于所述目标地理围栏的内部还是外部,例如,若该法向量指向所述目标地理围栏内部,所述目标向量为该边界顶点指向所述第一位置点的向量,则对于位于所述目标地理围栏内部的位置点,所述目标向量与所述法向量的夹角为锐角,位于所述目标地理围栏外部的位置点,所述目标向量与所述法向量的夹角为钝角;或者,若该法向量指向所述目标地理围栏外部,所述目标向量为该边界顶点指向所述第一位置点的向量,则对于位于所述目标地理围栏内部的位置点,所述目标向量与所述法向量的夹角为钝角,对于位于所述目标地理围栏外部的位置点,所述目标向量与所述法向量的夹角为锐角。而为了确定两个向量的夹角是否为锐角,可以根据两个向量的点积是否大于0来确定,若点积大于0,则可以确定两个向量的夹角为锐角,反之则为钝角。In the embodiment of the present application, the angle between the target vector formed by connecting the first location point and any boundary vertex in the target geofence and the normal vector corresponding to the edge vector where the boundary vertex is located can be determined. The positional relationship between the first position point and the target geofence, that is, determining whether the first position point is located inside or outside the target geofence. For example, if the normal vector points to the inside of the target geofence, then The target vector is a vector whose boundary vertex points to the first location point. Then, for the location point located inside the target geographical fence, the angle between the target vector and the normal vector is an acute angle, and the angle between the target vector and the normal vector is an acute angle. The position point outside the fence, the angle between the target vector and the normal vector is an obtuse angle; or, if the normal vector points outside the target geofence, the target vector is the boundary vertex pointing to the first position point vector, then for a position point located inside the target geofence, the angle between the target vector and the normal vector is an obtuse angle; for a position point located outside the target geofence, the target vector and the normal vector The angle between the normal vectors is an acute angle. In order to determine whether the angle between two vectors is an acute angle, it can be determined based on whether the dot product of the two vectors is greater than 0. If the dot product is greater than 0, it can be determined that the angle between the two vectors is an acute angle, and vice versa.
因此,本申请实施例中可基于上述原理,根据所述第一位置点与目标边界顶点连接形成的向量与目标法向量的点积,确定所述第一位置点与目标边界顶点连接形成的向量与所述目标法向量的夹角是否为锐角,进而结合所述第一位置点与目标边界顶点连接形成的向量的指向与所述目标法向量的指向,确定所述第一位置点与所述目标地理围栏的位置关系,即确定所述第一位置点是位于所述目标地理围栏内部还是外部。Therefore, in the embodiment of the present application, based on the above principle, the vector formed by connecting the first position point and the target boundary vertex can be determined according to the dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector. Whether the angle between the first position point and the target normal vector is an acute angle, and then combined with the direction of the vector formed by connecting the first position point and the target boundary vertex and the direction of the target normal vector, determine the relationship between the first position point and the The positional relationship of the target geofence, that is, determining whether the first location point is located inside or outside the target geofence.
其中,所述目标边界顶点可以包括所述目标地理围栏的所有边界顶点,也可以仅包括所述目标地理围栏的部分边界顶点,即一种实施方式中,可以根据所述第一位置点与所述目标地理围栏的每一边界顶点连接形成的向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,该实施方式适用于首次判断所述电子设备是否进入所述目标地理围栏内部的情况;另一种实施方式中,为节省计算量,可以根据所述第一位置点 与所述目标地理围栏的满足特定条件的目标边界顶点(如与所述第一位置点位于同侧的边界顶点)连接形成的向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,该实施方式适用于在所述电子设备已进入所述目标地理围栏内部,后续根据实时定位判断所述电子设备是否仍处于所述目标地理围栏内部的情况。所述目标边界顶点处的边向量可以是指以所述目标边界顶点为起点的边向量。Wherein, the target boundary vertices may include all boundary vertices of the target geofence, or may only include part of the boundary vertices of the target geofence. That is, in one embodiment, the target boundary vertices may be determined according to the first location point and the target geofence. The dot product of the vector formed by connecting each boundary vertex of the target geofence and the target normal vector determines the positional relationship between the first position point and the target geofence. This implementation is suitable for first determining whether the electronic device Entering inside the target geofence; in another implementation, in order to save calculations, the first location point can be The dot product of the vector formed by connecting the target boundary vertex of the target geofence that meets certain conditions (such as the boundary vertex on the same side as the first location point) and the target normal vector determines the relationship between the first location point and Regarding the positional relationship of the target geofence, this embodiment is applicable to the situation where the electronic device has entered the target geofence and subsequently determines whether the electronic device is still inside the target geofence based on real-time positioning. The edge vector at the target boundary vertex may refer to an edge vector starting from the target boundary vertex.
可选地,所述法向量指向所述目标地理围栏的内部;Optionally, the normal vector points to the interior of the target geofence;
所述步骤403包括:The step 403 includes:
在第一向量与所述目标法向量的点积大于0的情况下,确定所述第一位置点位于所述目标地理围栏内部,其中,所述第一向量为自所述目标边界顶点指向所述第一位置点的向量;When the dot product of the first vector and the target normal vector is greater than 0, it is determined that the first location point is located inside the target geofence, wherein the first vector points from the target boundary vertex to the target geofence. The vector of the first position point;
在所述第一向量与所述目标法向量的点积小于0的情况下,确定所述第一位置点位于所述目标地理围栏外部。When the dot product of the first vector and the target normal vector is less than 0, it is determined that the first location point is located outside the target geofence.
一种实施方式中,在确定所述目标地理围栏的各个边向量对应的法向量时,可以保证各个法向量均指向所述目标地理围栏的内部,具体地,所述目标地理围栏的各个边向量是相邻两个边界顶点按逆时针方向连接形成时,可以将各个边向量逆时针旋转90°,来得到对应的各个法向量,使得各个法向量均指向所述目标地理围栏内部;或者,所述目标地理围栏的各个边向量是相邻两个边界顶点按顺时针方向连接形成时,可以将各个边向量顺时针旋转90°,来得到对应的各个法向量,使得各个法向量均指向所述目标地理围栏内部。In one embodiment, when determining the normal vector corresponding to each edge vector of the target geofence, it can be ensured that each normal vector points to the inside of the target geofence. Specifically, each edge vector of the target geofence When two adjacent boundary vertices are connected in a counterclockwise direction, each edge vector can be rotated 90° counterclockwise to obtain the corresponding normal vectors, so that each normal vector points to the inside of the target geofence; or, When each edge vector of the target geofence is formed by connecting two adjacent boundary vertices in a clockwise direction, each edge vector can be rotated 90° clockwise to obtain the corresponding normal vectors, so that each normal vector points to the described Inside the target geofence.
而所述第一位置点与目标边界顶点连接形成的向量可以是自所述目标边界顶点指向所述第一位置点的第一向量,这样,若所述第一位置点位于所述目标地理围栏内部,则所述第一向量与所述目标法向量的夹角为锐角,即小于90°,相应地,所述第一向量与所述目标法向量的点积大于0,若所述第一位置点位于所述目标地理围栏外部,则所述第一向量与所述目标法向量的夹角为钝角,即大于90°,相应地,所述第一向量与所述目标法向量的点积小于0。The vector formed by connecting the first location point and the target boundary vertex may be a first vector pointing from the target boundary vertex to the first location point. In this way, if the first location point is located in the target geofence inside, then the angle between the first vector and the target normal vector is an acute angle, that is, less than 90°. Correspondingly, the dot product of the first vector and the target normal vector is greater than 0. If the first vector If the location point is located outside the target geofence, then the angle between the first vector and the target normal vector is an obtuse angle, that is, greater than 90°. Correspondingly, the dot product of the first vector and the target normal vector is Less than 0.
因此,该实施方式中,可以通过计算所述第一向量与所述目标法向量的点积,并与0进行比较,便可确定所述第一位置点是位于所述目标地理围栏内部还是外部,具体地,在所述第一向量与所述目标法向量的点积大于0的情况下,可以确定所述第一位置点位于所述目标地理围栏内部,在所述第一向量与所述目标法向量的点积小于0的情况下,可以确定所述第一位置点位于所述目标地理围栏外部。另外,需说明的是,实际场景中,也可能存在所述电子设备位于所述目标地理围栏边界,即所述第一向量与所述目标法向量的夹角为直角,即等于90°的情况,因此,可在所述第一向量与所述目标法向量的点积等于0的情况下,确定所述第一位置点位于所述目标地理围栏边界。Therefore, in this embodiment, by calculating the dot product of the first vector and the target normal vector and comparing it with 0, it can be determined whether the first location point is located inside or outside the target geofence. , specifically, when the dot product of the first vector and the target normal vector is greater than 0, it can be determined that the first location point is located inside the target geofence. When the dot product of the target normal vector is less than 0, it can be determined that the first location point is located outside the target geofence. In addition, it should be noted that in actual scenarios, there may also be situations where the electronic device is located at the boundary of the target geofence, that is, the angle between the first vector and the target normal vector is a right angle, which is equal to 90°. , therefore, it can be determined that the first location point is located at the boundary of the target geofence when the dot product of the first vector and the target normal vector is equal to 0.
这样,该实施方式中,在使所述目标地理围栏的各个法向量均指向所述目标地理围栏的内部的情况下,通过比较自所述目标边界顶点指向所述第一位置点的向量与所述目标法 向量的点积是否大于0,即可快速地确定所述电子设备当前所处位置点与所述目标地理围栏的位置关系,该方式计算量小且计算结果准确。In this way, in this embodiment, when each normal vector of the target geofence points to the inside of the target geofence, by comparing the vector pointing from the target boundary vertex to the first position point with the vector goal statement method Whether the dot product of the vector is greater than 0, the positional relationship between the current location point of the electronic device and the target geofence can be quickly determined. This method has a small amount of calculation and accurate calculation results.
本申请的核心发明点是采用向量法进行多边形地理围栏检测,下面详细介绍通过向量法判断点P是否位于多边形地理围栏内部的算法原理。The core invention of this application is to use the vector method to detect polygonal geofences. The following is a detailed introduction to the algorithm principle of using the vector method to determine whether point P is located inside a polygonal geofence.
通过向量法判断点P是否位于多边形地理围栏内部需满足如下先决条件:Using the vector method to determine whether point P is located inside a polygonal geofence requires the following prerequisites:
1)多边形地理围栏的边界顶点数列{Pn}={P1,P2,…,PN}是按照一定的顺序排列,为了叙述方便,本申请技术方案中可以规定多边形地理围栏的边界顶点数列是按照逆时针方向排列的;若按照顺时针方向排列,通过等价变换也可以实现相同的功能;1) The boundary vertex sequence of the polygonal geofence {P n } = {P 1 , P 2 ,..., P N } is arranged in a certain order. For the convenience of description, the boundary of the polygonal geofence can be specified in the technical solution of this application The vertex array is arranged in a counterclockwise direction; if it is arranged in a clockwise direction, the same function can be achieved through equivalent transformation;
2)多边形地理围栏的边界顶点数列的第一项和最后一项是相同的,即P1=PN,也就是说多边形地理围栏的形状是封闭的。2) The first and last items of the boundary vertex sequence of the polygonal geofence are the same, that is, P 1 =P N , which means that the shape of the polygonal geofence is closed.
在实际应用场景中,POI的地理围栏数据基本上都符合上述两个条件。可以设多边形地理围栏边界顶点数列中每一项的坐标为Pi=(xi,yi),i=1,2,3…,N,那么相邻两个边界顶点组成的边向量可记为i=1,2,3,…,N-1,边向量对应的法向量可记为由于多边形地理围栏的边界顶点数列是按照逆时针顺序排列的,可以认为法向量是根据边界顶点数据所在的坐标系经过逆时针旋转90°得到的,则坐标变换公式为:
In actual application scenarios, POI geofence data basically meets the above two conditions. The coordinates of each item in the polygonal geofence boundary vertex sequence can be set to P i = (x i , y i ), i = 1, 2, 3..., N. Then the edge vector composed of two adjacent boundary vertices can be recorded as i=1,2,3,…,N-1, edge vector The corresponding normal vector can be recorded as Since the boundary vertex array of the polygonal geofence is arranged in counterclockwise order, the normal vector can be considered It is obtained by rotating 90° counterclockwise based on the coordinate system where the boundary vertex data is located. The coordinate transformation formula is:
其中,(x′,y′)为坐标旋转后在新坐标系下的坐标值,θ为旋转角度,在这里,求法向量对应的旋转角度为θ=π/2。代入上述坐标变换公式,可得到边向量对应的法向量为:
Among them, (x′, y′) is the coordinate value in the new coordinate system after coordinate rotation, and θ is the rotation angle. Here, the rotation angle corresponding to the normal vector is θ = π/2. Substituting into the above coordinate transformation formula, we can get the edge vector The corresponding normal vector for:
多边形地理围栏的边向量和对应的法向量可以如图5所示,从图5中可以看出,多边形地理围栏的所有边向量对应的法向量都指向该多边形地理围栏的内部。The edge vectors and corresponding normal vectors of the polygonal geofence can be shown in Figure 5. It can be seen from Figure 5 that the normal vectors corresponding to all the edge vectors of the polygonal geofence point to the inside of the polygonal geofence.
对于任一点P=(x,y),可知如果点P位于多边形地理围栏的内部,那么点P与任意边界顶点Pi(i=1,2,…,N)所构成的边向量与该边界顶点Pi所在边向量对应的法向量的夹角为锐角,即小于90°;反之,如果点P位于多边形地理围栏的外部,那么边向量与该顶点Pi所在边向量对应的法向量的夹角为钝角,即大于90°。若夹角等于90°,则认定点P在多边形地理围栏的边界上。而根据向量的点积公式:
For any point P=(x,y), it can be seen that if point P is located inside the polygonal geofence, then the edge vector formed by point P and any boundary vertex Pi ( i =1,2,...,N) The normal vector corresponding to the edge vector where the boundary vertex Pi is located is an acute angle, that is, less than 90°; conversely, if point P is located outside the polygonal geofence, then the edge vector The normal vector corresponding to the edge vector where the vertex Pi is located The angle between is an obtuse angle, that is, greater than 90°. If the included angle is equal to 90°, then point P is determined to be on the boundary of the polygonal geofence. And according to the dot product formula of vectors:
可知,当边向量与法向量的夹角θ为锐角时,二者点积d>0;当边向量与法向量的夹角θ为钝角时,二者点积d<0。而根据边向量的表达式和法向量的表达式:
It can be seen that when the edge vector and normal vector When the angle θ is an acute angle, the dot product d>0; when the side vector and normal vector When the angle θ is an obtuse angle, the dot product d<0. And according to the edge vector The expression and normal vector of The expression of:
以及向量点积的表达式,可得:
As well as the expression of vector dot product, we can get:
这样,通过求解边向量与法向量的点积就可以判断点P是否在多边形地理围栏 的内部。而向量法计算的全过程中只用到了简单的四则运算,没有涉及复杂的运算模式,大大降低了计算量,提升了多边形地理围栏检测的性能。In this way, by solving the edge vector and normal vector The dot product can determine whether point P is in the polygon geofence internal. The whole process of vector method calculation only uses four simple arithmetic operations and does not involve complex calculation modes, which greatly reduces the amount of calculation and improves the performance of polygonal geofence detection.
本申请实施例中,采用向量法判断点P是否位于多边形地理围栏内部的计算流程图可如图6所示。In the embodiment of the present application, the calculation flow chart of using the vector method to determine whether point P is located inside a polygonal geofence is shown in Figure 6.
可选地,所述步骤401之后,所述步骤403之前,所述方法还包括:Optionally, after step 401 and before step 403, the method further includes:
确定所述目标地理围栏的外接矩形区域,其中,所述目标地理围栏的所有边界顶点均位于所述外接矩形区域内;Determine a circumscribed rectangular area of the target geofence, wherein all boundary vertices of the target geofence are located within the circumscribed rectangular area;
确定所述第一位置点与所述外接矩形区域的位置关系;Determine the positional relationship between the first position point and the circumscribed rectangular area;
所述步骤403包括:The step 403 includes:
在确定所述第一位置点不位于所述外接矩形区域外部的情况下,根据所述第一位置点与目标边界顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系。When it is determined that the first position point is not located outside the circumscribed rectangular area, the first position point is determined based on the dot product of the connecting vector between the first position point and the target boundary vertex and the target normal vector. The location relationship to the target geofence.
一种实施方式中,考虑到多边形地理围栏检测的算法相对复杂,如果对所有的定位点都直接用前述向量法进行多边形地理围栏检测会消耗掉不必要的算力和功耗。因此,如果定位位置点距离多边形地理围栏较远,则不必要直接用多边形地理围栏检测算法进行检测。该实施方式中,可先通过多边形地理围栏的外接矩形进行判定,如果定位点在该外接矩形的外部,则无需通过多边形地理围栏检测,可直接判定该定位点位于多边形地理围栏的外部。In one implementation, considering that the polygon geofence detection algorithm is relatively complex, if the aforementioned vector method is directly used for polygon geofence detection on all positioning points, unnecessary computing power and power consumption will be consumed. Therefore, if the location point is far away from the polygon geofence, it is not necessary to directly use the polygon geofence detection algorithm to detect it. In this embodiment, the determination can be made based on the circumscribed rectangle of the polygonal geofence. If the positioning point is outside the circumscribing rectangle, there is no need to detect the polygonal geofence, and it can be directly determined that the positioning point is located outside the polygonal geofence.
具体地,可以先根据所述目标地理围栏的位于最外侧的若干个边界顶点,确定所述目标地理围栏的外接矩形区域,例如,计算出多边形地理围栏的边界顶点数列中各个位置点的经纬度的最大值和最小值,取经度的最大值和最小值以及纬度的最大值和最小值,根据这四个点构成外接矩形的边界。Specifically, you can first determine the circumscribed rectangular area of the target geofence based on several outermost boundary vertices of the target geofence, for example, calculate the longitude and latitude of each position point in the sequence of boundary vertices of the polygonal geofence. The maximum and minimum values of , take the maximum and minimum values of longitude and the maximum and minimum values of latitude, and form the boundary of the circumscribed rectangle based on these four points.
在获取到所述电子设备当前所处的第一位置点后,可以先确定所述第一位置点与所述外接矩形区域的位置关系,即判断所述第一位置点是否位于所述外接矩形区域外部,若所述第一位置点位于所述外接矩形区域外部,则可直接确定所述第一位置点位于所述目标地理围栏外部,若所述第一位置点不位于所述外接矩形区域外部,如所述第一位置点位于所述外接矩形区域内部或位于所述外接矩形区域的边界,则可继续后续步骤403,即进一步根据所述第一位置点与目标边界顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系。After obtaining the first location point where the electronic device is currently located, the positional relationship between the first location point and the circumscribed rectangular area can be determined first, that is, it is determined whether the first location point is located in the circumscribed rectangle. Outside the area, if the first location point is located outside the circumscribed rectangular area, it can be directly determined that the first location point is located outside the target geofence, if the first location point is not located in the circumscribed rectangular area Externally, if the first position point is located inside the circumscribed rectangular area or at the boundary of the circumscribed rectangular area, then the subsequent step 403 can be continued, that is, further based on the connection vector between the first position point and the target boundary vertex. The dot product with the target normal vector determines the positional relationship between the first location point and the target geofence.
例如,对于当前位置点P,可以先判断点P是否在多边形地理围栏的外接矩形的外部,如果点P的经度超出了外接矩形的经度的最大值或者最小值,或者点P的纬度超出了外接矩形的纬度的最大值或者最小值,则可判定点P位于多边形地理围栏外部;否则,可根据前述向量法判断点P是否在多边形地理围栏外部。For example, for the current location point P, you can first determine whether point P is outside the circumscribed rectangle of the polygonal geofence. If the longitude of point P exceeds the maximum or minimum longitude of the circumscribed rectangle, or the latitude of point P exceeds the circumscribed rectangle. If the maximum or minimum value of the latitude of the rectangle is determined, it can be determined that point P is located outside the polygonal geofence; otherwise, whether point P is outside the polygonal geofence can be determined according to the aforementioned vector method.
需说明的是,如果多边形地理围栏的边界顶点的位置坐标所采用的坐标系是GCJ02、BD09等非大地坐标系时,需要对多边形地理围栏的各边界顶点进行坐标变换,将其转换 为国际上采用的地心坐标系(World Geodetic System——1984 Coordinate System,WGS84),因为只有WGS84坐标系是线性坐标系,才符合通过向量法进行多边形地理围栏检测的先决条件。即在生成多边形地理围栏的外接矩形之前,可以先进行多边形地理围栏的边界顶点坐标变换的步骤。如果多边形地理围栏边界的顶点坐标采用的就是WGS84坐标系,则无需进行该步骤。其中,将GCJ02或者BD09坐标系转换为WGS84坐标系,可以直接通过开源的转换插件进行转换。It should be noted that if the coordinate system used for the position coordinates of the boundary vertices of the polygonal geofence is a non-geodestic coordinate system such as GCJ02, BD09, etc., the coordinates of each boundary vertex of the polygonal geofence need to be transformed. It is the internationally adopted geocentric coordinate system (World Geodetic System - 1984 Coordinate System, WGS84). Because only the WGS84 coordinate system is a linear coordinate system, it meets the prerequisites for polygon geofence detection through the vector method. That is, before generating the bounding rectangle of the polygonal geofence, the step of transforming the coordinates of the boundary vertices of the polygonal geofence can be performed. If the vertex coordinates of the polygonal geofence boundary adopt the WGS84 coordinate system, this step is not required. Among them, converting the GCJ02 or BD09 coordinate system to the WGS84 coordinate system can be done directly through the open source conversion plug-in.
该实施方式的流程图可如图7所示,包括如下步骤:The flow chart of this implementation can be shown in Figure 7, including the following steps:
步骤701、多边形地理围栏边界顶点坐标变换。Step 701: Transform the coordinates of the vertices of the polygonal geofence boundary.
如果多边形地理围栏边界的顶点坐标采用的就是WGS84坐标系,则忽略该步骤。If the vertex coordinates of the polygonal geofence boundary use the WGS84 coordinate system, ignore this step.
步骤702、生成多边形地理围栏的外接矩形。Step 702: Generate the bounding rectangle of the polygonal geofence.
步骤703、判断点P是否在外接矩形外部。Step 703: Determine whether point P is outside the enclosing rectangle.
若是,则判定点P位于多边形地理围栏外部;否则,则进入步骤704,进行下一步的判断。If so, the determination point P is located outside the polygonal geofence; otherwise, step 704 is entered for the next step of determination.
步骤704、根据向量法判断点P是否在多边形地理围栏外部。Step 704: Determine whether point P is outside the polygonal geofence according to the vector method.
具体的判别步骤可参见图6。The specific identification steps can be seen in Figure 6.
这样,该实施方式中通过预先使用目标地理围栏的外接矩形区域对定位点进行判断,可简化多边形地理围栏检测的算法,降低了计算量,提升了检测的效率,降低了功耗。In this way, in this embodiment, by pre-using the circumscribed rectangular area of the target geofence to determine the positioning point, the polygonal geofence detection algorithm can be simplified, the amount of calculation is reduced, the detection efficiency is improved, and the power consumption is reduced.
可选地,所述步骤401之前,所述方法还包括:Optionally, before step 401, the method further includes:
在所述电子设备于第一时刻位于所述目标地理围栏内部的情况下,存储所述电子设备在所述第一时刻所处的第二位置点,所述第一时刻为当前时刻之前的时刻;When the electronic device is located inside the target geofence at the first time, store the second location point of the electronic device at the first time, and the first time is the time before the current time. ;
所述步骤401之后,所述步骤403之前,所述方法还包括:After step 401 and before step 403, the method further includes:
确定第二向量和第一夹角,其中,所述第二向量为自所述第二位置点指向所述第一位置点的向量,所述第一夹角为所述第二向量与直角坐标系中的-y轴的夹角;Determine the second vector and the first included angle, where the second vector is a vector from the second position point to the first position point, and the first included angle is the second vector and the rectangular coordinate The angle between the -y axis in the system;
根据所述第一夹角,对所述目标地理围栏的边界顶点进行坐标转换,得到所述目标地理围栏的边界顶点在第二坐标系下的纵坐标值,其中,所述第二坐标系为所述直角坐标系逆时针旋转所述第一夹角后的坐标系;According to the first included angle, coordinate transformation is performed on the boundary vertex of the target geofence to obtain the ordinate value of the boundary vertex of the target geofence in a second coordinate system, where the second coordinate system is The coordinate system after rotating the first included angle counterclockwise from the Cartesian coordinate system;
根据所述目标地理围栏的边界顶点在所述第二坐标系下的纵坐标值与所述第二位置点在所述第二坐标系下的纵坐标值,确定所述目标边界顶点,其中,所述目标边界顶点位于第一法线的第一侧,所述第一法线与所述第二向量垂直,所述第一位置点位于所述第一法线的第一侧。The target boundary vertex is determined according to the ordinate value of the boundary vertex of the target geofence in the second coordinate system and the ordinate value of the second location point in the second coordinate system, where, The target boundary vertex is located on a first side of a first normal line, the first normal line is perpendicular to the second vector, and the first position point is located on a first side of the first normal line.
从图6所示的基于向量法判断点P是否位于多边形地理围栏内部的算法流程图中可以看出,如果点P位于多边形地理围栏的内部,是需要将所有的边向量以及对应的法向量遍历计算一遍才能够得出结论。这对于边界复杂,边界顶点较多的多边形地理围栏来说其检测的计算量仍然很大。因此,一种实施方式中,可以在图6所示实施例的基础上,将不必要做计算的边向量以及对应的法向量识别出来,使得无需遍历计算所有的边向量和对应的 法向量,从而进一步减小计算量。It can be seen from the algorithm flow chart of determining whether point P is located inside a polygonal geofence based on the vector method shown in Figure 6 that if point P is located inside a polygonal geofence, all edge vectors and corresponding normal vectors need to be traversed Only after calculation can a conclusion be drawn. This is still very computationally intensive for polygonal geofences with complex boundaries and many boundary vertices. Therefore, in one implementation, based on the embodiment shown in Figure 6, edge vectors and corresponding normal vectors that do not need to be calculated can be identified, so that there is no need to traverse and calculate all edge vectors and corresponding normal vectors. normal vector, thereby further reducing the amount of calculation.
设在t0时刻电子设备用户已经进入了多边形地理围栏内部,其位置记为P(t0),下一定位时刻设为t1(t0<t1),记该时刻的定位位置为P(t1),现在要检测位置P(t1)是否位于多边形地理围栏的内部。Assume that at time t 0 , the electronic device user has entered the polygonal geofence, and its position is recorded as P(t 0 ). The next positioning time is set to t 1 (t 0 <t 1 ), and the positioning position at this time is recorded as P. (t 1 ), now we want to detect whether the position P (t 1 ) is inside the polygonal geofence.
记前后两个时刻的定位位置所构成的向量为该向量表征了用户从时刻t0到时刻t1的运动方向,可称之为运动方向向量。如图8所示,可经过点P(t0)作一条垂直于运动方向向量的直线L,称之为运动方向向量的法线。由于点P(t0)在多边形地理围栏的内部,那么这条法线L会将整个多边形地理围栏分割成两部分,相应地,多边形地理围栏边界上的顶点也会被这条法线分割成两部分;以法线L作为分界线,一部分顶点位于点P(t1)的同一侧,称为同侧顶点;一部分顶点位于点P(t1)的不同侧,称为异侧顶点(如图8中标记为“×”的顶点)。The vector composed of the positioning positions of the two moments before and after is recorded as This vector represents the user's movement direction from time t 0 to time t 1 , and can be called a movement direction vector. As shown in Figure 8, a vector perpendicular to the direction of motion can be drawn through point P (t 0 ) The straight line L is called the normal of the motion direction vector. Since point P(t 0 ) is inside the polygonal geofence, this normal line L will divide the entire polygonal geofence into two parts. Correspondingly, the vertices on the boundary of the polygonal geofence will also be divided into two parts by this normal line. Two parts; with the normal L as the dividing line, one part of the vertices is located on the same side of the point P(t 1 ), which is called the same-side vertex; the part of the vertex is located on different sides of the point P(t 1 ), which is called the different-side vertex (such as Vertices marked with “×” in Figure 8).
如图8所示,对于异侧顶点,由于点P(t0)已经位于多边形地理围栏内部,说明点P(t0)与这些异侧顶点相比已经位于多边形地理围栏的内侧,而点P(t1)相对于点P(t0)更加远离了异侧顶点,从这些异侧顶点的角度看,点P(t1)更可能是位于多边形地理围栏的内侧。因此,在判断点P(t1)是否位于多边形地理围栏内部这个问题上,这些异侧顶点起不到判断作用,从而在利用向量法进行多边形地理围栏检测时,可以忽略掉这部分异侧顶点以及对应的边向量,达到简化计算的目的。As shown in Figure 8, for vertices on opposite sides, since point P(t 0 ) is already located inside the polygonal geofence, it means that point P(t 0 ) is already located inside the polygonal geofence compared with these vertices on opposite sides, and point P (t 1 ) is farther away from the vertices on the opposite side than point P (t 0 ). From the perspective of these vertices on the opposite side, point P (t 1 ) is more likely to be located inside the polygonal geofence. Therefore, when it comes to judging whether the point P(t 1 ) is located inside the polygonal geofence, these vertices on the opposite sides do not play a role in determining whether the point P(t 1 ) is located inside the polygonal geofence. Therefore, when using the vector method to detect the polygonal geofence, these vertices on the opposite sides can be ignored. and the corresponding edge vectors to simplify calculations.
下面来讨论如何识别异侧顶点和同侧顶点。图8所示的是从几何的角度直观的判断异侧和同侧顶点,并不是计算机识别的算法语言。因此,在具体实施中,可以考虑通过坐标变换的方法进行识别。如图9所示,设运动方向向量与平面直角坐标系的y轴负半轴的夹角为φ,可知运动方向向量对应的法线L与平面直角坐标系的x轴正半轴的夹角也为φ,如果以法线L作为坐标变换后新的坐标系下的x*轴,相当于新旧坐标系的旋转角度为φ,坐标系旋转如图9所示。Let's discuss how to identify vertices on different sides and vertices on the same side. What Figure 8 shows is an intuitive judgment of vertices on the opposite side and the same side from a geometric point of view, and is not an algorithmic language for computer recognition. Therefore, in specific implementation, identification through coordinate transformation may be considered. As shown in Figure 9, assuming the motion direction vector The angle between the negative half-axis of the y-axis of the plane rectangular coordinate system is φ, and the motion direction vector can be known The angle between the corresponding normal L and the positive x-axis of the plane rectangular coordinate system is also φ. If the normal L is used as the x* axis in the new coordinate system after coordinate transformation, it is equivalent to the rotation angle of the old and new coordinate systems. is φ, the coordinate system is rotated as shown in Figure 9.
因此,可根据坐标旋转变换公式:
Therefore, the coordinate rotation transformation formula can be:
计算点P(t0)和所有边界顶点P1至P10在新坐标系下的纵坐标值(y*轴),记点P(t0)在新坐标系y*轴方向上的坐标值为yt0,如果P1至P10中某个顶点在新坐标系下的纵坐标值大于yt0,则可判断为异侧顶点;反之,则判断为同侧顶点。Calculate the ordinate value (y* axis) of point P (t 0 ) and all boundary vertices P 1 to P 10 in the new coordinate system, and record the coordinate value of point P (t 0 ) in the y* axis direction of the new coordinate system. is y t0 , if the ordinate value of a vertex from P 1 to P 10 in the new coordinate system is greater than y t0 , it can be judged to be a vertex on the opposite side; otherwise, it can be judged to be a vertex on the same side.
基于此,该实施方式的流程图可如图10所示,包括如下步骤:Based on this, the flow chart of this implementation can be shown in Figure 10, including the following steps:
步骤1001、缓存位于多边形地理围栏内部的位置点P(t0)。Step 1001: Cache the position point P(t 0 ) located inside the polygonal geofence.
步骤1002、电子设备于t1时刻发起定位,获取该时刻定位位置P(t1)。Step 1002: The electronic device initiates positioning at time t 1 and obtains the positioning position P(t 1 ) at that time.
定位的方式可以根据目标地理围栏的具体环境决定,例如,如果该地理围栏属于室外,则可用GPS进行定位;如果是室内环境,可以发起网络定位,通过WiFi或者基站信号定位。The positioning method can be determined according to the specific environment of the target geofence. For example, if the geofence is outdoors, GPS can be used for positioning; if it is an indoor environment, network positioning can be initiated and positioned through WiFi or base station signals.
步骤1003、计算运动方向向量和对应的夹角。 Step 1003: Calculate the motion direction vector and the corresponding angle.
设运动方向向量为可计算出运动方向向量与直角坐标系y轴负半轴的夹角为:
Let the motion direction vector be The angle between the movement direction vector and the negative half-axis of the y-axis of the Cartesian coordinate system can be calculated as:
步骤1004、根据坐标转换公式和夹角φ,对多边形地理围栏边界的所有顶点进行坐标变换,计算新坐标下的纵坐标值y′。Step 1004: According to the coordinate conversion formula and the included angle φ, perform coordinate transformation on all vertices of the polygonal geofence boundary, and calculate the ordinate value y′ under the new coordinates.
步骤1005、计算点P(t0)在新坐标下的纵坐标值yt0。比较y′与yt0的值,如果y′>yt0,则判定对应顶点为异侧顶点;反之,则判定对应顶点为同侧顶点。Step 1005: Calculate the ordinate value y t0 of point P(t 0 ) under the new coordinates. Compare the values of y′ and y t0 . If y′>y t0 , the corresponding vertex is determined to be a vertex on the opposite side; otherwise, the corresponding vertex is determined to be a vertex on the same side.
步骤1006、使用同侧顶点用向量法判定点P(t1)是否位于多边形地理围栏内部。Step 1006: Use the vector method to determine whether point P(t 1 ) is located inside the polygonal geofence using vertices on the same side.
这样,通过该实施方式,可避免遍历所有边向量进行多边形地理围栏检测,进一步降低了计算量。In this way, through this implementation, it is possible to avoid traversing all edge vectors for polygon geofence detection, further reducing the amount of calculation.
进一步地,所述第二坐标系的原点为所述第二位置点,所述第二位置点在所述第二坐标系下的纵坐标值为0;Further, the origin of the second coordinate system is the second position point, and the ordinate value of the second position point in the second coordinate system is 0;
所述步骤401包括:The step 401 includes:
在第一边界顶点在所述第二坐标系下的纵坐标值小于或等于0的情况下,确定所述第一边界顶点为所述目标边界顶点,其中,所述第一边界顶点为所述目标地理围栏中的任一边界顶点;When the ordinate value of the first boundary vertex in the second coordinate system is less than or equal to 0, the first boundary vertex is determined to be the target boundary vertex, wherein the first boundary vertex is the Any boundary vertex in the target geofence;
在所述第一边界顶点在所述第二坐标系下的纵坐标值大于0的情况下,确定所述第一边界顶点不为所述目标边界顶点。When the ordinate value of the first boundary vertex in the second coordinate system is greater than 0, it is determined that the first boundary vertex is not the target boundary vertex.
一种实施方式中,可以之前时刻的第二位置点作为直角坐标系原点,对所述直角坐标系进行逆时针旋转,以得到转换后的第二坐标系,使所述第二坐标系的原点为所述第二位置点,从而所述第二位置点在所述第二坐标系下的纵坐标值为0。例如,可以t0时刻的位置点P(t0)为变换后新坐标系的原点,从而P(t0)在新坐标系下的纵坐标值为0。In one implementation, the second position point at the previous moment can be used as the origin of the Cartesian coordinate system, and the Cartesian coordinate system is rotated counterclockwise to obtain the converted second coordinate system, so that the origin of the second coordinate system is the second position point, so the ordinate value of the second position point in the second coordinate system is 0. For example, the position point P(t 0 ) at time t 0 can be the origin of the new coordinate system after transformation, so that the ordinate value of P(t 0 ) in the new coordinate system is 0.
这样,在根据所述目标地理围栏的各边界顶点在所述第二坐标系下的纵坐标值与所述第二位置点在所述第二坐标系下的纵坐标值,判断各边界顶点是否为目标边界顶点(即是否为同侧顶点)时,只需将各边界顶点在所述第二坐标系下的纵坐标值与0进行比较即可,具体地,若某个边界顶点在所述第二坐标系下的纵坐标值大于0,则可以确定该边界顶点为异侧顶点,即不是目标边界顶点,反之,若某个边界顶点在所述第二坐标系下的纵坐标值小于或等于0,则可以确定该边界顶点为同侧顶点,即是目标边界顶点。In this way, based on the ordinate value of each boundary vertex of the target geofence in the second coordinate system and the ordinate value of the second location point in the second coordinate system, it is determined whether each boundary vertex is When it is the target boundary vertex (that is, whether it is a vertex on the same side), it is only necessary to compare the ordinate value of each boundary vertex in the second coordinate system with 0. Specifically, if a certain boundary vertex is in the If the ordinate value in the second coordinate system is greater than 0, it can be determined that the boundary vertex is a vertex on the opposite side, that is, it is not the target boundary vertex. On the contrary, if the ordinate value of a boundary vertex in the second coordinate system is less than or If equal to 0, it can be determined that the boundary vertex is the vertex on the same side, that is, it is the target boundary vertex.
这样,该实施方式中,在以所述第二位置点为第二坐标系的原点,使得所述第二位置点在所述第二坐标系下的纵坐标值为0的情况下,只需比较所述目标地理围栏的各边界顶点在所述第二坐标系下的纵坐标值是否大于0,即可快速地确定各边界顶点是否为目标边界顶点。In this way, in this embodiment, when the second position point is taken as the origin of the second coordinate system, so that the ordinate value of the second position point in the second coordinate system is 0, only By comparing whether the ordinate value of each boundary vertex of the target geofence in the second coordinate system is greater than 0, it can be quickly determined whether each boundary vertex is a target boundary vertex.
可选地,所述步骤401之前,所述方法还包括:Optionally, before step 401, the method further includes:
在所述电子设备于第二时刻位于所述目标地理围栏内部的情况下,存储所述电子设备 在所述第二时刻所处的第三位置点,所述第二时刻为当前时刻之前的时刻;In the case where the electronic device is located inside the target geofence at the second time, storing the electronic device At the third location point where the second time is located, the second time is the time before the current time;
根据所述第三位置点分别沿预设的M个方向与所述目标地理围栏的边界的距离,生成空间环境表,其中,所述空间环境表中存储有方向与距离的对应关系,所述M个方向中相邻两个方向之间间隔预设角度,M等于360度除以所述预设角度;According to the distances between the third location point and the boundary of the target geofence along the preset M directions, a spatial environment table is generated, wherein the spatial environment table stores a corresponding relationship between directions and distances. There is a preset angle between two adjacent directions in the M directions, and M is equal to 360 degrees divided by the preset angle;
所述步骤401之后,所述步骤403之前,所述方法还包括:After step 401 and before step 403, the method further includes:
确定所述第一位置点相对所述第三位置点的第一距离和第一方向;Determine a first distance and a first direction of the first position point relative to the third position point;
从所述空间环境表中查询所述第一方向对应的第二距离;Query the second distance corresponding to the first direction from the spatial environment table;
所述步骤403包括:The step 403 includes:
在所述第一距离大于所述第二距离的情况下,根据所述第一位置点与目标边界顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系。When the first distance is greater than the second distance, the distance between the first position point and the target is determined based on the dot product of the connecting vector between the first position point and the target boundary vertex and the target normal vector. Geofence location relationships.
在实际应用场景中,用户进入了一个地理围栏之后,通常会逗留一段时间,并不会立即离开围栏。例如,用户在一个商场逛街,在逛街的时间段内用户一直处在这个商场对应的多边形地理围栏内部,如果每次定位都用多边形地理围栏的检测算法进行检测的话,每次检测都需要消耗较大的计算量。如果用户在逛街的过程中调用了室内导航等应用,就会导致定位的频次变高,计算量和功耗会变得更大。因此,该实施方式中,提出了一种更为简便的算法,来覆盖这种场景。In actual application scenarios, after a user enters a geofence, he or she usually stays for a while and does not leave the geofence immediately. For example, a user is shopping in a shopping mall, and the user has been inside the polygonal geofence corresponding to the shopping mall during the shopping period. If the polygonal geofence detection algorithm is used for each positioning, each detection will consume a lot of time. Large amount of calculation. If the user calls applications such as indoor navigation while shopping, the frequency of positioning will increase, and the amount of calculation and power consumption will increase. Therefore, in this implementation, a simpler algorithm is proposed to cover this scenario.
该实施方式所设计的方法是一种以空间换时间的方法,具体来说就是用户在第一次进入该多边形地理围栏时就构建好关于这个多边形地理围栏的空间环境,使得每次定位时只需要进行简单的计算就可以判断当前是否仍位于多边形地理围栏内部。因此,该实施方式的核心是如何构建多边形地理围栏的空间环境。The method designed in this embodiment is a method of exchanging space for time. Specifically, the user constructs the spatial environment of the polygonal geofence when entering the polygonal geofence for the first time, so that each time the user is positioned, only A simple calculation is required to determine whether you are still inside the polygonal geofence. Therefore, the core of this implementation is how to construct a spatial environment of polygonal geofences.
设在t0时刻用户已经进入了多边形地理围栏内部,其位置记为P(t0),下一定位时刻设为t1(t0<t1),记该时刻的定位位置为P(t1),在构建多边形地理围栏的空间环境时,具体可以点P(t0)为出发点沿指定的方向向量等间隔打点,这些点在指定的方向向量上构成一个点序列,记为这个点序列中相邻两个点的间隔是相等的,那么肯定会存在一个点,该点位于多边形地理围栏的外部,之后这个序列上所有的点都会位于多边形地理围栏的外部,那么这个点就是切换点,它前面的点就是位于多边形地理围栏内部的最后一个点。由于点与点之间的距离是等间隔的,因此可以计算出在方向向量ω上点P(t0)到多边形地理围栏边界的距离。通过这种方法就可以计算出点P(t0)在所有的方向向量上到多边形地理围栏边界的距离,具体可以如图11所示。Assume that the user has entered the polygonal geofence at time t 0 , and its position is recorded as P(t 0 ). The next positioning time is set to t 1 (t 0 <t 1 ), and the positioning position at this time is recorded as P(t 1 ), when constructing the spatial environment of a polygonal geofence, specifically point P (t 0 ) can be used as the starting point to score points at equal intervals along the specified direction vector. These points form a point sequence on the specified direction vector, which is recorded as The distance between two adjacent points in this point sequence is equal, then there will definitely be a point that is located outside the polygonal geofence. After that, all points in this sequence will be located outside the polygonal geofence, then this point is Switch the point so that the point before it is the last point inside the polygon geofence. Since the distances between points are equally spaced, the distance from point P(t 0 ) to the polygonal geofence boundary on the direction vector ω can be calculated. Through this method, the distance from point P(t 0 ) to the boundary of the polygonal geofence in all direction vectors can be calculated, as shown in Figure 11.
这样,就可以生成一张该多边形地理围栏的空间环境表,表中记录当前点在所有方向向量上的距离。具体地,可以根据实际需求,设定相邻两条方向向量的夹角,例如,可以设相邻两条方向向量的夹角为15°,那么整个多边形地理围栏空间可被分成24个方向向量。该地理围栏的空间环境表可以如下表1所示。In this way, a spatial environment table of the polygonal geofence can be generated, which records the distance of the current point in all direction vectors. Specifically, the angle between two adjacent direction vectors can be set according to actual needs. For example, the angle between two adjacent direction vectors can be set to 15°, then the entire polygonal geofence space can be divided into 24 direction vectors. . The spatial environment table of the geofence can be shown in Table 1 below.
表1多边形地理围栏的空间环境表
Table 1 Spatial environment table of polygonal geofences
这样,在下一时刻获得定位位置P(t1)之后,只需计算出运动方向向量的夹角和距离,在空间环境表中查询即可判定点P(t1)是否位于多边形地理围栏内部。如果运动方向向量的模值(代表距离)小于空间环境表中该方向向量上的距离时,就可以认定点P(t1)在多边形地理围栏内部;反之,可再启动向量法作进一步判定。In this way, after obtaining the positioning position P (t 1 ) at the next moment, we only need to calculate the movement direction vector By querying the angle and distance in the spatial environment table, you can determine whether point P(t 1 ) is located inside the polygonal geofence. If the motion direction vector When the modulus value (representing distance) is less than the distance on the direction vector in the spatial environment table, it can be determined that point P (t 1 ) is inside the polygonal geofence; otherwise, the vector method can be restarted for further determination.
这样,该实施方式中,通过预先建立目标地理围栏的空间环境表,使得能够根据实时定位位置,查表判断用户是否仍位于地理围栏内部,对于用户长时间在某地理围栏逗留的场景下,能够进一步减少计算量。In this way, in this embodiment, by pre-establishing the spatial environment table of the target geofence, it is possible to check the table to determine whether the user is still inside the geofence based on the real-time positioning position. In the scenario where the user stays in a certain geofence for a long time, it is possible to further reduce the amount of calculation.
进一步地,在确定所述第一位置点位于所述目标地理围栏内部的情况下,所述方法还包括:Further, when it is determined that the first location point is located inside the target geofence, the method further includes:
确定第三向量分别与所述M个方向中各个方向的夹角,其中,所述第三向量为自所述第三位置点指向所述第一位置点的向量;Determine the angle between the third vector and each of the M directions, wherein the third vector is a vector from the third position point to the first position point;
根据所述第三向量分别与所述M个方向中各个方向的夹角和所述第三向量的模值,确定所述M个方向中各个方向的距离改变值;Determine the distance change value in each of the M directions according to the angle between the third vector and each of the M directions and the modulus of the third vector;
根据所述M个方向中各个方向的距离改变值,更新所述空间环境表。The spatial environment table is updated according to the distance change value in each of the M directions.
上一实施方式中,在定位位置更新后,若确定所述电子设备用户仍位于所述目标地理围栏内部,则可以对所述空间环境表进行更新,以便后续定位位置能够基于更新的空间环境表做更准确的判断。In the previous embodiment, after the positioning position is updated, if it is determined that the electronic device user is still inside the target geofence, the spatial environment table can be updated so that subsequent positioning positions can be based on the updated spatial environment table. Make more accurate judgments.
更新的具体方法可以是:计算运动方向向量与空间环境表中各个方向向量的夹角α;计算运动方向向量的模值d′;计算在各个方向向量上的距离改变值Δd=d′×cosα;将空间环境表中每一行方向向量编号对应的距离值减去Δd,即完成了更新。The specific method of updating can be: calculating the motion direction vector The angle α with each direction vector in the space environment table; calculate the motion direction vector The modulus value d′; calculate the distance change value Δd=d′×cosα in each direction vector; subtract Δd from the distance value corresponding to the direction vector number in each row of the spatial environment table, and the update is completed.
该实施方式的流程图可如图12所示,包括如下步骤:The flow chart of this embodiment can be shown in Figure 12, including the following steps:
步骤1201、生成空间环境表。Step 1201: Generate a spatial environment table.
步骤1202、获取定位位置,计算用户运动方向向量的模值和方向。Step 1202: Obtain the positioning position and calculate the modulus and direction of the user's motion direction vector.
步骤1203、从空间环境表中查询运动方向向量所在方向的向量区间编号。Step 1203: Query the vector interval number in the direction of the motion direction vector from the space environment table.
步骤1204、查询出对应向量区间编号的距离。 Step 1204: Query the distance corresponding to the vector interval number.
步骤1205、判断运动方向向量的模值是否小于空间环境表中查询到的距离,若是,则直接判定该点位于多边形地理围栏内部;否则,则进入步骤1206。Step 1205: Determine whether the modulus value of the motion direction vector is less than the distance queried in the spatial environment table. If so, directly determine that the point is located inside the polygonal geofence; otherwise, proceed to step 1206.
步骤1206、启动向量法进行多边形地理围栏检测。Step 1206: Start the vector method to detect polygonal geofences.
步骤1207、更新空间环境表。Step 1207: Update the space environment table.
本申请实施例中的地理围栏检测方法,获取电子设备当前所处的第一位置点;分别确定目标地理围栏的各个法向量,其中,所述目标地理围栏由N个边界顶点按预设顺序连接形成,所述法向量与所述目标地理围栏的边向量垂直,所述边向量为所述目标地理围栏的相邻两个边界顶点连接形成的向量,N为大于2的整数;根据所述第一位置点与目标边界顶点连接形成的向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,其中,所述目标边界顶点为所述目标地理围栏中的部分或全部边界顶点,所述目标法向量为与所述目标边界顶点处的边向量垂直的法向量。这样,通过向量法来对电子设备进行地理围栏检测,避免了传统交叉数法中涉及的复杂运算,而只用到了简单的四则运算,从而能够有效降低围栏检测的计算复杂度,极大减少计算量,提升检测效率。The geofence detection method in the embodiment of the present application obtains the first location point where the electronic device is currently located; respectively determines each normal vector of the target geofence, wherein the target geofence is connected by N boundary vertices in a preset order Formed, the normal vector is perpendicular to the edge vector of the target geographical fence, the edge vector is a vector formed by connecting two adjacent boundary vertices of the target geographical fence, and N is an integer greater than 2; according to the first The dot product of the vector formed by connecting a position point and the target boundary vertex and the target normal vector determines the positional relationship between the first position point and the target geofence, wherein the target boundary vertex is in the target geofence. Some or all of the boundary vertices, the target normal vector is a normal vector perpendicular to the edge vector at the target boundary vertex. In this way, the vector method is used to detect geofences on electronic devices, avoiding the complex operations involved in the traditional cross number method, and only using four simple arithmetic operations, which can effectively reduce the computational complexity of fence detection and greatly reduce calculations. quantity and improve detection efficiency.
本申请实施例提供的地理围栏检测方法,执行主体可以为地理围栏检测装置。本申请实施例中以地理围栏检测装置执行地理围栏检测方法为例,说明本申请实施例提供的地理围栏检测装置。For the geofence detection method provided by the embodiment of the present application, the execution subject may be a geofence detection device. In the embodiments of this application, the geofence detection method performed by the geofence detection device is used as an example to illustrate the geofence detection device provided by the embodiments of this application.
请参见图13,图13为本申请实施例提供的地理围栏检测装置的结构示意图,如图13所示,地理围栏检测装置1300包括:Please refer to Figure 13, which is a schematic structural diagram of a geofence detection device provided by an embodiment of the present application. As shown in Figure 13, the geofence detection device 1300 includes:
获取模块1301,用于获取电子设备当前所处的第一位置点;The acquisition module 1301 is used to acquire the first location point where the electronic device is currently located;
第一确定模块1302,用于分别确定目标地理围栏的各个法向量,其中,所述目标地理围栏由N个边界顶点按预设顺序连接形成,所述法向量与所述目标地理围栏的边向量垂直,所述边向量为所述目标地理围栏的相邻两个边界顶点连接形成的向量,N为大于2的整数;The first determination module 1302 is used to determine each normal vector of the target geographical fence, wherein the target geographical fence is formed by connecting N boundary vertices in a preset order, and the normal vector is the same as the edge vector of the target geographical fence. Vertical, the edge vector is a vector formed by connecting two adjacent boundary vertices of the target geofence, and N is an integer greater than 2;
第二确定模块1303,用于根据所述第一位置点与目标边界顶点连接形成的向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,其中,所述目标边界顶点为所述目标地理围栏中的部分或全部边界顶点,所述目标法向量为与所述目标边界顶点处的边向量垂直的法向量。The second determination module 1303 is configured to determine the positional relationship between the first position point and the target geofence based on the dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector, where, The target boundary vertex is part or all of the boundary vertices in the target geofence, and the target normal vector is a normal vector perpendicular to an edge vector at the target boundary vertex.
可选地,地理围栏检测装置1300还包括:Optionally, the geofence detection device 1300 also includes:
第三确定模块,用于确定所述目标地理围栏的外接矩形区域,其中,所述目标地理围栏的所有边界顶点均位于所述外接矩形区域内;A third determination module, configured to determine the circumscribed rectangular area of the target geofence, wherein all boundary vertices of the target geofence are located within the circumscribed rectangular area;
第四确定模块,用于确定所述第一位置点与所述外接矩形区域的位置关系;The fourth determination module is used to determine the positional relationship between the first position point and the circumscribed rectangular area;
所述第二确定模块用于在确定所述第一位置点不位于所述外接矩形区域外部的情况下,根据所述第一位置点与目标边界顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系。The second determination module is configured to determine based on the dot product of the connection vector between the first position point and the target boundary vertex and the target normal vector when it is determined that the first position point is not located outside the circumscribed rectangular area. , determine the positional relationship between the first location point and the target geofence.
可选地,所述法向量指向所述目标地理围栏的内部; Optionally, the normal vector points to the interior of the target geofence;
第二确定模块1303包括:The second determination module 1303 includes:
第一确定单元,用于在第一向量与所述目标法向量的点积大于0的情况下,确定所述第一位置点位于所述目标地理围栏内部,其中,所述第一向量为自所述目标边界顶点指向所述第一位置点的向量;A first determination unit configured to determine that the first location point is located inside the target geofence when the dot product of the first vector and the target normal vector is greater than 0, wherein the first vector is A vector from the target boundary vertex pointing to the first position point;
第二确定单元,用于在所述第一向量与所述目标法向量的点积小于0的情况下,确定所述第一位置点位于所述目标地理围栏外部。A second determination unit configured to determine that the first location point is located outside the target geofence when the dot product of the first vector and the target normal vector is less than 0.
可选地,地理围栏检测装置1300还包括:Optionally, the geofence detection device 1300 also includes:
第一存储模块,用于在所述电子设备于第一时刻位于所述目标地理围栏内部的情况下,存储所述电子设备在所述第一时刻所处的第二位置点,所述第一时刻为当前时刻之前的时刻;A first storage module configured to store the second location point of the electronic device at the first time when the electronic device is located inside the target geofence at the first time, the first The time is the time before the current time;
第五确定模块,用于确定第二向量和第一夹角,其中,所述第二向量为自所述第二位置点指向所述第一位置点的向量,所述第一夹角为所述第二向量与直角坐标系中的-y轴的夹角;The fifth determination module is used to determine the second vector and the first included angle, wherein the second vector is a vector from the second position point to the first position point, and the first included angle is the The angle between the second vector and the -y axis in the Cartesian coordinate system;
坐标转换模块,用于根据所述第一夹角,对所述目标地理围栏的边界顶点进行坐标转换,得到所述目标地理围栏的边界顶点在第二坐标系下的纵坐标值,其中,所述第二坐标系为所述直角坐标系逆时针旋转所述第一夹角后的坐标系;A coordinate conversion module configured to perform coordinate conversion on the boundary vertex of the target geofence according to the first included angle to obtain the ordinate value of the boundary vertex of the target geofence in the second coordinate system, wherein: The second coordinate system is a coordinate system obtained by rotating the rectangular coordinate system counterclockwise by the first included angle;
第六确定模块,用于根据所述目标地理围栏的边界顶点在所述第二坐标系下的纵坐标值与所述第二位置点在所述第二坐标系下的纵坐标值,确定所述目标边界顶点,其中,所述目标边界顶点位于第一法线的第一侧,所述第一法线与所述第二向量垂直,所述第一位置点位于所述第一法线的第一侧。The sixth determination module is used to determine the ordinate value of the boundary vertex of the target geofence in the second coordinate system and the ordinate value of the second location point in the second coordinate system. The target boundary vertex, wherein the target boundary vertex is located on a first side of a first normal line, the first normal line is perpendicular to the second vector, and the first position point is located on the first side of the first normal line First side.
可选地,所述第二坐标系的原点为所述第二位置点,所述第二位置点在所述第二坐标系下的纵坐标值为0;Optionally, the origin of the second coordinate system is the second position point, and the ordinate value of the second position point in the second coordinate system is 0;
所述第六确定模块包括:The sixth determination module includes:
第三确定单元,用于在第一边界顶点在所述第二坐标系下的纵坐标值小于或等于0的情况下,确定所述第一边界顶点为所述目标边界顶点,其中,所述第一边界顶点为所述目标地理围栏中的任一边界顶点;A third determination unit configured to determine that the first boundary vertex is the target boundary vertex when the ordinate value of the first boundary vertex in the second coordinate system is less than or equal to 0, wherein, The first boundary vertex is any boundary vertex in the target geofence;
第四确定单元,用于在所述第一边界顶点在所述第二坐标系下的纵坐标值大于0的情况下,确定所述第一边界顶点不为所述目标边界顶点。A fourth determination unit configured to determine that the first boundary vertex is not the target boundary vertex when the ordinate value of the first boundary vertex in the second coordinate system is greater than 0.
可选地,地理围栏检测装置1300还包括:Optionally, the geofence detection device 1300 also includes:
第二存储模块,用于在所述电子设备于第二时刻位于所述目标地理围栏内部的情况下,存储所述电子设备在所述第二时刻所处的第三位置点,所述第二时刻为当前时刻之前的时刻;A second storage module configured to store the third location point of the electronic device at the second time when the electronic device is located inside the target geofence at the second time. The time is the time before the current time;
生成模块,用于根据所述第三位置点分别沿预设的M个方向与所述目标地理围栏的边界的距离,生成空间环境表,其中,所述空间环境表中存储有方向与距离的对应关系,所述M个方向中相邻两个方向之间间隔预设角度,M等于360度除以所述预设角度。 A generation module configured to generate a spatial environment table according to the distances between the third location point and the boundary of the target geofence along the preset M directions, wherein the spatial environment table stores directions and distances. Correspondingly, two adjacent directions among the M directions are separated by a preset angle, and M is equal to 360 degrees divided by the preset angle.
第七确定模块,用于确定所述第一位置点相对所述第三位置点的第一距离和第一方向;A seventh determination module, used to determine the first distance and the first direction of the first position point relative to the third position point;
查询模块,用于从所述空间环境表中查询所述第一方向对应的第二距离;A query module, used to query the second distance corresponding to the first direction from the spatial environment table;
第二确定模块1303用于在所述第一距离大于所述第二距离的情况下,根据所述第一位置点与目标边界顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系。The second determination module 1303 is configured to determine the first distance based on the dot product of the connection vector between the first position point and the target boundary vertex and the target normal vector when the first distance is greater than the second distance. The positional relationship between a location point and the target geofence.
可选地,地理围栏检测装置1300还包括:Optionally, the geofence detection device 1300 also includes:
第八确定模块,用于在确定所述第一位置点位于所述目标地理围栏内部的情况下,确定第三向量分别与所述M个方向中各个方向的夹角,其中,所述第三向量为自所述第三位置点指向所述第一位置点的向量;An eighth determination module, configured to determine the angle between the third vector and each of the M directions respectively when it is determined that the first location point is located inside the target geofence, wherein the third vector The vector is a vector from the third position point to the first position point;
第九确定模块,用于根据所述第三向量分别与所述M个方向中各个方向的夹角和所述第三向量的模值,确定所述M个方向中各个方向的距离改变值;A ninth determination module, configured to determine the distance change value in each of the M directions according to the angle between the third vector and each of the M directions and the modulus of the third vector;
更新模块,用于根据所述M个方向中各个方向的距离改变值,更新所述空间环境表。An update module, configured to update the spatial environment table according to the distance change value in each of the M directions.
本申请实施例中的地理围栏检测装置1300,获取电子设备当前所处的第一位置点;分别确定目标地理围栏的各个法向量,其中,所述目标地理围栏由N个边界顶点按预设顺序连接形成,所述法向量与所述目标地理围栏的边向量垂直,所述边向量为所述目标地理围栏的相邻两个边界顶点连接形成的向量,N为大于2的整数;根据所述第一位置点与目标边界顶点连接形成的向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,其中,所述目标边界顶点为所述目标地理围栏中的部分或全部边界顶点,所述目标法向量为与所述目标边界顶点处的边向量垂直的法向量。这样,通过向量法来对电子设备进行地理围栏检测,避免了传统交叉数法中涉及的复杂运算,而只用到了简单的四则运算,从而能够有效降低围栏检测的计算复杂度,极大减少计算量,提升检测效率。The geofence detection device 1300 in the embodiment of the present application obtains the first location point where the electronic device is currently located; and determines each normal vector of the target geofence, wherein the target geofence consists of N boundary vertices in a preset order The connection is formed, the normal vector is perpendicular to the edge vector of the target geographical fence, the edge vector is a vector formed by connecting two adjacent boundary vertices of the target geographical fence, and N is an integer greater than 2; according to the The dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector determines the positional relationship between the first position point and the target geofence, wherein the target boundary vertex is the target geofence At some or all of the boundary vertices in , the target normal vector is a normal vector perpendicular to the edge vector at the target boundary vertex. In this way, the vector method is used to detect geofences on electronic devices, avoiding the complex operations involved in the traditional cross number method, and only using four simple arithmetic operations, which can effectively reduce the computational complexity of fence detection and greatly reduce calculations. quantity and improve detection efficiency.
本申请实施例中的地理围栏检测装置可以是电子设备,也可以是电子设备中的部件,例如集成电路或芯片。该电子设备可以是终端,也可以为除终端之外的其他设备。示例性的,电子设备可以为手机、平板电脑、笔记本电脑、掌上电脑、车载电子设备、移动上网装置(Mobile Internet Device,MID)、增强现实(Augmented Reality,AR)/虚拟现实(Virtual Reality,VR)设备、机器人、可穿戴设备、超级移动个人计算机(Ultra-Mobile Personal Computer,UMPC)、上网本或者个人数字助理(Personal Digital Assistant,PDA)等,还可以为服务器、网络附属存储器(Network Attached Storage,NAS)、个人计算机(Personal Computer,PC)、电视机(Television,TV)、柜员机或者自助机等,本申请实施例不作具体限定。The geofence detection device in the embodiment of the present application may be an electronic device or a component of the electronic device, such as an integrated circuit or chip. The electronic device may be a terminal or other devices other than the terminal. For example, the electronic device can be a mobile phone, a tablet computer, a notebook computer, a handheld computer, a vehicle-mounted electronic device, a mobile Internet device (MID), or an augmented reality (Augmented Reality, AR)/virtual reality (Virtual Reality, VR) ) equipment, robots, wearable devices, ultra-mobile personal computers (Ultra-Mobile Personal Computer, UMPC), netbooks or personal digital assistants (Personal Digital Assistant, PDA), etc., and can also be servers, network attached storage (Network Attached Storage, NAS), personal computer (Personal Computer, PC), television (Television, TV), teller machine or self-service machine, etc., the embodiments of this application are not specifically limited.
本申请实施例中的地理围栏检测装置可以为具有操作系统的装置。该操作系统可以为安卓(Android)操作系统,可以为ios操作系统,还可以为其他可能的操作系统,本申请实施例不作具体限定。The geofence detection device in the embodiment of the present application may be a device with an operating system. The operating system can be an Android operating system, an ios operating system, or other possible operating systems, which are not specifically limited in the embodiments of this application.
本申请实施例提供的地理围栏检测装置能够实现图4至图12的实施例实现的各个过程,为避免重复,这里不再赘述。 The geofence detection device provided by the embodiment of the present application can implement various processes implemented by the embodiments of Figures 4 to 12. To avoid duplication, they will not be described again here.
可选地,如图14所示,本申请实施例还提供一种电子设备1400,包括处理器1401和存储器1402,存储器1402上存储有可在所述处理器1401上运行的程序或指令,该程序或指令被处理器1401执行时实现上述地理围栏检测方法实施例的各个步骤,且能达到相同的技术效果,为避免重复,这里不再赘述。Optionally, as shown in Figure 14, this embodiment of the present application also provides an electronic device 1400, including a processor 1401 and a memory 1402. The memory 1402 stores programs or instructions that can be run on the processor 1401. When the program or instruction is executed by the processor 1401, each step of the above geofence detection method embodiment is implemented and the same technical effect can be achieved. To avoid duplication, the details will not be described here.
需要说明的是,本申请实施例中的电子设备包括上述所述的移动电子设备和非移动电子设备。It should be noted that the electronic devices in the embodiments of the present application include the above-mentioned mobile electronic devices and non-mobile electronic devices.
图15为实现本申请实施例的一种电子设备的硬件结构示意图。Figure 15 is a schematic diagram of the hardware structure of an electronic device that implements an embodiment of the present application.
该电子设备1500包括但不限于:射频单元1501、网络模块1502、音频输出单元1503、输入单元1504、传感器1505、显示单元1506、用户输入单元1507、接口单元1508、存储器1509、以及处理器1510等部件。The electronic device 1500 includes but is not limited to: radio frequency unit 1501, network module 1502, audio output unit 1503, input unit 1504, sensor 1505, display unit 1506, user input unit 1507, interface unit 1508, memory 1509, processor 1510, etc. part.
本领域技术人员可以理解,电子设备1500还可以包括给各个部件供电的电源(比如电池),电源可以通过电源管理系统与处理器1510逻辑相连,从而通过电源管理系统实现管理充电、放电、以及功耗管理等功能。图15中示出的电子设备结构并不构成对电子设备的限定,电子设备可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置,在此不再赘述。Those skilled in the art can understand that the electronic device 1500 may also include a power supply (such as a battery) that supplies power to various components. The power supply may be logically connected to the processor 1510 through a power management system, thereby managing charging, discharging, and function through the power management system. Consumption management and other functions. The structure of the electronic device shown in Figure 15 does not constitute a limitation of the electronic device. The electronic device may include more or less components than shown in the figure, or combine certain components, or arrange different components, which will not be described again here. .
其中,处理器1510,用于:Among them, processor 1510 is used for:
获取电子设备当前所处的第一位置点;Obtain the first location point where the electronic device is currently located;
分别确定目标地理围栏的各个法向量,其中,所述目标地理围栏由N个边界顶点按预设顺序连接形成,所述法向量与所述目标地理围栏的边向量垂直,所述边向量为所述目标地理围栏的相邻两个边界顶点连接形成的向量,N为大于2的整数;Determine each normal vector of the target geofence respectively, wherein the target geofence is formed by connecting N boundary vertices in a preset order, the normal vector is perpendicular to the edge vector of the target geofence, and the edge vector is The vector formed by connecting two adjacent boundary vertices of the target geofence, N is an integer greater than 2;
根据所述第一位置点与目标边界顶点连接形成的向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,其中,所述目标边界顶点为所述目标地理围栏中的部分或全部边界顶点,所述目标法向量为与所述目标边界顶点处的边向量垂直的法向量。The positional relationship between the first position point and the target geofence is determined according to the dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector, wherein the target boundary vertex is the For some or all boundary vertices in the target geofence, the target normal vector is a normal vector perpendicular to the edge vector at the target boundary vertex.
可选地,处理器1510,还用于:Optionally, processor 1510 is also used to:
确定所述目标地理围栏的外接矩形区域,其中,所述目标地理围栏的所有边界顶点均位于所述外接矩形区域内;Determine a circumscribed rectangular area of the target geofence, wherein all boundary vertices of the target geofence are located within the circumscribed rectangular area;
确定所述第一位置点与所述外接矩形区域的位置关系;Determine the positional relationship between the first position point and the circumscribed rectangular area;
在确定所述第一位置点不位于所述外接矩形区域外部的情况下,根据所述第一位置点与目标边界顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系。When it is determined that the first position point is not located outside the circumscribed rectangular area, the first position point is determined based on the dot product of the connecting vector between the first position point and the target boundary vertex and the target normal vector. The location relationship to the target geofence.
可选地,所述法向量指向所述目标地理围栏的内部;Optionally, the normal vector points to the interior of the target geofence;
处理器1510,还用于:Processor 1510, also used for:
在第一向量与所述目标法向量的点积大于0的情况下,确定所述第一位置点位于所述目标地理围栏内部,其中,所述第一向量为自所述目标边界顶点指向所述第一位置点的向 量;When the dot product of the first vector and the target normal vector is greater than 0, it is determined that the first location point is located inside the target geofence, wherein the first vector points from the target boundary vertex to the target geofence. Describe the direction of the first position point quantity;
在所述第一向量与所述目标法向量的点积小于0的情况下,确定所述第一位置点位于所述目标地理围栏外部。When the dot product of the first vector and the target normal vector is less than 0, it is determined that the first location point is located outside the target geofence.
可选地,处理器1510,还用于:Optionally, processor 1510 is also used to:
在所述电子设备于第一时刻位于所述目标地理围栏内部的情况下,存储所述电子设备在所述第一时刻所处的第二位置点,所述第一时刻为当前时刻之前的时刻;When the electronic device is located inside the target geofence at the first time, store the second location point of the electronic device at the first time, and the first time is the time before the current time. ;
确定第二向量和第一夹角,其中,所述第二向量为自所述第二位置点指向所述第一位置点的向量,所述第一夹角为所述第二向量与直角坐标系中的-y轴的夹角;Determine the second vector and the first included angle, where the second vector is a vector from the second position point to the first position point, and the first included angle is the second vector and the rectangular coordinate The angle between the -y axis in the system;
根据所述第一夹角,对所述目标地理围栏的边界顶点进行坐标转换,得到所述目标地理围栏的边界顶点在第二坐标系下的纵坐标值,其中,所述第二坐标系为所述直角坐标系逆时针旋转所述第一夹角后的坐标系;According to the first included angle, coordinate transformation is performed on the boundary vertex of the target geofence to obtain the ordinate value of the boundary vertex of the target geofence in a second coordinate system, where the second coordinate system is The coordinate system after rotating the first included angle counterclockwise from the Cartesian coordinate system;
根据所述目标地理围栏的边界顶点在所述第二坐标系下的纵坐标值与所述第二位置点在所述第二坐标系下的纵坐标值,确定所述目标边界顶点,其中,所述目标边界顶点位于第一法线的第一侧,所述第一法线与所述第二向量垂直,所述第一位置点位于所述第一法线的第一侧。The target boundary vertex is determined according to the ordinate value of the boundary vertex of the target geofence in the second coordinate system and the ordinate value of the second location point in the second coordinate system, where, The target boundary vertex is located on a first side of a first normal line, the first normal line is perpendicular to the second vector, and the first position point is located on a first side of the first normal line.
可选地,所述第二坐标系的原点为所述第二位置点,所述第二位置点在所述第二坐标系下的纵坐标值为0;Optionally, the origin of the second coordinate system is the second position point, and the ordinate value of the second position point in the second coordinate system is 0;
处理器1510,还用于:Processor 1510, also used for:
在第一边界顶点在所述第二坐标系下的纵坐标值小于或等于0的情况下,确定所述第一边界顶点为所述目标边界顶点,其中,所述第一边界顶点为所述目标地理围栏中的任一边界顶点;When the ordinate value of the first boundary vertex in the second coordinate system is less than or equal to 0, the first boundary vertex is determined to be the target boundary vertex, wherein the first boundary vertex is the Any boundary vertex in the target geofence;
在所述第一边界顶点在所述第二坐标系下的纵坐标值大于0的情况下,确定所述第一边界顶点不为所述目标边界顶点。When the ordinate value of the first boundary vertex in the second coordinate system is greater than 0, it is determined that the first boundary vertex is not the target boundary vertex.
可选地,处理器1510,还用于:Optionally, processor 1510 is also used to:
在所述电子设备于第二时刻位于所述目标地理围栏内部的情况下,存储所述电子设备在所述第二时刻所处的第三位置点,所述第二时刻为当前时刻之前的时刻;When the electronic device is located inside the target geofence at the second time, store the third location point of the electronic device at the second time, and the second time is the time before the current time. ;
根据所述第三位置点分别沿预设的M个方向与所述目标地理围栏的边界的距离,生成空间环境表,其中,所述空间环境表中存储有方向与距离的对应关系,所述M个方向中相邻两个方向之间间隔预设角度,M等于360度除以所述预设角度;According to the distances between the third location point and the boundary of the target geofence along the preset M directions, a spatial environment table is generated, wherein the spatial environment table stores a corresponding relationship between directions and distances. There is a preset angle between two adjacent directions in the M directions, and M is equal to 360 degrees divided by the preset angle;
确定所述第一位置点相对所述第三位置点的第一距离和第一方向;Determine a first distance and a first direction of the first position point relative to the third position point;
从所述空间环境表中查询所述第一方向对应的第二距离;Query the second distance corresponding to the first direction from the spatial environment table;
在所述第一距离大于所述第二距离的情况下,根据所述第一位置点与目标边界顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系。When the first distance is greater than the second distance, the distance between the first position point and the target is determined based on the dot product of the connecting vector between the first position point and the target boundary vertex and the target normal vector. Geofence location relationships.
可选地,处理器1510,还用于:Optionally, processor 1510 is also used to:
确定第三向量分别与所述M个方向中各个方向的夹角,其中,所述第三向量为自所 述第三位置点指向所述第一位置点的向量;Determine the angle between the third vector and each of the M directions, where the third vector is a vector from the third position point pointing to the first position point;
根据所述第三向量分别与所述M个方向中各个方向的夹角和所述第三向量的模值,确定所述M个方向中各个方向的距离改变值;Determine the distance change value in each of the M directions according to the angle between the third vector and each of the M directions and the modulus of the third vector;
根据所述M个方向中各个方向的距离改变值,更新所述空间环境表。The spatial environment table is updated according to the distance change value in each of the M directions.
本申请实施例中的电子设备,获取电子设备当前所处的第一位置点;分别确定目标地理围栏的各个法向量,其中,所述目标地理围栏由N个边界顶点按预设顺序连接形成,所述法向量与所述目标地理围栏的边向量垂直,所述边向量为所述目标地理围栏的相邻两个边界顶点连接形成的向量,N为大于2的整数;根据所述第一位置点与目标边界顶点连接形成的向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,其中,所述目标边界顶点为所述目标地理围栏中的部分或全部边界顶点,所述目标法向量为与所述目标边界顶点处的边向量垂直的法向量。这样,通过向量法来对电子设备进行地理围栏检测,避免了传统交叉数法中涉及的复杂运算,而只用到了简单的四则运算,从而能够有效降低围栏检测的计算复杂度,极大减少计算量,提升检测效率。The electronic device in the embodiment of the present application obtains the first position point where the electronic device is currently located; and determines each normal vector of the target geofence, wherein the target geofence is formed by connecting N boundary vertices in a preset order, The normal vector is perpendicular to the edge vector of the target geofence, the edge vector is a vector formed by connecting two adjacent boundary vertices of the target geofence, and N is an integer greater than 2; according to the first position The dot product of the vector formed by connecting the point and the target boundary vertex and the target normal vector determines the positional relationship between the first position point and the target geofence, wherein the target boundary vertex is part of the target geofence. Or all boundary vertices, the target normal vector is a normal vector perpendicular to the edge vector at the target boundary vertex. In this way, the vector method is used to detect geofences on electronic devices, avoiding the complex operations involved in the traditional cross number method, and only using four simple arithmetic operations, which can effectively reduce the computational complexity of fence detection and greatly reduce calculations. quantity and improve detection efficiency.
应理解的是,本申请实施例中,输入单元1504可以包括图形处理器(Graphics Processing Unit,GPU)15041和麦克风15042,图形处理器15041对在视频捕获模式或图像捕获模式中由图像捕获装置(如摄像头)获得的静态图片或视频的图像数据进行处理。显示单元1506可包括显示面板15061,可以采用液晶显示器、有机发光二极管等形式来配置显示面板15061。用户输入单元1507包括触控面板15071以及其他输入设备15072中的至少一种。触控面板15071,也称为触摸屏。触控面板15071可包括触摸检测装置和触摸控制器两个部分。其他输入设备15072可以包括但不限于物理键盘、功能键(比如音量控制按键、开关按键等)、轨迹球、鼠标、操作杆,在此不再赘述。It should be understood that in the embodiment of the present application, the input unit 1504 may include a graphics processor (Graphics Processing Unit, GPU) 15041 and a microphone 15042. The graphics processor 15041 is responsible for the image capture device (GPU) in the video capture mode or the image capture mode. Process the image data of still pictures or videos obtained by cameras (such as cameras). The display unit 1506 may include a display panel 15061, which may be configured in the form of a liquid crystal display, an organic light emitting diode, or the like. The user input unit 1507 includes a touch panel 15071 and at least one of other input devices 15072 . Touch panel 15071, also known as touch screen. The touch panel 15071 may include two parts: a touch detection device and a touch controller. Other input devices 15072 may include but are not limited to physical keyboards, function keys (such as volume control keys, switch keys, etc.), trackballs, mice, and joysticks, which will not be described again here.
存储器1509可用于存储软件程序以及各种数据。存储器1509可主要包括存储程序或指令的第一存储区和存储数据的第二存储区,其中,第一存储区可存储操作系统、至少一个功能所需的应用程序或指令(比如声音播放功能、图像播放功能等)等。此外,存储器1509可以包括易失性存储器或非易失性存储器,或者,存储器1509可以包括易失性和非易失性存储器两者。其中,非易失性存储器可以是只读存储器(Read-Only Memory,ROM)、可编程只读存储器(Programmable ROM,PROM)、可擦除可编程只读存储器(Erasable PROM,EPROM)、电可擦除可编程只读存储器(Electrically EPROM,EEPROM)或闪存。易失性存储器可以是随机存取存储器(Random Access Memory,RAM),静态随机存取存储器(Static RAM,SRAM)、动态随机存取存储器(Dynamic RAM,DRAM)、同步动态随机存取存储器(Synchronous DRAM,SDRAM)、双倍数据速率同步动态随机存取存储器(Double Data Rate SDRAM,DDRSDRAM)、增强型同步动态随机存取存储器(Enhanced SDRAM,ESDRAM)、同步连接动态随机存取存储器(Synch link DRAM,SLDRAM)和直接内存总线随机存取存储器(Direct Rambus RAM,DRRAM)。本申请实施例中的存储器1509包括但不限于这些和任意其它适合类型的存储器。 Memory 1509 may be used to store software programs as well as various data. The memory 1509 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, Image playback function, etc.) etc. Additionally, memory 1509 may include volatile memory or nonvolatile memory, or memory 1509 may include both volatile and nonvolatile memory. Among them, the non-volatile memory can be read-only memory (Read-Only Memory, ROM), programmable read-only memory (Programmable ROM, PROM), erasable programmable read-only memory (Erasable PROM, EPROM), electrically removable memory. Erase programmable read-only memory (Electrically EPROM, EEPROM) or flash memory. Volatile memory can be random access memory (Random Access Memory, RAM), static random access memory (Static RAM, SRAM), dynamic random access memory (Dynamic RAM, DRAM), synchronous dynamic random access memory (Synchronous DRAM, SDRAM), double data rate synchronous dynamic random access memory (Double Data Rate SDRAM, DDRSDRAM), enhanced synchronous dynamic random access memory (Enhanced SDRAM, ESDRAM), synchronous link dynamic random access memory (Synch link DRAM) , SLDRAM) and direct memory bus random access memory (Direct Rambus RAM, DRRAM). Memory 1509 in embodiments of the present application includes, but is not limited to, these and any other suitable types of memory.
处理器1510可包括一个或多个处理单元;可选地,处理器1510集成应用处理器和调制解调处理器,其中,应用处理器主要处理涉及操作系统、用户界面和应用程序等的操作,调制解调处理器主要处理无线通信信号,如基带处理器。可以理解的是,上述调制解调处理器也可以不集成到处理器1510中。The processor 1510 may include one or more processing units; optionally, the processor 1510 integrates an application processor and a modem processor, where the application processor mainly handles operations related to the operating system, user interface, application programs, etc., Modem processors mainly process wireless communication signals, such as baseband processors. It can be understood that the above modem processor may not be integrated into the processor 1510.
本申请实施例还提供一种可读存储介质,所述可读存储介质上存储有程序或指令,该程序或指令被处理器执行时实现上述地理围栏检测方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。其中,所述处理器为上述实施例中所述的电子设备中的处理器。所述可读存储介质,包括计算机可读存储介质,如计算机只读存储器ROM、随机存取存储器RAM、磁碟或者光盘等。Embodiments of the present application also provide a readable storage medium. Programs or instructions are stored on the readable storage medium. When the program or instructions are executed by a processor, each process of the above geofence detection method embodiment is implemented, and can achieve The same technical effects are not repeated here to avoid repetition. Wherein, the processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes computer readable storage media, such as computer read-only memory ROM, random access memory RAM, magnetic disk or optical disk, etc.
本申请实施例另提供了一种芯片,所述芯片包括处理器和通信接口,所述通信接口和所述处理器耦合,所述处理器用于运行程序或指令,实现上述地理围栏检测方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。应理解,本申请实施例提到的芯片还可以称为系统级芯片、系统芯片、芯片系统或片上系统芯片等。An embodiment of the present application further provides a chip. The chip includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the above embodiments of the geofence detection method. Each process can achieve the same technical effect. To avoid repetition, we will not go into details here. It should be understood that the chips mentioned in the embodiments of this application may also be called system-on-chip, system-on-a-chip, system-on-a-chip or system-on-chip, etc.
本申请实施例提供一种计算机程序产品,该程序产品被存储在存储介质中,该程序产品被至少一个处理器执行以实现如上述地理围栏检测方法实施例的各个过程,且能达到相同的技术效果,为避免重复,这里不再赘述。Embodiments of the present application provide a computer program product. The program product is stored in a storage medium. The program product is executed by at least one processor to implement each process of the above geofence detection method embodiment, and can achieve the same technology. The effect will not be described here to avoid repetition.
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者装置不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者装置所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者装置中还存在另外的相同要素。此外,需要指出的是,本申请实施方式中的方法和装置的范围不限按示出或讨论的顺序来执行功能,还可包括根据所涉及的功能按基本同时的方式或按相反的顺序来执行功能,例如,可以按不同于所描述的次序来执行所描述的方法,并且还可以添加、省去、或组合各种步骤。另外,参照某些示例所描述的特征可在其他示例中被组合。通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对相关技术中技术做出贡献的部分可以以计算机软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端(可以是手机,计算机,服务器,或者网络设备等)执行本申请各个实施例所述的方法。上面结合附图对本申请的实施例进行了描述,但是本申请并不局限于上述的具体实施方式,上述的具体实施方式仅仅是示意性的,而不是限制性的,本领域的普通技术人员在本申请的启示下,在不脱离本申请宗旨和权利要求所保护的范围情况下,还可做出很多形式,均属于本申请的保护之内。 It should be noted that, in this document, the terms "comprising", "comprises" or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article or device that includes a series of elements not only includes those elements, It also includes other elements not expressly listed or inherent in the process, method, article or apparatus. Without further limitation, an element defined by the statement "comprises a..." does not exclude the presence of additional identical elements in a process, method, article or apparatus that includes that element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, but may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved. Functions may be performed, for example, the methods described may be performed in an order different from that described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples. Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus the necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is better. implementation. Based on this understanding, the technical solution of the present application can be embodied in the form of a computer software product in essence or in other words, the part that contributes to the technology in related technologies. The computer software product is stored in a storage medium (such as ROM/RAM, magnetic disc, optical disk), including several instructions to cause a terminal (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in various embodiments of this application. The embodiments of the present application have been described above in conjunction with the accompanying drawings. However, the present application is not limited to the above-mentioned specific implementations. The above-mentioned specific implementations are only illustrative and not restrictive. Those of ordinary skill in the art will Inspired by this application, many forms can be made without departing from the purpose of this application and the scope protected by the claims, all of which fall within the protection of this application.

Claims (19)

  1. 一种地理围栏检测方法,包括:A geofence detection method including:
    获取电子设备当前所处的第一位置点;Obtain the first location point where the electronic device is currently located;
    分别确定目标地理围栏的各个法向量,其中,所述目标地理围栏由N个边界顶点按预设顺序连接形成,所述法向量与所述目标地理围栏的边向量垂直,所述边向量为所述目标地理围栏的相邻两个边界顶点连接形成的向量,N为大于2的整数;Determine each normal vector of the target geofence respectively, wherein the target geofence is formed by connecting N boundary vertices in a preset order, the normal vector is perpendicular to the edge vector of the target geofence, and the edge vector is The vector formed by connecting two adjacent boundary vertices of the target geofence, N is an integer greater than 2;
    根据所述第一位置点与目标边界顶点连接形成的向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,其中,所述目标边界顶点为所述目标地理围栏中的部分或全部边界顶点,所述目标法向量为与所述目标边界顶点处的边向量垂直的法向量。The positional relationship between the first position point and the target geofence is determined according to the dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector, wherein the target boundary vertex is the For some or all boundary vertices in the target geofence, the target normal vector is a normal vector perpendicular to the edge vector at the target boundary vertex.
  2. 根据权利要求1所述的方法,其中,所述获取电子设备当前所处的第一位置点之后,所述根据所述第一位置点与目标边界顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系之前,所述方法还包括:The method according to claim 1, wherein after obtaining the first position point where the electronic device is currently located, the method is based on the dot product of the connection vector between the first position point and the target boundary vertex and the target normal vector. , before determining the positional relationship between the first location point and the target geofence, the method further includes:
    确定所述目标地理围栏的外接矩形区域,其中,所述目标地理围栏的所有边界顶点均位于所述外接矩形区域内;Determine a circumscribed rectangular area of the target geofence, wherein all boundary vertices of the target geofence are located within the circumscribed rectangular area;
    确定所述第一位置点与所述外接矩形区域的位置关系;Determine the positional relationship between the first position point and the circumscribed rectangular area;
    所述根据所述第一位置点与目标边界顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,包括:Determining the positional relationship between the first position point and the target geofence based on the dot product of the connection vector between the first position point and the target boundary vertex and the target normal vector includes:
    在确定所述第一位置点不位于所述外接矩形区域外部的情况下,根据所述第一位置点与目标边界顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系。When it is determined that the first position point is not located outside the circumscribed rectangular area, the first position point is determined based on the dot product of the connecting vector between the first position point and the target boundary vertex and the target normal vector. The location relationship to the target geofence.
  3. 根据权利要求1所述的方法,其中,所述法向量指向所述目标地理围栏的内部;The method of claim 1, wherein the normal vector points into the interior of the target geofence;
    所述根据所述第一位置点与目标边界顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,包括:Determining the positional relationship between the first position point and the target geofence based on the dot product of the connection vector between the first position point and the target boundary vertex and the target normal vector includes:
    在第一向量与所述目标法向量的点积大于0的情况下,确定所述第一位置点位于所述目标地理围栏内部,其中,所述第一向量为自所述目标边界顶点指向所述第一位置点的向量;When the dot product of the first vector and the target normal vector is greater than 0, it is determined that the first location point is located inside the target geofence, wherein the first vector points from the target boundary vertex to the target geofence. The vector of the first position point;
    在所述第一向量与所述目标法向量的点积小于0的情况下,确定所述第一位置点位于所述目标地理围栏外部。When the dot product of the first vector and the target normal vector is less than 0, it is determined that the first location point is located outside the target geofence.
  4. 根据权利要求1至3中任一项所述的方法,其中,所述获取电子设备当前所处的第一位置点之前,所述方法还包括:The method according to any one of claims 1 to 3, wherein before obtaining the first location point where the electronic device is currently located, the method further includes:
    在所述电子设备于第一时刻位于所述目标地理围栏内部的情况下,存储所述电子设备在所述第一时刻所处的第二位置点,所述第一时刻为当前时刻之前的时刻;When the electronic device is located inside the target geofence at the first time, store the second location point of the electronic device at the first time, and the first time is the time before the current time. ;
    所述获取电子设备当前所处的第一位置点之后,所述根据所述第一位置点与目标边界 顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系之前,所述方法还包括:After obtaining the first location point where the electronic device is currently located, the method determines whether the first location point and the target boundary are Before determining the positional relationship between the first position point and the target geofence based on the dot product of the connection vector of the vertex and the target normal vector, the method further includes:
    确定第二向量和第一夹角,其中,所述第二向量为自所述第二位置点指向所述第一位置点的向量,所述第一夹角为所述第二向量与直角坐标系中的-y轴的夹角;Determine the second vector and the first included angle, where the second vector is a vector from the second position point to the first position point, and the first included angle is the second vector and the rectangular coordinate The angle between the -y axis in the system;
    根据所述第一夹角,对所述目标地理围栏的边界顶点进行坐标转换,得到所述目标地理围栏的边界顶点在第二坐标系下的纵坐标值,其中,所述第二坐标系为所述直角坐标系逆时针旋转所述第一夹角后的坐标系;According to the first included angle, coordinate transformation is performed on the boundary vertex of the target geofence to obtain the ordinate value of the boundary vertex of the target geofence in a second coordinate system, where the second coordinate system is The coordinate system after rotating the first included angle counterclockwise from the Cartesian coordinate system;
    根据所述目标地理围栏的边界顶点在所述第二坐标系下的纵坐标值与所述第二位置点在所述第二坐标系下的纵坐标值,确定所述目标边界顶点,其中,所述目标边界顶点位于第一法线的第一侧,所述第一法线与所述第二向量垂直,所述第一位置点位于所述第一法线的第一侧。The target boundary vertex is determined according to the ordinate value of the boundary vertex of the target geofence in the second coordinate system and the ordinate value of the second location point in the second coordinate system, where, The target boundary vertex is located on a first side of a first normal line, the first normal line is perpendicular to the second vector, and the first position point is located on a first side of the first normal line.
  5. 根据权利要求4所述的方法,其中,所述第二坐标系的原点为所述第二位置点,所述第二位置点在所述第二坐标系下的纵坐标值为0;The method according to claim 4, wherein the origin of the second coordinate system is the second position point, and the ordinate value of the second position point in the second coordinate system is 0;
    所述根据所述目标地理围栏的边界顶点在所述第二坐标系下的纵坐标值与所述第二位置点在所述第二坐标系下的纵坐标值,确定所述目标边界顶点,包括:Determining the target boundary vertex based on the ordinate value of the boundary vertex of the target geofence in the second coordinate system and the ordinate value of the second location point in the second coordinate system, include:
    在第一边界顶点在所述第二坐标系下的纵坐标值小于或等于0的情况下,确定所述第一边界顶点为所述目标边界顶点,其中,所述第一边界顶点为所述目标地理围栏中的任一边界顶点;When the ordinate value of the first boundary vertex in the second coordinate system is less than or equal to 0, the first boundary vertex is determined to be the target boundary vertex, wherein the first boundary vertex is the Any boundary vertex in the target geofence;
    在所述第一边界顶点在所述第二坐标系下的纵坐标值大于0的情况下,确定所述第一边界顶点不为所述目标边界顶点。When the ordinate value of the first boundary vertex in the second coordinate system is greater than 0, it is determined that the first boundary vertex is not the target boundary vertex.
  6. 根据权利要求1至3中任一项所述的方法,其中,所述获取电子设备当前所处的第一位置点之前,所述方法还包括:The method according to any one of claims 1 to 3, wherein before obtaining the first location point where the electronic device is currently located, the method further includes:
    在所述电子设备于第二时刻位于所述目标地理围栏内部的情况下,存储所述电子设备在所述第二时刻所处的第三位置点,所述第二时刻为当前时刻之前的时刻;When the electronic device is located inside the target geofence at the second time, store the third location point of the electronic device at the second time, and the second time is the time before the current time. ;
    根据所述第三位置点分别沿预设的M个方向与所述目标地理围栏的边界的距离,生成空间环境表,其中,所述空间环境表中存储有方向与距离的对应关系,所述M个方向中相邻两个方向之间间隔预设角度,M等于360度除以所述预设角度;According to the distances between the third location point and the boundary of the target geofence along the preset M directions, a spatial environment table is generated, wherein the spatial environment table stores a corresponding relationship between directions and distances. There is a preset angle between two adjacent directions in the M directions, and M is equal to 360 degrees divided by the preset angle;
    所述获取电子设备当前所处的第一位置点之后,所述根据所述第一位置点与目标边界顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系之前,所述方法还包括:After obtaining the first position point where the electronic device is currently located, determining the first position point and the target normal vector based on the dot product of the connection vector between the first position point and the target boundary vertex and the target normal vector. Before determining the location relationship of the target geofence, the method further includes:
    确定所述第一位置点相对所述第三位置点的第一距离和第一方向;Determine a first distance and a first direction of the first position point relative to the third position point;
    从所述空间环境表中查询所述第一方向对应的第二距离;Query the second distance corresponding to the first direction from the spatial environment table;
    所述根据所述第一位置点与目标边界顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,包括:Determining the positional relationship between the first position point and the target geofence based on the dot product of the connection vector between the first position point and the target boundary vertex and the target normal vector includes:
    在所述第一距离大于所述第二距离的情况下,根据所述第一位置点与目标边界顶点的 连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系。In the case where the first distance is greater than the second distance, according to the relationship between the first position point and the target boundary vertex, The dot product of the connection vector and the target normal vector determines the positional relationship between the first position point and the target geofence.
  7. 根据权利要求6所述的方法,其中,在确定所述第一位置点位于所述目标地理围栏内部的情况下,所述方法还包括:The method of claim 6, wherein, if it is determined that the first location point is located inside the target geofence, the method further includes:
    确定第三向量分别与所述M个方向中各个方向的夹角,其中,所述第三向量为自所述第三位置点指向所述第一位置点的向量;Determine the angle between the third vector and each of the M directions, wherein the third vector is a vector from the third position point to the first position point;
    根据所述第三向量分别与所述M个方向中各个方向的夹角和所述第三向量的模值,确定所述M个方向中各个方向的距离改变值;Determine the distance change value in each of the M directions according to the angle between the third vector and each of the M directions and the modulus of the third vector;
    根据所述M个方向中各个方向的距离改变值,更新所述空间环境表。The spatial environment table is updated according to the distance change value in each of the M directions.
  8. 一种地理围栏检测装置,包括:A geofence detection device including:
    获取模块,用于获取电子设备当前所处的第一位置点;The acquisition module is used to acquire the first position point where the electronic device is currently located;
    第一确定模块,用于分别确定目标地理围栏的各个法向量,其中,所述目标地理围栏由N个边界顶点按预设顺序连接形成,所述法向量与所述目标地理围栏的边向量垂直,所述边向量为所述目标地理围栏的相邻两个边界顶点连接形成的向量,N为大于2的整数;The first determination module is used to determine each normal vector of the target geographical fence, wherein the target geographical fence is formed by connecting N boundary vertices in a preset order, and the normal vector is perpendicular to the edge vector of the target geographical fence. , the edge vector is a vector formed by connecting two adjacent boundary vertices of the target geofence, and N is an integer greater than 2;
    第二确定模块,用于根据所述第一位置点与目标边界顶点连接形成的向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系,其中,所述目标边界顶点为所述目标地理围栏中的部分或全部边界顶点,所述目标法向量为与所述目标边界顶点处的边向量垂直的法向量。The second determination module is used to determine the positional relationship between the first position point and the target geofence according to the dot product of the vector formed by connecting the first position point and the target boundary vertex and the target normal vector, wherein, The target boundary vertex is part or all of the boundary vertices in the target geofence, and the target normal vector is a normal vector perpendicular to an edge vector at the target boundary vertex.
  9. 根据权利要求8所述的地理围栏检测装置,其中,所述地理围栏检测装置还包括:The geofence detection device according to claim 8, wherein the geofence detection device further includes:
    第三确定模块,用于确定所述目标地理围栏的外接矩形区域,其中,所述目标地理围栏的所有边界顶点均位于所述外接矩形区域内;A third determination module, configured to determine the circumscribed rectangular area of the target geofence, wherein all boundary vertices of the target geofence are located within the circumscribed rectangular area;
    第四确定模块,用于确定所述第一位置点与所述外接矩形区域的位置关系;The fourth determination module is used to determine the positional relationship between the first position point and the circumscribed rectangular area;
    所述第二确定模块用于在确定所述第一位置点不位于所述外接矩形区域外部的情况下,根据所述第一位置点与目标边界顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系。The second determination module is configured to determine based on the dot product of the connection vector between the first position point and the target boundary vertex and the target normal vector when it is determined that the first position point is not located outside the circumscribed rectangular area. , determine the positional relationship between the first location point and the target geofence.
  10. 根据权利要求8所述的地理围栏检测装置,其中,所述法向量指向所述目标地理围栏的内部;The geofence detection device of claim 8, wherein the normal vector points inside the target geofence;
    所述第二确定模块包括:The second determination module includes:
    第一确定单元,用于在第一向量与所述目标法向量的点积大于0的情况下,确定所述第一位置点位于所述目标地理围栏内部,其中,所述第一向量为自所述目标边界顶点指向所述第一位置点的向量;A first determination unit configured to determine that the first location point is located inside the target geofence when the dot product of the first vector and the target normal vector is greater than 0, wherein the first vector is A vector from the target boundary vertex pointing to the first position point;
    第二确定单元,用于在所述第一向量与所述目标法向量的点积小于0的情况下,确定所述第一位置点位于所述目标地理围栏外部。A second determination unit configured to determine that the first location point is located outside the target geofence when the dot product of the first vector and the target normal vector is less than 0.
  11. 根据权利要求8至10中任一项所述的地理围栏检测装置,其中,所述地理围栏检测装置还包括:The geofence detection device according to any one of claims 8 to 10, wherein the geofence detection device further includes:
    第一存储模块,用于在所述电子设备于第一时刻位于所述目标地理围栏内部的情况下, 存储所述电子设备在所述第一时刻所处的第二位置点,所述第一时刻为当前时刻之前的时刻;A first storage module configured to, when the electronic device is located inside the target geofence at the first moment, Store the second location point where the electronic device is at the first time, and the first time is the time before the current time;
    第五确定模块,用于确定第二向量和第一夹角,其中,所述第二向量为自所述第二位置点指向所述第一位置点的向量,所述第一夹角为所述第二向量与直角坐标系中的-y轴的夹角;The fifth determination module is used to determine the second vector and the first included angle, wherein the second vector is a vector from the second position point to the first position point, and the first included angle is the The angle between the second vector and the -y axis in the Cartesian coordinate system;
    坐标转换模块,用于根据所述第一夹角,对所述目标地理围栏的边界顶点进行坐标转换,得到所述目标地理围栏的边界顶点在第二坐标系下的纵坐标值,其中,所述第二坐标系为所述直角坐标系逆时针旋转所述第一夹角后的坐标系;A coordinate conversion module configured to perform coordinate conversion on the boundary vertex of the target geofence according to the first included angle to obtain the ordinate value of the boundary vertex of the target geofence in the second coordinate system, wherein: The second coordinate system is a coordinate system obtained by rotating the rectangular coordinate system counterclockwise by the first included angle;
    第六确定模块,用于根据所述目标地理围栏的边界顶点在所述第二坐标系下的纵坐标值与所述第二位置点在所述第二坐标系下的纵坐标值,确定所述目标边界顶点,其中,所述目标边界顶点位于第一法线的第一侧,所述第一法线与所述第二向量垂直,所述第一位置点位于所述第一法线的第一侧。The sixth determination module is used to determine the ordinate value of the boundary vertex of the target geofence in the second coordinate system and the ordinate value of the second location point in the second coordinate system. The target boundary vertex, wherein the target boundary vertex is located on a first side of a first normal line, the first normal line is perpendicular to the second vector, and the first position point is located on the first side of the first normal line First side.
  12. 根据权利要求11所述的地理围栏检测装置,其中,所述第二坐标系的原点为所述第二位置点,所述第二位置点在所述第二坐标系下的纵坐标值为0;The geofence detection device according to claim 11, wherein the origin of the second coordinate system is the second position point, and the ordinate value of the second position point in the second coordinate system is 0. ;
    所述第六确定模块包括:The sixth determination module includes:
    第三确定单元,用于在第一边界顶点在所述第二坐标系下的纵坐标值小于或等于0的情况下,确定所述第一边界顶点为所述目标边界顶点,其中,所述第一边界顶点为所述目标地理围栏中的任一边界顶点;A third determination unit configured to determine that the first boundary vertex is the target boundary vertex when the ordinate value of the first boundary vertex in the second coordinate system is less than or equal to 0, wherein, The first boundary vertex is any boundary vertex in the target geofence;
    第四确定单元,用于在所述第一边界顶点在所述第二坐标系下的纵坐标值大于0的情况下,确定所述第一边界顶点不为所述目标边界顶点。A fourth determination unit configured to determine that the first boundary vertex is not the target boundary vertex when the ordinate value of the first boundary vertex in the second coordinate system is greater than 0.
  13. 根据权利要求8至10中任一项所述的地理围栏检测装置,其中,所述地理围栏检测装置还包括:The geofence detection device according to any one of claims 8 to 10, wherein the geofence detection device further includes:
    第二存储模块,用于在所述电子设备于第二时刻位于所述目标地理围栏内部的情况下,存储所述电子设备在所述第二时刻所处的第三位置点,所述第二时刻为当前时刻之前的时刻;A second storage module configured to store the third location point of the electronic device at the second time when the electronic device is located inside the target geofence at the second time. The time is the time before the current time;
    生成模块,用于根据所述第三位置点分别沿预设的M个方向与所述目标地理围栏的边界的距离,生成空间环境表,其中,所述空间环境表中存储有方向与距离的对应关系,所述M个方向中相邻两个方向之间间隔预设角度,M等于360度除以所述预设角度;A generation module configured to generate a spatial environment table according to the distances between the third location point and the boundary of the target geofence along the preset M directions, wherein the spatial environment table stores directions and distances. Corresponding relationship, two adjacent directions among the M directions are separated by a preset angle, and M is equal to 360 degrees divided by the preset angle;
    第七确定模块,用于确定所述第一位置点相对所述第三位置点的第一距离和第一方向;A seventh determination module, used to determine the first distance and the first direction of the first position point relative to the third position point;
    查询模块,用于从所述空间环境表中查询所述第一方向对应的第二距离;A query module, used to query the second distance corresponding to the first direction from the spatial environment table;
    所述第二确定模块用于在所述第一距离大于所述第二距离的情况下,根据所述第一位置点与目标边界顶点的连线向量与目标法向量的点积,确定所述第一位置点与所述目标地理围栏的位置关系。The second determination module is configured to determine, when the first distance is greater than the second distance, the dot product of the connection vector between the first position point and the target boundary vertex and the target normal vector. The positional relationship between the first location point and the target geofence.
  14. 根据权利要求13所述的地理围栏检测装置,其中,所述地理围栏检测装置还包括: The geofence detection device according to claim 13, wherein the geofence detection device further includes:
    第八确定模块,用于在确定所述第一位置点位于所述目标地理围栏内部的情况下,确定第三向量分别与所述M个方向中各个方向的夹角,其中,所述第三向量为自所述第三位置点指向所述第一位置点的向量;An eighth determination module, configured to determine the angle between the third vector and each of the M directions respectively when it is determined that the first location point is located inside the target geofence, wherein the third vector The vector is a vector from the third position point to the first position point;
    第九确定模块,用于根据所述第三向量分别与所述M个方向中各个方向的夹角和所述第三向量的模值,确定所述M个方向中各个方向的距离改变值;A ninth determination module, configured to determine the distance change value in each of the M directions according to the angle between the third vector and each of the M directions and the modulus of the third vector;
    更新模块,用于根据所述M个方向中各个方向的距离改变值,更新所述空间环境表。An update module, configured to update the spatial environment table according to the distance change value in each of the M directions.
  15. 一种电子设备,包括处理器和存储器,所述存储器存储可在所述处理器上运行的程序或指令,所述程序或指令被所述处理器执行时实现如权利要求1-7中任一项所述的地理围栏检测方法的步骤。An electronic device, including a processor and a memory, the memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, any one of claims 1-7 is implemented. The steps of the geofence detection method described in Item 1.
  16. 一种电子设备,所述电子设备用于执行如权利要求1-7中任一项所述的地理围栏检测方法。An electronic device, the electronic device is used to perform the geofence detection method according to any one of claims 1-7.
  17. 一种可读存储介质,所述可读存储介质上存储程序或指令,所述程序或指令被处理器执行时实现如权利要求1-7中任一项所述的地理围栏检测方法的步骤。A readable storage medium on which a program or instructions are stored. When the program or instructions are executed by a processor, the steps of the geofence detection method according to any one of claims 1 to 7 are implemented.
  18. 一种芯片,所述芯片包括处理器和通信接口,所述通信接口和所述处理器耦合,所述处理器用于运行程序或指令,实现如权利要求1-7中任一项所述的地理围栏检测方法。A chip. The chip includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the geographic location as described in any one of claims 1-7. Fence detection methods.
  19. 一种计算机程序产品,所述计算机程序产品被存储在存储介质中,所述计算机程序产品被至少一个处理器执行以实现如权利要求1-7中任一项所述的地理围栏检测方法。 A computer program product, the computer program product is stored in a storage medium, and the computer program product is executed by at least one processor to implement the geofence detection method according to any one of claims 1-7.
PCT/CN2023/110485 2022-08-04 2023-08-01 Geofence detection method and apparatus and electronic device WO2024027684A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210931542.5A CN115209349A (en) 2022-08-04 2022-08-04 Geofence detection method and device and electronic equipment
CN202210931542.5 2022-08-04

Publications (1)

Publication Number Publication Date
WO2024027684A1 true WO2024027684A1 (en) 2024-02-08

Family

ID=83586069

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/110485 WO2024027684A1 (en) 2022-08-04 2023-08-01 Geofence detection method and apparatus and electronic device

Country Status (2)

Country Link
CN (1) CN115209349A (en)
WO (1) WO2024027684A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115209349A (en) * 2022-08-04 2022-10-18 维沃移动通信有限公司 Geofence detection method and device and electronic equipment

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108846882A (en) * 2018-06-25 2018-11-20 北京嘀嘀无限科技发展有限公司 A kind of method, apparatus and electronic equipment of determining point and fence relationship
CN113852914A (en) * 2021-09-23 2021-12-28 广东几米星联通讯有限公司 Position positioning method and positioning device for point to be inspected
CN115209349A (en) * 2022-08-04 2022-10-18 维沃移动通信有限公司 Geofence detection method and device and electronic equipment

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108846882A (en) * 2018-06-25 2018-11-20 北京嘀嘀无限科技发展有限公司 A kind of method, apparatus and electronic equipment of determining point and fence relationship
CN110633344A (en) * 2018-06-25 2019-12-31 北京嘀嘀无限科技发展有限公司 Method and device for determining point-to-fence relationship and electronic equipment
CN113852914A (en) * 2021-09-23 2021-12-28 广东几米星联通讯有限公司 Position positioning method and positioning device for point to be inspected
CN115209349A (en) * 2022-08-04 2022-10-18 维沃移动通信有限公司 Geofence detection method and device and electronic equipment

Also Published As

Publication number Publication date
CN115209349A (en) 2022-10-18

Similar Documents

Publication Publication Date Title
US11170741B2 (en) Method and apparatus for rendering items in a user interface
US20160358363A1 (en) Geo-Tagging Digital Images
US20170323478A1 (en) Method and apparatus for evaluating environmental structures for in-situ content augmentation
US8339399B2 (en) Declustering point-of-interest icons
US8306267B1 (en) Object tracking
WO2024027684A1 (en) Geofence detection method and apparatus and electronic device
US20180012403A1 (en) Method and device for computing a path in a game scene
US20090123088A1 (en) Tiled projections for planar processing of round earth data
US20150049080A1 (en) Method and Apparatus for Rendering Items in a User Interface
CN110362242B (en) Map display method and terminal equipment
US20230394756A1 (en) Three-dimensional reconstruction method, three-dimensional reconstruction apparatus and storage medium
US9245366B1 (en) Label placement for complex geographic polygons
WO2022227489A1 (en) Collision detection method and apparatus for objects, and device and storage medium
US9483496B1 (en) Label placement for line features
US20220357159A1 (en) Navigation Method, Navigation Apparatus, Electronic Device, and Storage Medium
US9928572B1 (en) Label orientation
CN108322889A (en) A kind of method, storage medium and the intelligent terminal of multisource data fusion indoor positioning
CN107578470B (en) Three-dimensional model processing method and device, server and storage medium
US8867785B2 (en) Method and apparatus for detecting proximate interface elements
JP7422222B2 (en) Collision detection method, apparatus, electronic device, storage medium and computer program for object
WO2015192716A1 (en) Scribe line search method and device based on electronic map
US9852542B1 (en) Methods and apparatus related to georeferenced pose of 3D models
CN115511701A (en) Method and device for converting geographic information
CN117576645B (en) Parking space detection method and device based on BEV visual angle and computer equipment
CN117308966B (en) Indoor positioning and navigation method, system and computer equipment

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 23849391

Country of ref document: EP

Kind code of ref document: A1