A Safety Warning Algorithm Based on Axis Aligned Bounding Box Method to Prevent Onsite Accidents of Mobile Construction Machineries

Mobile construction machineries are accident-prone on a dynamic construction site, as the site environment is constantly changing and continuous safety monitoring by human beings is impossible. These accidents usually happen in the form of machinery overturning or collapsing into risk areas, including the foundation pit, slopes, or soft soil area. Therefore, preventing mobile construction machineries from entering risk areas is the key. However, currently, there is a lack of practical safety management techniques to achieve this. Utilizing a wireless sensor device to collect the location information of mobile construction machineries, this research develops a safety warning algorithm to prevent the machineries moving into risk area and reduces onsite overturning or collapsing accidents. A modified axis aligned bounding box method is proposed according to the movement patterns of mobile construction machineries, and the warning algorithm is developed based on the onsite safety management regulations. The algorithm is validated in a real case simulation when machinery enters the warning zone. The simulation results showed that the overall algorithm combining the location sensing technology and the modified bounding box method could detect risk and give warnings in a timely manner. This algorithm can be implemented for the safety monitoring of mobile construction machineries in daily onsite management.


Introduction
With the increasing complexity of modern construction projects, the types and quantity of onsite construction machinery are also increasing, which brings more challenges for the safety management on construction sites. For example, in terms of housing and municipal engineering projects in China, the number of construction accidents has been increasing from 2015 to 2019, namely 442, 634, 692, 734, and 773 for each year [1]. Specifically, the 2018 and 2019 annual statistical reports of construction accidents in China show that 29.63% and 30.78% of total accidents in respective years have involved machineries, and they are from three categories: (1) construction machine and equipment injury; (2) foundation/ground collapsing accidents, which are caused by a lack of management of mobile machinery, and (3) others including vehicle injury [2,3]. Although there is no specific category for accidents related to mobile construction machineries, it is widely known that, compared to fixed construction equipment and facilities, mobile construction machineries are more frequently involved in onsite accidents.
Accidents involving construction machineries are likely to cause long project delays and large economic loss, as construction machineries are key components to keep projects on schedule and are also expensive equipment [4,5]. Some major accidents caused by

