9fans.net/go@v0.0.5/draw/icossin.go (about)

     1  package draw
     2  
     3  /*
     4   * Integer sine and cosine for integral degree argument.
     5   * Tables computed by (sin,cos)(PI*d/180).
     6   */
     7  var sinus = [91]int16{
     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  
   101  // IntCosSin returns scaled integers representing the cosine and sine
   102  // of the angle deg, measured in integer degrees.
   103  // The values are scaled by ICOSSCALE (1024), so that cos(0) is 1024.
   104  func IntCosSin(deg int) (cos, sin int) {
   105  	deg %= 360
   106  	if deg < 0 {
   107  		deg += 360
   108  	}
   109  	sinsign := 1
   110  	cossign := 1
   111  	var stp, ctp int16
   112  	ctp = 0
   113  	switch deg / 90 {
   114  	case 2:
   115  		sinsign = -1
   116  		cossign = -1
   117  		deg -= 180
   118  		fallthrough
   119  	case 0:
   120  		stp = sinus[deg]
   121  		ctp = sinus[90-deg]
   122  	case 3:
   123  		sinsign = -1
   124  		cossign = -1
   125  		deg -= 180
   126  		fallthrough
   127  	case 1:
   128  		deg = 180 - deg
   129  		cossign = -cossign
   130  		stp = sinus[deg]
   131  		ctp = sinus[90-deg]
   132  	}
   133  	return cossign * int(ctp), sinsign * int(stp)
   134  }