/** * @(#) $RCSfile: TrigonometryTable.as,v $ $Revision: 1.5 $ $Date: 2003/02/13 17:59:03 $ * * Copyright 2003 Orgdot AS. All Rights Reserved. * http://dev.swfit.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * This will generate a table of trigonometric values for Flash4 and place those * values into level 0 of the movie. * * @author Olaf Havnes * @version $Revision: 1.5 $ $Date: 2003/02/13 17:59:03 $ * @since SWFIT1.0 */ /** * We split the unit circle in NUM_DEG degrees (and store that value). */ /:DEG_MULT = 4; /:NUM_DEG = 360 * /:DEG_MULT; /:MATH_PI = 3.141592654; s_0 = 0; c_0 = 1; // s_1 = Math.sin (( MATH_PI * 2) / NUM_DEG); // c_1 = Math.cos (( MATH_PI * 2) / NUM_DEG); s_1 = 0.00436331; c_1 = 0.99999; s = s_1 * 2; i = 0; // Store the values in _level0. /:SIN_0 = s_0; /:COS_0 = c_0; /:SIN_1 = s_1; /:COS_1 = c_1; /** * We iterate over the double angle formulas - see EOF for notes. */ i = 2; while (i < /:NUM_DEG) { s_2 = s_0 + s * c_1; c_2 = c_0 - s * s_1; s_0 = s_1; c_0 = c_1; s_1 = s_2; c_1 = c_2; // Store the values in _level0. set ( "/:SIN_" add i, s_2 ); set ( "/:COS_" add i, c_2 ); i++; } /** * Create an inverse table for the first quadrant - saturated with values, some * will overwrite previous values, but the important thing is to fill all steps. * We're slightly off on this one, so don't navigate a battle ship by this code. */ i = 0; while (i < /:NUM_DEG / /:DEG_MULT) { sin = eval ("/:SIN_" add i); cos = eval ("/:COS_" add i); s00 = int (100.0 * sin); c00 = int (100.0 * cos); angle = i / DEG_MULT; set ("/:ASIN_" add s00, angle); set ("/:ACOS_" add c00, angle); i++; } /** * FRACTIONAL TRIGONOMETRY WITH nSHIFTEES: * * This algorithm is adapted from a java applet I made - in flash4 there is of course * no point in using bitshifts... * * I will define 1 nShiftee is as asin (2^(-n)) ~= 2^(-n) Radians. This relation * will of course be more correct the larger n is, as sin(x)/x approaches 1 when * x approaches 0. * * We have that: * * sin (A+B) = sin (A) * cos (B) + cos (A) * sin (B) * cos (A+B) = cos (A) * cos (B) - sin (A) * sin (B) * * sin (2*B) = 2 * sin (B) * cos (B) * cos (2*B) = cos^2 (B) - sin^2 (B) * * ==> * * sin (A+2*B) = sin (A) * cos (2*B) + cos (A) * sin (2*B) = sin (A) * ( cos^2 (B) - sin^2 (B) ) + cos (A) * 2 * sin (B) * cos (B) * cos (A+2*B) = cos (A) * cos (2*B) - sin (A) * sin (2*B) = cos (A) * ( cos^2 (B) - sin^2 (B) ) - sin (A) * 2 * sin (B) * cos (B) * * ==> * * sin (A+2*B) = sin (A) * ( 1 - 2 * sin^2 (B) ) + cos (A) * 2 * sin (B) * cos (B) * cos (A+2*B) = cos (A) * ( 1 - 2 * sin^2 (B) ) - sin (A) * 2 * sin (B) * cos (B) * * ==> * * sin (A+2*B) = sin (A) + 2 * sin (B) * cos (A+B) * cos (A+2*B) = cos (A) - 2 * sin (B) * sin (A+B) * * * We introduce the nShiftee into the equation: * If B = 1 nShiftee = asin (2^(-n)), then sin (B) = 2^(-n) * * A0 = A + 0*B * A1 = A + 1*B * A2 = A + 2*B * ... * Ai = A + i*B * * * in general: * * sin (Ai) = sin (Ai-2) + cos (Ai-1) * 2^(1-n) * cos (Ai) = cos (Ai-2) - sin (Ai-1) * 2^(1-n) * **/