Literature Review
Many previous studies focused on the collapse of foundation pits or tunnels caused by deformation of a large settlement, ineffective original reinforcement, or lack of stability of support structures, while few studies considered collapsing accidents caused by mobile machinery [26][27][28][29]. How to prevent mobile machineries from overturning/collapsing into risk areas has not been explored. There are some previous studies on overturning accidents, but they are mainly focused on those machines whose main function is lifting operations. For example, Edwards et al., [30] and Mitrev and Marinković [31] calculated the safe working load and simulated operations to enhance the excavator stability of lifting tasks. Huidong et al., [32] made a virtual prototype simulation for safety of lifting operations on mobile cranes. These studies are limited to the lifting process rather than moving status of mobile machinery on construction sites.
Proximity detection/collision warning needs to collect real-time location data [20]. There are different types of position data acquisition technologies or devices available that can be implemented on construction sites, such as GPS, sensors and RFID [33,34]. Many commercial positioning and sensing devices can be used to provide location data of targeted objects or areas [20,35,36]. The method of proximity status analysis between mobile construction machineries and risk areas can also be regarded as an anti-collision or collision detection method. Previous studies on collision detection are mainly focused on preventing collision between machineries [22,[35][36][37][38], or between construction machineries and fixed construction items, or building elements [33,34] and workers on construction sites [39,40]. Ren and Wu [22] proposed a real-time automated anti-collision system to prevent collisions between a crane and fixed obstacles during the crane lifting operation process. Hwang [37] used ultra-wideband technology for the real-time monitoring of equipment operation and designed a platform with several functional modules, including real-time data acquisition, visualization, decision making, and possibility analysis of collision. Li, Gu and Jia [34] designed an anti-collision method using ultrasonic sensors to locate obstacles, and multisensor information fusion technologies are integrated for anti-collision warning. RFID can also be used for collision detection of construction machinery, such as hydraulic excavators and cranes [20,41]. Jo, Lee, Kim, Kim and Choi [39] designed an RFID-based warning and excavator control system to prevent collision accidents between equipment and workers. Most of these studies involved in proximity situations that focused mainly on preventing collisions between machinery and obvious obstacles. To prevent mobile machinery entering risk area, the main challenge is to detect the relationship of machinery with the identified risk areas from live onsite location data. For construction projects, using just-in-time onsite position data to give early safety warning and prevent accidents is an important area to be developed [42,43]. Based on previous published studies in this field, there is a lack of an effective algorithm developed for continuously monitoring the mobile machineries and preventing them entering risk areas on construction sites. In this study, a practical collision detection algorithm is developed which can use real-time location data of construction machinery to give safety warnings when machinery is entering onsite risk areas.

Research Methodology
The development of a safety warning algorithm has a few steps, including the establishing warning rules, developing a collision detection algorithm, collecting real-time location data and coordinating system development, as well as implementation and testing.

Establishing Warning Rules
Before the safety warning algorithm can be developed, warning rules need to be determined based on the onsite management regulations. Warning rules include safe distances and the classification of warning states.

Determining Safety Distances
The safety distance is the minimum distance that should be maintained between construction machinery and the risk area. Many rules, technical specifications, and regulations have been established to regulate the behavior of workers and machinery on construction sites. For example, China's "Administrative Regulations on the Work Safety of Construction Projects" states that warning signals must be clearly set up at the edge of holes, foundation pits, and other dangerous places [44]. China's "Technique Specification for Safety Operation of Construction Machinery" also specifies requirements for safety distances when machineries are working around these areas, as shown in Table 1.
On a construction site, the real-time distance between a construction machinery and risky area is to be compared with the specified safety distance. The real-time distance must be bigger than the safety distance, so when machinery is getting close to a risky area, the operator can have sufficient time to brake or make a turn to avoid entering the area. To make the algorithm suitable to be used for any machinery, the maximum distance requirement for all types of machines is adopted in this research, which is 2 m, as shown in Table 1. However, this distance could be adjusted in different situations and countries when implemented in real cases. For machineries moving at a relatively high speed and when more response time is needed, this distance can be further increased. The distance from edge of new embankment slope shall be no less than 1 m [45] Wheel loader The distance from the edge of slope, trench and pit should be more than 1.5 m when unloading [45] Concrete spreader The distance from other equipment should not be less than 0.6 m [45] Others Moving machinery from edge of foundation pit shall be no less than 2 m [46] 3.1.

Classify Safety Warning States
The safety distance is used to distinguish three areas ( Figure 1): the safe zone, the warning zone, and the risk area. The safe zone refers to the area that the machinery can work safely in and there is no need to take any prevention actions. The warning zone refers to the area that is less than the safety distance from the risk area, as specified in site regulations, where there is a need to take actions to move away and prevent accidents happening. The risk area refers to areas, such as foundation pits, sloped areas, or soft soil, where overturning and collapsing accidents will happen if construction machinery enters. The size of a risk area can be adjusted in consideration of the slope stability and soil property. For the construction site with an unstable slopy area, the risk area should be marked bigger according to empirical data. The distance from edge of new embankment slope shall be no less than 1 m [45] Wheel loader The distance from the edge of slope, trench and pit should be more than 1.5 m when unloading [45] Concrete spreader The distance from other equipment should not be less than 0.6 m [45] Others Moving machinery from edge of foundation pit shall be no less than 2 m [46] On a construction site, the real-time distance between a construction machinery and risky area is to be compared with the specified safety distance. The real-time distance must be bigger than the safety distance, so when machinery is getting close to a risky area, the operator can have sufficient time to brake or make a turn to avoid entering the area. To make the algorithm suitable to be used for any machinery, the maximum distance requirement for all types of machines is adopted in this research, which is 2 m, as shown in Table  1. However, this distance could be adjusted in different situations and countries when implemented in real cases. For machineries moving at a relatively high speed and when more response time is needed, this distance can be further increased.

Classify Safety Warning States
The safety distance is used to distinguish three areas ( Figure 1): the safe zone, the warning zone, and the risk area. The safe zone refers to the area that the machinery can work safely in and there is no need to take any prevention actions. The warning zone refers to the area that is less than the safety distance from the risk area, as specified in site regulations, where there is a need to take actions to move away and prevent accidents happening. The risk area refers to areas, such as foundation pits, sloped areas, or soft soil, where overturning and collapsing accidents will happen if construction machinery enters. The size of a risk area can be adjusted in consideration of the slope stability and soil property. For the construction site with an unstable slopy area, the risk area should be marked bigger according to empirical data. The movement pattern of construction machinery is examined. Construction machineries are usually large in size and can only move forward or backward in a straight or curved line. This means that either the head or rear part of the machinery will move into the risk area first. Therefore, warning signals will be triggered if the head or rear part of the machine enters the warning zone, and Figure 1 shows these two statuses: State 1 checks if there is a collision between the head of the moving machinery and the warning zone, and State 2 checks if there is a collision between the rear of the machinery and the warning zone. The distance between the nearest point of a moving machinery to the The movement pattern of construction machinery is examined. Construction machineries are usually large in size and can only move forward or backward in a straight or curved line. This means that either the head or rear part of the machinery will move into the risk area first. Therefore, warning signals will be triggered if the head or rear part of the machine enters the warning zone, and Figure 1 shows these two statuses: State 1 checks if there is a collision between the head of the moving machinery and the warning zone, and State 2 checks if there is a collision between the rear of the machinery and the warning zone. The distance between the nearest point of a moving machinery to the boundary of risk area is d, to the boundary of the warning zone is ∆d, and the safety distance adopted in this paper is D = 2 m (Figure 1).
Safe status: d > D; • State 1: The head of the machine enters the warning zone If the moving machine is going towards the warning zone, the critical state is that d = D and ∆d = 0, as shown in Figure 1. The head of the machine intersects with the warning zone boundary, which triggers the warning signal to be sent immediately. There is no need to conduct further detection of the rear part of the machine. Otherwise, it indicates that the head of the machine is in a safe zone, and then State 2 test is conducted to check if the rear part of the machinery intersects with the warning zone boundary.

•
State 2: The rear of the machine enters the warning zone In a similar way, if the rear of the machine intersects with the warning zone, the critical state is that d = D and ∆d = 0, as shown in Figure 1. The rear of the machine intersects with the warning zone boundary, which triggers the warning signal to be sent immediately. If there is no intersection, then combined with the results of the State 1 and State 2 checking, the machine is in a safe zone.
There is a third state worth some discussion, which is when the side edge of moving machinery collides with the warning zone, but the head and rear part of the machinery are in safe zone, as shown in Figure 2. boundary of risk area is d, to the boundary of the warning zone is ∆d, and the safety distance adopted in this paper is D = 2 m ( Figure 1). Safe status: d > D; Warning status: d ≤ D and ∆d is decreasing; Accident happening in risk area: d ≤ 0. According to the movement patterns of construction machineries, the two critical states are checked to trigger the warning signals.
• State 1: The head of the machine enters the warning zone If the moving machine is going towards the warning zone, the critical state is that d = D and ∆d = 0, as shown in Figure 1. The head of the machine intersects with the warning zone boundary, which triggers the warning signal to be sent immediately. There is no need to conduct further detection of the rear part of the machine. Otherwise, it indicates that the head of the machine is in a safe zone, and then State 2 test is conducted to check if the rear part of the machinery intersects with the warning zone boundary.
• State 2: The rear of the machine enters the warning zone In a similar way, if the rear of the machine intersects with the warning zone, the critical state is that d = D and ∆d = 0, as shown in Figure 1. The rear of the machine intersects with the warning zone boundary, which triggers the warning signal to be sent immediately. If there is no intersection, then combined with the results of the State 1 and State 2 checking, the machine is in a safe zone.
There is a third state worth some discussion, which is when the side edge of moving machinery collides with the warning zone, but the head and rear part of the machinery are in safe zone, as shown in Figure 2. This is a special state when a machine is making a turn close to the warning zone, and the side edge of the machine collides with the corner of the warning zone. In this case, the contour of the whole machine has collided with the warning zone. However, it is still in the safe stage as both the head and rear parts of the construction machinery are located in the safe ground, and this state is of "temporary nature" and the machinery can return to a safe state where no part collides with the warning zone. This state is regarded as a safe state, but noting this state is important for the collision detection design which will be discussed in the next section.

Collision Detection Method
Whether machinery is at risk is based on the relative position between the head and rear of the machinery to the warning zone. From the 2D projection view of the construction site, machinery entering a warning zone can be taken as a collision problem in image processing. The design of a collision detection mechanism should consider the purpose of detection and performance of different collision methods. This is a special state when a machine is making a turn close to the warning zone, and the side edge of the machine collides with the corner of the warning zone. In this case, the contour of the whole machine has collided with the warning zone. However, it is still in the safe stage as both the head and rear parts of the construction machinery are located in the safe ground, and this state is of "temporary nature" and the machinery can return to a safe state where no part collides with the warning zone. This state is regarded as a safe state, but noting this state is important for the collision detection design which will be discussed in the next section.

Collision Detection Method
Whether machinery is at risk is based on the relative position between the head and rear of the machinery to the warning zone. From the 2D projection view of the construction site, machinery entering a warning zone can be taken as a collision problem in image processing. The design of a collision detection mechanism should consider the purpose of detection and performance of different collision methods.

The Bounding Box Methods
Collision detection is based on the principle that two non-penetrating objects cannot share the same area, and collision can be predicted by estimating if the surfaces of two nonpenetrating objects are going to touch each other [47,48]. Bounding boxes are commonly used to process the intersection of objects by using simplified shapes [49,50]. Checking the intersection among bounding boxes is almost always more efficient than checking the intersection of complex objects [48,50]. Commonly used bounding boxes include the axis aligned bounding box (AABB), oriented bounding box (OBB), K-discrete orientation polyhedral (k-DOP), and bounding sphere. The representations of these methods are shown in Figure 3 [50][51][52]. Among them, AABB is the easiest to develop, as the box is bounded by the minimum and maximum coordinates of the object in each dimension [53][54][55]. The OBB bounding box is of the minimum area that covers a complex object tightly, whose coordinate system is chosen individually based on the orientation of the object [50,53]. k-DOP is a convex polytope which is bounded by spaces aligned with axes from a small, fixed set of k orientations (where k is an even number) [52,56,57]. Bounding sphere is the minimum enclosing sphere of objects and is simple and fast for intersection, as only the radiuses are required to compute the distances between objects [49,50]. Collision detection is based on the principle that two non-penetrating objects cannot share the same area, and collision can be predicted by estimating if the surfaces of two non-penetrating objects are going to touch each other [47,48]. Bounding boxes are commonly used to process the intersection of objects by using simplified shapes [49,50]. Checking the intersection among bounding boxes is almost always more efficient than checking the intersection of complex objects [48,50]. Commonly used bounding boxes include the axis aligned bounding box (AABB), oriented bounding box (OBB), K-discrete orientation polyhedral (k-DOP), and bounding sphere. The representations of these methods are shown in Figure 3 [50][51][52]. Among them, AABB is the easiest to develop, as the box is bounded by the minimum and maximum coordinates of the object in each dimension [53][54][55]. The OBB bounding box is of the minimum area that covers a complex object tightly, whose coordinate system is chosen individually based on the orientation of the object [50,53]. k-DOP is a convex polytope which is bounded by spaces aligned with axes from a small, fixed set of k orientations (where k is an even number) [52,56,57]. Bounding sphere is the minimum enclosing sphere of objects and is simple and fast for intersection, as only the radiuses are required to compute the distances between objects [49,50]. Two main factors need to be considered in selecting a bounding box: computational cost and accuracy [50]. Computational cost includes the coding complexity of bounding the object and the computational intensity of collision detection [50,53]. Accuracy is usually determined by the tightness or compactness between objects and the bounding box [51,54]. In terms of computation costs, the AABB and bounding sphere are simple and fast for processing, and for continuous collision tests, sphere bounding box method can be faster than AABB [50,54]. OBB is more complex in processing as it needs to rotate with objects, which requires additional computation effort [50,52]. k-DOP is the most computationally intensive method since the coordinate system needs to rotate with objects and k times overlapping tests are required [50,51]. The k-DOP method has the highest accuracy in representing objects and the sphere box has the least accuracy in most cases [52,54]. OBB is the minimum box, so it is a more accurate representation than AABB, but it is less compact than k-DOP [52,55]. In summary, the rank of each bounding box method in terms of computational costs and compactness is given in Table 2. Each method has advantages and disadvantages, and the selection of the bounding box needs to consider the characteristics of objects and the application scenarios. In this study, the warning zone on a construction site can be taken as a two-dimensional shape. Although a machine is a three-dimensional object, the intersection test can Two main factors need to be considered in selecting a bounding box: computational cost and accuracy [50]. Computational cost includes the coding complexity of bounding the object and the computational intensity of collision detection [50,53]. Accuracy is usually determined by the tightness or compactness between objects and the bounding box [51,54]. In terms of computation costs, the AABB and bounding sphere are simple and fast for processing, and for continuous collision tests, sphere bounding box method can be faster than AABB [50,54]. OBB is more complex in processing as it needs to rotate with objects, which requires additional computation effort [50,52]. k-DOP is the most computationally intensive method since the coordinate system needs to rotate with objects and k times overlapping tests are required [50,51]. The k-DOP method has the highest accuracy in representing objects and the sphere box has the least accuracy in most cases [52,54]. OBB is the minimum box, so it is a more accurate representation than AABB, but it is less compact than k-DOP [52,55]. In summary, the rank of each bounding box method in terms of computational costs and compactness is given in Table 2. Each method has advantages and disadvantages, and the selection of the bounding box needs to consider the characteristics of objects and the application scenarios. In this study, the warning zone on a construction site can be taken as a two-dimensional shape. Although a machine is a three-dimensional object, the intersection test can be carried out between the warning zone and the projection of moving machinery on the ground. For the majority of construction machines, their projection on the ground is close to a rectangle. Therefore, AABB or OBB are better options, as they are of the same shape as the objects that they represent [54,56]. As can be seen from Table 2, AABB is more efficient in the computational process, while OBB has higher accuracy. Therefore, these two methods are further considered for this study.

A Modified Bounding Box Method
The purpose of collision detection is to identify the critical State 1 and State 2 as shown in Figure 1. First, OBB bounding box is considered, as OBB can accurately represent the whole machine for the collision test with the warning zone. However, if OBB is adopted, the special state demonstrated in Figure 2 could be detected as a collision, while the machine is actually in a safe state. Therefore, using OBB to represent the whole machine is not an effective method as it may give false alarms. For safety warnings, it is important that false alarms are avoided, as if the warning signals are not reliable, they may be ignored by onsite operators as a habit and cannot effectively prevent accidents. Therefore, the development of the bounding box needs to exclude the middle area of the machine to prevent false alarms.
The AABB bounding box is considered due to its computational efficiency for practical purpose. The traditional way to develop AABB representing the whole machinery could result in extra areas being included, as shown in Figure 4a. Based on the states illustrated in Figures 1 and 2, only the head and rear parts of the machinery need to be considered. Therefore, two AABB bounding boxes can be used to represent the front and rear parts of the machinery, respectively, as illustrated in Figure 4b. As the machine is not always parallel to the coordinate axis when it is moving, there may be extra areas of these AABB bounding boxes be included [54]. However, as the sizes of the two AABBs (front and rear) are much smaller than the original AABB representing the whole machine, these extra areas are much smaller and the errors caused by them can be ignored. In fact, these extra areas can be regarded as a small warning buffer, as these extra areas are always in the same direction as the machinery's movement. When the extra area collides with the warning zone, it indicates the machine is moving towards the warning zone and will collide with it. Therefore, this modified AABB bounding box method not only reduces the large error areas of the original single AABB bounding box which includes the middle part of the machinery, but also enhances the effectiveness of the safety alarm with a small additional warning buffer.
be carried out between the warning zone and the projection of moving machinery on the ground. For the majority of construction machines, their projection on the ground is close to a rectangle. Therefore, AABB or OBB are better options, as they are of the same shape as the objects that they represent [54,56]. As can be seen from Table 2, AABB is more efficient in the computational process, while OBB has higher accuracy. Therefore, these two methods are further considered for this study.

A Modified Bounding Box Method
The purpose of collision detection is to identify the critical State 1 and State 2 as shown in Figure 1. First, OBB bounding box is considered, as OBB can accurately represent the whole machine for the collision test with the warning zone. However, if OBB is adopted, the special state demonstrated in Figure 2 could be detected as a collision, while the machine is actually in a safe state. Therefore, using OBB to represent the whole machine is not an effective method as it may give false alarms. For safety warnings, it is important that false alarms are avoided, as if the warning signals are not reliable, they may be ignored by onsite operators as a habit and cannot effectively prevent accidents. Therefore, the development of the bounding box needs to exclude the middle area of the machine to prevent false alarms.
The AABB bounding box is considered due to its computational efficiency for practical purpose. The traditional way to develop AABB representing the whole machinery could result in extra areas being included, as shown in Figure 4a. Based on the states illustrated in Figures 1 and 2, only the head and rear parts of the machinery need to be considered. Therefore, two AABB bounding boxes can be used to represent the front and rear parts of the machinery, respectively, as illustrated in Figure 4b. As the machine is not always parallel to the coordinate axis when it is moving, there may be extra areas of these AABB bounding boxes be included [54]. However, as the sizes of the two AABBs (front and rear) are much smaller than the original AABB representing the whole machine, these extra areas are much smaller and the errors caused by them can be ignored. In fact, these extra areas can be regarded as a small warning buffer, as these extra areas are always in the same direction as the machinery's movement. When the extra area collides with the warning zone, it indicates the machine is moving towards the warning zone and will collide with it. Therefore, this modified AABB bounding box method not only reduces the large error areas of the original single AABB bounding box which includes the middle part of the machinery, but also enhances the effectiveness of the safety alarm with a small additional warning buffer.  As seen in Figure 4b, the minimum and maximum coordinates in abscissa and vertical axes of the two AABB bounding boxes for machinery are determined by the position data of four wheels. These position data and the position data of the risk area need to be determined and a coordination system established for collision detection. As seen in Figure 4b, the minimum and maximum coordinates in abscissa and vertical axes of the two AABB bounding boxes for machinery are determined by the position data of four wheels. These position data and the position data of the risk area need to be determined and a coordination system established for collision detection.

Position Data Acquisition
In this study, the risk area is always simplified as a rectangle shape to represent a site area with potential risk, such as a foundation pit. The risk area is also taken as a large AABB bounding box in the collision detection, and its position is determined by the location of its four corners.
To obtain the location data of the risk area and mobile machinery, a wireless positioning device needs to be adopted [37,57]. Currently, there are multiple applications in the market which can be used to collect position data [58]. LocalSense is a widely used sensor device for detecting location in China with high accuracy of 10 mm, as shown in Figure 5, and it is adopted in this research. This device has two parts: tags and base stations, and it has its own coordination system (referred to as the global coordinate system in this paper). The system can capture real-time position based on ultrawide band antennas and calculate coordinates of tags with collected data information [59,60]. The mechanism of determining the location of the LocalSense tags is illustrated in Figure 5: Two base stations can provide two possible locations of the tag (two circles have two common points), and the third station can determine the exact location (x, y) of the tag. Mathematically, the tag position (x, y) is resolved using the three equations in Figure 5: the three base stations' coordinates are (x 1 , y 1 ), (x 2 , y 2 ), (x 3 , y 3 ) in the global coordinate system, and d 1 , d 2 , and d 3 are the distances between each base station and the tag, determined by the signal's travelling time between the tag and the base stations. Therefore, three base stations can be installed on a construction site, and with four tags attached to the wheels of mobile machinery, the global coordinates H 1 (x h1 , y h1 ), H 2 (x h2 , y h2 ), R 1 (x r3 , y r3 ), and R 2 (x r4 , y r4 ) of the four wheels can be collected.

Position Data Acquisition
In this study, the risk area is always simplified as a rectangle shape to represent a site area with potential risk, such as a foundation pit. The risk area is also taken as a large AABB bounding box in the collision detection, and its position is determined by the location of its four corners.
To obtain the location data of the risk area and mobile machinery, a wireless positioning device needs to be adopted [37,57]. Currently, there are multiple applications in the market which can be used to collect position data [58]. LocalSense is a widely used sensor device for detecting location in China with high accuracy of 10 mm, as shown in Figure 5, and it is adopted in this research. This device has two parts: tags and base stations, and it has its own coordination system (referred to as the global coordinate system in this paper). The system can capture real-time position based on ultrawide band antennas and calculate coordinates of tags with collected data information [59,60]. The mechanism of determining the location of the LocalSense tags is illustrated in Figure 5: Two base stations can provide two possible locations of the tag (two circles have two common points), and the third station can determine the exact location (x, y) of the tag. Mathematically, the tag position (x, y) is resolved using the three equations in Figure 5: the three base stations' coordinates are (x1, y1), (x2, y2), (x3, y3) in the global coordinate system, and d1, d2, and d3 are the distances between each base station and the tag, determined by the signal's travelling time between the tag and the base stations. Therefore, three base stations can be installed on a construction site, and with four tags attached to the wheels of mobile machinery, the global coordinates H1(xh1, yh1), H2(xh2, yh2), R1(xr3, yr3), and R2(xr4, yr4) of the four wheels can be collected. In the same way, tags are installed at the corners of the identified risk area and their coordinates can be obtained. These tags can be reused and can be moved when the risk areas change. To prevent the tags of the risk area from destroying by machinery, the tags will be removed after the coordinates of the risk area are captured by the locating device. The obtained coordinates will be recorded in the software system. In the same way, tags are installed at the corners of the identified risk area and their coordinates can be obtained. These tags can be reused and can be moved when the risk areas change. To prevent the tags of the risk area from destroying by machinery, the tags will be removed after the coordinates of the risk area are captured by the locating device. The obtained coordinates will be recorded in the software system.

Coordinate System of Risk Area
In most cases, the risk area is not parallel to the global coordinate system. As the usual AABB development takes the maximum coordinates of the rectangular shape, it is not an accurate representation of the risk area in the global coordinate system (Figure 6a). In this research, a local coordinate system is established for the risk area with the x and y axes of the coordinate system parallel to the sides of risk area, and the AABB is exactly the same as the risk area, which removes the errors caused by using the global system directly, as shown in Figure 6b. In most cases, the risk area is not parallel to the global coordinate system. As the usual AABB development takes the maximum coordinates of the rectangular shape, it is not an accurate representation of the risk area in the global coordinate system (Figure 6a). In this research, a local coordinate system is established for the risk area with the x and y axes of the coordinate system parallel to the sides of risk area, and the AABB is exactly the same as the risk area, which removes the errors caused by using the global system directly, as shown in Figure 6b. Establishment of the local coordinate system also allows multiple risk areas which are not parallel to each other (and to the global system) to be processed separately and effectively. Transformation between global coordinate system and the local coordinate system of risk area is required, and it is shown in Figure 7. The transformation matrix T is used to establish a local coordinate system. The available data are four coordinates of the risk area collected by positioning application, namely A1 (x1, y1), A2 (x2, y2), A3 (x3, y3), A4 (x4, y4). The way to calculate T can be regarded as a matrix to transform coordinate Ai in global system to AiL in local system, where AiL is the original point in local coordinate system.  Establishment of the local coordinate system also allows multiple risk areas which are not parallel to each other (and to the global system) to be processed separately and effectively. Transformation between global coordinate system and the local coordinate system of risk area is required, and it is shown in Figure 7. The transformation matrix T is used to establish a local coordinate system. The available data are four coordinates of the risk area collected by positioning application, namely A 1 (x 1 , y 1 ), A 2 (x 2 , y 2 ), A 3 (x 3 , y 3 ), A 4 (x 4 , y 4 ). The way to calculate T can be regarded as a matrix to transform coordinate A i in global system to A iL in local system, where A iL is the original point in local coordinate system. In most cases, the risk area is not parallel to the global coordinate system. As the usual AABB development takes the maximum coordinates of the rectangular shape, it is not an accurate representation of the risk area in the global coordinate system (Figure 6a). In this research, a local coordinate system is established for the risk area with the x and y axes of the coordinate system parallel to the sides of risk area, and the AABB is exactly the same as the risk area, which removes the errors caused by using the global system directly, as shown in Figure 6b. Establishment of the local coordinate system also allows multiple risk areas which are not parallel to each other (and to the global system) to be processed separately and effectively. Transformation between global coordinate system and the local coordinate system of risk area is required, and it is shown in Figure 7. The transformation matrix T is used to establish a local coordinate system. The available data are four coordinates of the risk area collected by positioning application, namely A1 (x1, y1), A2 (x2, y2), A3 (x3, y3), A4 (x4, y4). The way to calculate T can be regarded as a matrix to transform coordinate Ai in global system to AiL in local system, where AiL is the original point in local coordinate system.

Coordinates of the Mobile Machinery
As presented in Section 3.2.2, coordinates of the head and rear parts of mobile machinery are required to establish modified AABB bounding box. Therefore, four wheels are marked as points 1, 2, 3, and 4, as shown in Figure 8. The coordinates of the two head wheels are H 1 (x h1 , y h1 ) and H 2 (x h2 , y h2 ), and coordinates of rear wheels are R 1 (x r3 , y r3 ) and R 2 (x r4 , y r4 ). Currently coordinates of machinery are also collected in global system, which should be transformed to the local system as developed in Figure 8. By using transformation matrix T to get the coordinates in the same way, the local coordinates of machinery are H 1L (x h1L , y h1L ), H 2L (x h2L , y h2L ), R 1L (x r3L , y r3L ), R 2L (x r4L , y r4L ). Based on the four coordinates, the modified AABB method can be developed to represent the machinery as designed. Therefore, in the local system, the other two coordinates of head AABB 1 are H 3L (x h2L , y h1L ) and H 4L (x h1L , y h2L ), and the other two are R 3L (x r3L , y r4L ) and R 4L (x r4L , y r3L ) for rear AABB 2 . All coordinates of the modified AABB are obtained, as shown in Figure 8. The models of the warning zone and construction machinery are established in the same local coordinate system. After transformation, coordinates of risk area are A1L (x1L, y1L), A2L (x2L, y2L), A3L (x3L, y3L), A4L (x4L, y4L), where AiL can be calculated as: As mentioned in Section 3.1, the coordinates used for collision detection are from the warning zone rather than risk area. Therefore, coordinates of warning zone can be represented as W1L (x1L − 2D, y1L − 2D), W2L (x2L − 2D, y2L + 2D), W3L (x3L + 2D, y3L + 2D), W4L (x4L + 2D, y4L − 2D), as seen in Figure 7b).

