Path: chuka.playstation.co.uk!news From: "Tom" Newsgroups: scee.yaroze.programming.2d_graphics Subject: Re: Inverse Tangent Date: Thu, 23 Sep 1999 18:53:50 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 86 Message-ID: <7sdpff$7b1@chuka.playstation.co.uk> References: <7satfu$6r1@chuka.playstation.co.uk> NNTP-Posting-Host: ad11-s15-200-79.cwci.net X-Newsreader: Microsoft Outlook Express 4.72.3110.1 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Hi Matt, I hope this works. We've just got a network set up in our house and this is my first stab at sending a post via the file server. Anyway, the answer to your question is that there isn't one (a function I mean, not an answer). I found some code from someone elses demo (sorry whoever you are I can't remember where I got it from) which can either be found in math.c of my latest project, or listed down below. The original code cocked up when the angle was exactly 45 degrees, but I think this works in all cases. Cheers, Tom // table for inverse tangent (of form 512 = 90 degrees) short InvTanLut[] = { 0, 3, 5, 8, 10, 13, 15, 18, 20, 23, 25, 28, 31, 33, 36, 38, 41, 43, 46, 48, 51, 53, 56, 58, 61, 63, 66, 69, 71, 74, 76, 79, 81, 84, 86, 89, 91, 94, 96, 99, 101, 104, 106, 108, 111, 113, 116, 118, 121, 123, 126, 128, 131, 133, 136, 138, 140, 143, 145, 148, 150, 152, 155, 157, 160, 162, 164, 167, 169, 172, 174, 176, 179, 181, 183, 186, 188, 190, 193, 195, 197, 200, 202, 204, 207, 209, 211, 214, 216, 218, 220, 223, 225, 227, 229, 232, 234, 236, 238, 241, 243, 245, 247, 249, 252, 254, 256, 258, 260, 262, 265, 267, 269, 271, 273, 275, 277, 279, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 346, 347, 349, 351, 353, 355, 357, 359, 360, 362, 364, 366, 368, 370, 371, 373, 375, 377, 379, 380, 382, 384, 386, 387, 389, 391, 393, 394, 396, 398, 399, 401, 403, 405, 406, 408, 410, 411, 413, 415, 416, 418, 419, 421, 423, 424, 426, 428, 429, 431, 432, 434, 435, 437, 439, 440, 442, 443, 445, 446, 448, 449, 451, 452, 454, 455, 457, 458, 460, 461, 463, 464, 466, 467, 469, 470, 471, 473, 474, 476, 477, 479, 480, 481, 483, 484, 486, 487, 488, 490, 491, 492, 494, 495, 496, 498, 499, 500, 502, 503, 504, 506, 507, 508, 509, 511 }; // A modified version of some code that I found long InvTan(long x, long y) { long t; if (x==0 && y==0) return 0; if (Abs(x) == Abs(y)) { if (x > 0) return (y<0 ? 3584 : 512); return (y<0 ? 2560 : 1536); } if (Abs(x) > Abs(y)) { t = (y<<8)/x; if (t>=0) return InvTanLut[t&255] + (x<0 ? 2048 : 0); return (x<0 ? 2048 : 4096) - InvTanLut[(-t)&255]; } t = (x<<8)/y; if (t>=0) return (y<0 ? 3072 : 1024) - InvTanLut[t&255]; return InvTanLut[(-t) & 255] + (y < 0 ? 3072 : 1024); }