vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

icossin.c (2116B)


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