Coordinates of the Mobile Machinery
As presented in Section 3.2.2, coordinates of the head and rear parts of mobile machinery are required to establish modified AABB bounding box. Therefore, four wheels are marked as points 1, 2, 3, and 4, as shown in Figure 8. The coordinates of the two head wheels are H1(xh1, yh1) and H2(xh2, yh2), and coordinates of rear wheels are R1(xr3, yr3) and R2(xr4, yr4). Currently coordinates of machinery are also collected in global system, which should be transformed to the local system as developed in Figure 8. By using transformation matrix T to get the coordinates in the same way, the local coordinates of machinery are H1L(xh1L, yh1L), H2L(xh2L, yh2L), R1L(xr3L, yr3L), R2L(xr4L, yr4L). Based on the four coordinates, the modified AABB method can be developed to represent the machinery as designed. Therefore, in the local system, the other two coordinates of head AABB1 are H3L(xh2L, yh1L) and H4L(xh1L, yh2L), and the other two are R3L(xr3L, yr4L) and R4L(xr4L, yr3L) for rear AABB2. All coordinates of the modified AABB are obtained, as shown in Figure 8. The models of the warning zone and construction machinery are established in the same local coordinate system.

Proximity Detection/Collision Warning Analysis
The critical process is to conduct proximity detection/collision warning analysis using collected location data. After the coordinate system development of the pre-identified warning zone and machinery in a local system, proximity detection is used to check if the AABB representing the machinery (head or rear) intersect with the AABB representing the warning zone on either the X or Y axes. The algorithm of intersection tests is given as follows: for (i = 0; i < 2; i++) if L 1i > H 2i || L 2i > H 1i return 0; else return 1; Where the minimum and maximum vertices of the two AABBs are P 1 (L 10 ,L 11 ), Q 1 (H 10 ,H 11 ), and P 2 (L 20 ,L 21 ), Q 2 (H 20 ,H 21 ), as illustrated in Figure 9. Based on the above algorithm, if it returns "1", it means the two boxes intersect or are colliding. Otherwise, if the algorithm returns "0", it means there is no collision. There are four possible relationships between the two AABB bounding boxes. If the two AABBs do not intersect with each other on both axes, there is no collision between them, as marked in green circles in Figure 9a. If there is an intersection on either of the axes with no intersection on the other axis, the two AABB still do not intersect with each other, as seen in Figure 9b,c. If the two AABB intersect with each other on both axes, there is collision between them as marked in red circles in Figure 9d.

Proximity Detection/Collision Warning Analysis
The critical process is to conduct proximity detection/collision warning analysis using collected location data. After the coordinate system development of the pre-identified warning zone and machinery in a local system, proximity detection is used to check if the AABB representing the machinery (head or rear) intersect with the AABB representing the warning zone on either the X or Y axes. The algorithm of intersection tests is given as follows: for (i = 0; i < 2; i++) if L1i > H2i || L2i > H1i return 0; else return 1; Where the minimum and maximum vertices of the two AABBs are P1(L10,L11), Q1(H10,H11), and P2(L20,L21), Q2(H20,H21), as illustrated in Figure 9. Based on the above algorithm, if it returns "1", it means the two boxes intersect or are colliding. Otherwise, if the algorithm returns "0", it means there is no collision. There are four possible relationships between the two AABB bounding boxes. If the two AABBs do not intersect with each other on both axes, there is no collision between them, as marked in green circles in Figure 9a. If there is an intersection on either of the axes with no intersection on the other axis, the two AABB still do not intersect with each other, as seen in Figure 9b,c. If the two AABB intersect with each other on both axes, there is collision between them as marked in red circles in Figure 9d. This proximity detection will be adopted to check if the modified AABB bounding boxes (representing the head and rear of a mobile machinery) collide with the warning zone. As the machinery is constantly moving, a continuous checking mechanism needs to be established.

Warning Algorithm Implementation
Both head and rear AABB bounding boxes of machinery need to be tested using the proximity detection with the warning zone (W0). For practical onsite operation, most of the time the machine is in a state of moving forward, so the front wheels are more likely than the rear wheels to move into the warning zone (W0). Therefore, it is reasonable to test collision of the head AABB1 (H1) first followed by the rear AABB2 (R1). The complete process for implementing the collision detection is given in Figure 10. The warning signal can be given instantly based on the developed algorithm. This proximity detection will be adopted to check if the modified AABB bounding boxes (representing the head and rear of a mobile machinery) collide with the warning zone. As the machinery is constantly moving, a continuous checking mechanism needs to be established.

Warning Algorithm Implementation
Both head and rear AABB bounding boxes of machinery need to be tested using the proximity detection with the warning zone (W 0 ). For practical onsite operation, most of the time the machine is in a state of moving forward, so the front wheels are more likely than the rear wheels to move into the warning zone (W 0 ). Therefore, it is reasonable to test collision of the head AABB 1 (H 1 ) first followed by the rear AABB 2 (R 1 ). The complete process for implementing the collision detection is given in Figure 10. The warning signal can be given instantly based on the developed algorithm. Sensors 2021, 21, x FOR PEER REVIEW 12 of 20 Figure 10. System design of safety warning algorithm.

