Advertisement
KeithS

Trig_Blog_Sample_6

Aug 2nd, 2012
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <math.h>
  2. #include <cstdio>
  3. #define _USE_MATH_DEFINES
  4.  
  5.  
  6. struct point
  7. {
  8.     float x_pos;
  9.     float y_pos;
  10.     float _Hypot;
  11.     float _Asin;
  12.     float _Asin_Mod;
  13. };
  14.  
  15.  
  16. int main()
  17. {
  18.     point a_point[4];
  19.  
  20.  
  21.     a_point[0].x_pos = 300.0f;
  22.     a_point[0].y_pos = 200.0f;
  23.     a_point[1].x_pos = -200.0f;
  24.     a_point[1].y_pos = 300.0f;
  25.     a_point[2].x_pos = -300.0f;
  26.     a_point[2].y_pos = -200.0f;
  27.     a_point[3].x_pos = 200.0f;
  28.     a_point[3].y_pos = -300.0f;
  29.  
  30.  
  31.     int i;
  32.     for( i = 0; i < 4; i++)
  33.     {
  34.         a_point[i]._Hypot = hypotf(a_point[i].y_pos, a_point[i].x_pos);
  35.         a_point[i]._Asin = asinf(a_point[i].y_pos / a_point[i]._Hypot);
  36.  
  37.  
  38.         // Here's the quadrant correction...
  39.         if(a_point[i].x_pos >= 0.0f && a_point[i].y_pos >= 0.0f)
  40.         {
  41.             a_point[i]._Asin_Mod = asinf(a_point[i].y_pos / a_point[i]._Hypot);
  42.         }
  43.         if(a_point[i].x_pos < 0.0f && a_point[i].y_pos >= 0.0f)
  44.         {
  45.             a_point[i]._Asin_Mod = M_PI - asinf(a_point[i].y_pos / a_point[i]._Hypot);
  46.         }
  47.         if(a_point[i].x_pos < 0.0f && a_point[i].y_pos < 0.0f)
  48.         {
  49.             a_point[i]._Asin_Mod = M_PI + (asinf(a_point[i].y_pos / a_point[i]._Hypot) * -1);
  50.         }
  51.         if(a_point[i].x_pos >= 0.0f && a_point[i].y_pos < 0.0f)
  52.         {
  53.             a_point[i]._Asin_Mod = asinf(a_point[i].y_pos / a_point[i]._Hypot) + (M_PI * 2.0f);
  54.         }
  55.  
  56.  
  57.         printf("\nPOINT %d\n", i);
  58.         printf("X Pos: %.1f\nY Pos: %.1f\nAsin : %.3f\nAsinMod: %.3f\n\n",
  59.             a_point[i].x_pos, a_point[i].y_pos, a_point[i]._Asin, a_point[i]._Asin_Mod);
  60.     }
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement