icossin.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <draw.h>
  4. /*
  5. * Integer sine and cosine for integral degree argument.
  6. * Tables computed by (sin,cos)(PI*d/180).
  7. */
  8. static short sinus[91] = {
  9. 0, /* 0 */
  10. 18, /* 1 */
  11. 36, /* 2 */
  12. 54, /* 3 */
  13. 71, /* 4 */
  14. 89, /* 5 */
  15. 107, /* 6 */
  16. 125, /* 7 */
  17. 143, /* 8 */
  18. 160, /* 9 */
  19. 178, /* 10 */
  20. 195, /* 11 */
  21. 213, /* 12 */
  22. 230, /* 13 */
  23. 248, /* 14 */
  24. 265, /* 15 */
  25. 282, /* 16 */
  26. 299, /* 17 */
  27. 316, /* 18 */
  28. 333, /* 19 */
  29. 350, /* 20 */
  30. 367, /* 21 */
  31. 384, /* 22 */
  32. 400, /* 23 */
  33. 416, /* 24 */
  34. 433, /* 25 */
  35. 449, /* 26 */
  36. 465, /* 27 */
  37. 481, /* 28 */
  38. 496, /* 29 */
  39. 512, /* 30 */
  40. 527, /* 31 */
  41. 543, /* 32 */
  42. 558, /* 33 */
  43. 573, /* 34 */
  44. 587, /* 35 */
  45. 602, /* 36 */
  46. 616, /* 37 */
  47. 630, /* 38 */
  48. 644, /* 39 */
  49. 658, /* 40 */
  50. 672, /* 41 */
  51. 685, /* 42 */
  52. 698, /* 43 */
  53. 711, /* 44 */
  54. 724, /* 45 */
  55. 737, /* 46 */
  56. 749, /* 47 */
  57. 761, /* 48 */
  58. 773, /* 49 */
  59. 784, /* 50 */
  60. 796, /* 51 */
  61. 807, /* 52 */
  62. 818, /* 53 */
  63. 828, /* 54 */
  64. 839, /* 55 */
  65. 849, /* 56 */
  66. 859, /* 57 */
  67. 868, /* 58 */
  68. 878, /* 59 */
  69. 887, /* 60 */
  70. 896, /* 61 */
  71. 904, /* 62 */
  72. 912, /* 63 */
  73. 920, /* 64 */
  74. 928, /* 65 */
  75. 935, /* 66 */
  76. 943, /* 67 */
  77. 949, /* 68 */
  78. 956, /* 69 */
  79. 962, /* 70 */
  80. 968, /* 71 */
  81. 974, /* 72 */
  82. 979, /* 73 */
  83. 984, /* 74 */
  84. 989, /* 75 */
  85. 994, /* 76 */
  86. 998, /* 77 */
  87. 1002, /* 78 */
  88. 1005, /* 79 */
  89. 1008, /* 80 */
  90. 1011, /* 81 */
  91. 1014, /* 82 */
  92. 1016, /* 83 */
  93. 1018, /* 84 */
  94. 1020, /* 85 */
  95. 1022, /* 86 */
  96. 1023, /* 87 */
  97. 1023, /* 88 */
  98. 1024, /* 89 */
  99. 1024, /* 90 */
  100. };
  101. void
  102. icossin(int deg, int *cosp, int *sinp)
  103. {
  104. int sinsign, cossign;
  105. short *stp, *ctp;
  106. deg %= 360;
  107. if(deg < 0)
  108. deg += 360;
  109. sinsign = 1;
  110. cossign = 1;
  111. stp = 0;
  112. ctp = 0;
  113. switch(deg/90){
  114. case 2:
  115. sinsign = -1;
  116. cossign = -1;
  117. deg -= 180;
  118. /* fall through */
  119. case 0:
  120. stp = &sinus[deg];
  121. ctp = &sinus[90-deg];
  122. break;
  123. case 3:
  124. sinsign = -1;
  125. cossign = -1;
  126. deg -= 180;
  127. /* fall through */
  128. case 1:
  129. deg = 180-deg;
  130. cossign = -cossign;
  131. stp = &sinus[deg];
  132. ctp = &sinus[90-deg];
  133. break;
  134. }
  135. *sinp = sinsign*stp[0];
  136. *cosp = cossign*ctp[0];
  137. }