Case Background
A real case simulation is carried out to validate the proposed algorithm. Figure 11 shows a construction site layout. The site is complex with different construction areas, and some foundation pits are under excavation, which are potential risk areas for onsite mobile machineries, and they are presented as red rectangles in Figure 11. Some risk areas are not exactly in the shape of a rectangle. However, they are simplified to the closest rectangular areas for an easier process. In this study, a relatively small risk area, marked in a red circle in Figure 11, is selected for case simulation to validate the algorithm. The dimension of the area can be determined directly from the coordinates captured by the tags installed at the four corners of the risk area.

Case Background
A real case simulation is carried out to validate the proposed algorithm. Figure 11 shows a construction site layout. The site is complex with different construction areas, and some foundation pits are under excavation, which are potential risk areas for onsite mobile machineries, and they are presented as red rectangles in Figure 11. Some risk areas are not exactly in the shape of a rectangle. However, they are simplified to the closest rectangular areas for an easier process. In this study, a relatively small risk area, marked in a red circle in Figure 11, is selected for case simulation to validate the algorithm. The dimension of the area can be determined directly from the coordinates captured by the tags installed at the four corners of the risk area. Sensors 2021, 21, x FOR PEER REVIEW 13 of 20 Figure 11. Case example of potential risk area for mobile machinery and arrangement of positioning application.
As mentioned in Section 3.3.3, three base-stations could determine the position of a tag. In this case simulation, a total of four base stations are installed, and the system will use the closest three base station data to calculate the tags' location. The layout of the basestations and the tags for collecting coordinates are shown in Figure 12 (diagram is not in proportion with the real distance on site). The base-stations could obtain x, y coordinates of these tags in global coordinate system. Then, these coordinate data are transmitted to a monitor terminal, where the proposed algorithm is installed. These coordinates are the input data of the proposed safety warning algorithm. The data flow is also shown in Figure 12, which demonstrates how tags on the risk area and machinery in the construction site are linked with the proposed safety warning algorithm. As mentioned in Section 3.3.3, three base-stations could determine the position of a tag. In this case simulation, a total of four base stations are installed, and the system will use the closest three base station data to calculate the tags' location. The layout of the base-stations and the tags for collecting coordinates are shown in Figure 12 (diagram is not in proportion with the real distance on site). The base-stations could obtain x, y coordinates of these tags in global coordinate system. Then, these coordinate data are transmitted to a monitor terminal, where the proposed algorithm is installed. These coordinates are the input data of the proposed safety warning algorithm. The data flow is also shown in Figure 12, which demonstrates how tags on the risk area and machinery in the construction site are linked with the proposed safety warning algorithm.

