icossin.c 2.1 KB

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