jack06215

[tools] get angle of a vector

Jul 8th, 2020 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <cmath>
  2.  
  3. /* ************************************************************************* */
  4. /**
  5.  * @brief This function computes the angle from the vector given by (X Y). From 0 to 2*Pi
  6.  */
  7. inline float getAngleV2(float x, float y) {
  8.  
  9.     float theta = atan2f(y,x);
  10.  
  11.     if (theta >= 0)
  12.     return theta;
  13.     else
  14.     return theta + static_cast<float>(2.0f*CV_PI);
  15. }
  16.  
  17. /* ************************************************************************* */
  18. /**
  19.  * @brief This function checks descriptor limits
  20.  * @param x X Position
  21.  * @param y Y Position
  22.  * @param width Image width
  23.  * @param height Image height
  24.  */
  25. inline void checkDescriptorLimitsV2(int &x, int &y, int width, int height) {
  26.  
  27.   if (x < 0) {
  28.     x = 0;
  29.   }
  30.  
  31.   if (y < 0) {
  32.     y = 0;
  33.   }
  34.  
  35.   if (x > width - 1) {
  36.     x = width - 1;
  37.   }
  38.  
  39.   if (y > height - 1) {
  40.     y = height - 1;
  41.   }
  42. }
  43.  
  44. /* ************************************************************************* */
  45. /**
  46.  * @brief This function rounds float to nearest integer
  47.  * @param flt Input float
  48.  * @return dst Nearest integer
  49.  */
  50. inline int fRoundV2(float flt) {
  51.   return (int)(flt + 0.5f);
  52. }
Add Comment
Please, Sign In to add comment