Model Development and Collision Test Results
The location data collected by the tags installed at the four corners of the risk area are expressed in the global coordination system as A1 (22.62, 27.86), A2 (26.72, 34.96), A3 (44.35, 15.31), and A4 (48.45, 22.41). As discussed in Section 3.3.2, transformation matrix T is applied to convert these data into the local coordinate system, which is computed as: . Four tags are installed on the wheels of machinery. Tag 1, tag 2, tag 3, and tag 4 are used for continuous location data collection of H1, H2, R1, and R2 respectively. The global coordinate data are collected real-time at every 0.5 s and are input into the safety warning algorithm simultaneously. Multiple rounds of simulation and data collection were carried out, which validated the effectiveness and accuracy of the proposed algorithm. In this paper, two key datasets are reported, one is data collected while moving forward and another is collected while moving backward. Machinery is simulated to be moving on the construction site, starting from about 20 m away from the risk area. A wheel loader was taken as the machinery in the simulation, and its approximate dimension is 1.98 × 2.82 m. In some reported research, the working speed of wheel loader is about 5 km/h (around 1.39 m/s) on a construction site [61,62]. Therefore, the simulation speed of moving forward is set as 1.5 m/s, and the speed of moving backward is set as 1 m/s. Table 3 shows the continuously collected location data (every 0.5 s) of the four tags on the wheel loader. These data are the input data of the safety warning algorithm.

