# A Depth-Based Hybrid Approach for Safe Flight Corridor Generation in Memoryless Planning
## 5 Local Planning Algorithm
### Best Direction Path  
We apply a direction function \(\mathcal{J}(P)\), inspired by our previous work [37], for evaluating path's reward as follows:  
\[\overrightarrow{d} =\frac{\overrightarrow{\mathcal{O}\mathcal{G}}}{\|\overrightarrow {\mathcal{O}\mathcal{G}}\|} \tag{2}\] \[\mathcal{J}(\mathcal{P}) =\frac{\overrightarrow{d}.\overrightarrow{\mathcal{O}\mathcal{P }}}{\|\overrightarrow{\mathcal{O}\mathcal{P}}\|}\] \[\underset{P}{\arg\max}\quad\mathcal{J}(\mathcal{P}) \tag{3}\]  
where \(\mathcal{O}\), \(\mathcal{G}\), and \(\mathcal{P}\) are the world-frame positions of the vehicle, the goal, and the best path's endpoint we need to find, respectively. \(\overrightarrow{d}\) is the vector of exploration direction. This vector-based function corrects the velocity vector to the desired direction. In our proposed system, \(\overrightarrow{d}\) will be the unit vector from the vehicle's current position to the goal. The reward is simply the dot product of the exploration vector \(\overrightarrow{d}\) and the unit vector of the path, i.e., the direction of a better path will align closer to the goal direction. With \(p\) and \(g\), respectively, as the projections of \(\mathcal{P}\) and \(\mathcal{G}\) in the image plane, we can see that \(\mathcal{J}(\mathcal{P})\) is at its maximum when the distance between \(p\) and \(g\) is minimal. With rectangular bounding boxes as constraints, our problem will be a 2D geometry issue: find the point \(p\) inside bounding boxes \(bb\) so that the distance \(|pg|\) is minimal. We have the coordinates of the goal and its projection in the camera frame calculated as follows,  
\[\mathcal{G} =(x_{\mathcal{G}},y_{\mathcal{G}},z_{\mathcal{G}})\] \[g =(x_{\mathcal{G}}*f_{x}/z_{\mathcal{G}}+c_{x},\,y_{\mathcal{G}}*f_ {y}/z_{\mathcal{G}}+c_{y}) \tag{4}\] \[bb =(x_{1},y_{1},x_{2},y_{2})\]  
where \(f_{x}\), \(f_{y}\), \(c_{x}\), and \(c_{y}\) are the focal lengths and principle point's coordinates in the corresponding axis, respectively; \(x_{1},y_{1}\), \(x_{2}\), and \(y_{2}\) are the bounding box's left, top, right, and bottom coordinates, all calculated in pixel unit. \(\mathcal{P}\) and \(\mathcal{G}\) coordinates are in meters. Our problem becomes:  
\[\underset{p}{\arg\min} |pg|\] (5) s.t. \[p\in bb\]  
The solution can be found trivially by a 2D geometry approach. We divide the region inside a bounding box and the image plane by nine areas, as illustrated in Figure 10. \(g\) will fall into one of nine areas. \(p\) can be specified in three situations:  
1. If \(g\) falls into one of four corner areas, \(p\) is the nearest corner.
2. If \(g\) falls into one of the four edge areas, \(p\) will lie on the nearest edge, specified by a perpendicular line drawn from \(g\) to the edge.
3. If \(g\) falls into the bounding box, the solution is \(g\) itself.  
Finally, we deproject \(p\) back to \(P\) in the space by equation:  
\[P =((x_{p}-c_{x})*D_{max}/f_{x},\] \[(y_{p}-c_{y})*D_{max}/f_{y}, \tag{6}\] \[D_{max})\]Furthermore, we apply the depth-based steering policy as in our previous work [37] to generate steering commands for several local minima motions, navigating the robot over large convex obstacles.