Model Development and Collision Test Results
The location data collected by the tags installed at the four corners of the risk area are expressed in the global coordination system as A 1 (22.62, 27.86), A 2 (26.72, 34.96), A 3 (44.35, 15.31), and A 4 (48.45, 22.41). As discussed in Section 3.3.2, transformation matrix T is applied to convert these data into the local coordinate system, which is computed as: Four tags are installed on the wheels of machinery. Tag 1, tag 2, tag 3, and tag 4 are used for continuous location data collection of H1, H2, R1, and R2 respectively. The global coordinate data are collected real-time at every 0.5 s and are input into the safety warning algorithm simultaneously. Multiple rounds of simulation and data collection were carried out, which validated the effectiveness and accuracy of the proposed algorithm. In this paper, two key datasets are reported, one is data collected while moving forward and another is collected while moving backward. Machinery is simulated to be moving on the construction site, starting from about 20 m away from the risk area. A wheel loader was taken as the machinery in the simulation, and its approximate dimension is 1.98 × 2.82 m. In some reported research, the working speed of wheel loader is about 5 km/h (around 1.39 m/s) on a construction site [61,62]. Therefore, the simulation speed of moving forward is set as 1.5 m/s, and the speed of moving backward is set as 1 m/s. Table 3 shows the continuously collected location data (every 0.5 s) of the four tags on the wheel loader. These data are the input data of the safety warning algorithm.  Figure 13b. The next step is the collision detection test, which will also be carried out every 0.5 s. In the safety warning algorithm, the improved AABB of machinery will be automatically created in the local coordinate system, as shown in Figure 8. The continuous collision detection was carried out. As shown in Figure 13a, at the time of 11:42:11.790 , collision was detected, and the head bounding box was displayed in red colour and warning is given. The warning signal instructs the operator of the machinery to move backwards in a timely manner. A similar simulation was carried out while the machinery was moving backward, as shown in Figure 13b. Collision was detected at the time of 11:44:59.798 . The rear AABB was displayed in red and a warning given.
These two simulations demonstrate the safety warning signals are triggered successfully and instructions are released to the machinery operator to avoid an accident.

Discussions and Conclusions
The above case simulation represents typical situations for construction machinery moving around a risk area. The proposed algorithm could continuously process input location data of moving machinery and release safety warning signals to machinery operators when the machinery enters the warning zone.
In this simulation, the safe distance between the risk area and the warning zone boundary is set as 2 m, this distance is used according to the construction site regulations in China as listed in Table 1. Considering the fact that a machine operator needs to have some response time, and when machinery is moving at a speed of 1-1.5 m/s (about 3.6−5.4 km/hour), 2 m only provides less than 2 s of response time. Therefore, it is suggested that in real construction practice, this distance is to be increased according to the machinery's speed. When this algorithm is used in other countries or in a specific situation, this distance can also be adjusted to provide appropriate response time to the machine operator.
The collision detection was carried out every 0.5 s in this simulation, and as the computation process is efficient and almost instant, this frequency can also be adjusted according to the speed of the machinery to meet the requirement of onsite monitoring in real projects.
This study proposed a safety warning algorithm for moving construction machineries to prevent them from entering risk areas to avoid overturning and collapsing accidents. The designed algorithm and the continuous processing of the collected location data by sensor devices offer a reliable and practical means for the automated onsite monitoring of construction machineries. There are two major contributions of this proposed algorithm.

Discussions and Conclusions
The above case simulation represents typical situations for construction machinery moving around a risk area. The proposed algorithm could continuously process input location data of moving machinery and release safety warning signals to machinery operators when the machinery enters the warning zone.
In this simulation, the safe distance between the risk area and the warning zone boundary is set as 2 m, this distance is used according to the construction site regulations in China as listed in Table 1. Considering the fact that a machine operator needs to have some response time, and when machinery is moving at a speed of 1-1.5 m/s (about 3.6−5.4 km/hour), 2 m only provides less than 2 s of response time. Therefore, it is suggested that in real construction practice, this distance is to be increased according to the machinery's speed. When this algorithm is used in other countries or in a specific situation, this distance can also be adjusted to provide appropriate response time to the machine operator.
The collision detection was carried out every 0.5 s in this simulation, and as the computation process is efficient and almost instant, this frequency can also be adjusted according to the speed of the machinery to meet the requirement of onsite monitoring in real projects.
This study proposed a safety warning algorithm for moving construction machineries to prevent them from entering risk areas to avoid overturning and collapsing accidents. The designed algorithm and the continuous processing of the collected location data by sensor devices offer a reliable and practical means for the automated onsite monitoring of construction machineries. There are two major contributions of this proposed algorithm.
Firstly, for improving computation efficiency and reducing false alarm, a modified axis aligned bounding box (AABB) method is proposed. AABB is a relatively simple method. However, using two AABBs to represent the head and rear part of a construction machinery respectively is a novel approach. The error caused by the simplification is minimized, and the small extra space of the two AABBs serves as warning buffer, which increases the sensitivity of the warning algorithm. The modified AABB method also eliminates the possibility of the false warning caused by the turning machinery at the corner of the warning zone. This method is suitable for monitoring onsite construction machineries as it can make a flexible representation of machinery for collision detection analysis compared with other bounding box methods, and therefore improves its reliability in capturing actual situations of onsite construction machineries with an efficient computational approach.
Secondly, the proposed algorithm could be conveniently integrated with various realtime location sensing techniques and use their own coordinate system to collect location data. It then converts the location data into a local coordinate system established for each risk area. The use of a local coordinate system enables that each risk area is accurately represented by a standard AABB bounding box and ensures the computation accuracy when multiple risk areas are included. The proposed algorithm provides a practical method for continuous monitoring of construction mobile machineries.
The simulation results demonstrate that the proposed safety warning algorithm works effectively in detecting risks and can release timely warning signals. It also requires very little data space for data storage, and is of very low computational cost. The warning signals can be triggered by using wireless communication technologies, such as Wifi and Internet of Things (IoT), and the details of implementing these technologies are reported in other studies [63][64][65].
Construction site safety management is an important aspect of an efficient overall site layout planning [66]. The limitation of this algorithm is that the risk area identified in this case needs to be simplified as a rectangular shape, while there are some risk areas in construction sites that are in circular or other irregular shapes, and some machineries could also be of a different shape, such as excavators in the form of a bounding sphere. Therefore, in the future, a more flexible bounding box development method could be proposed for risk areas and machineries of other shapes, and this could support a more efficient and accurate safety status check for different mobile machineries working close to all types of risk areas. Moreover, this research only considers proximity detection between machineries and risk areas. Thus, future research could address monitoring the relative positions of multiple machineries and preventing collision between them.