package Approximations; import java.lang.Math; import java.awt.*; //Only for graphics test. import Globals.*; //Integer approximations of functions sin and cos. //Can be used in graphics. public class ICos{ public static final int argMax = 1024; //Debug: 4; public static final int argMax4 = argMax * 4; public static final int sinMax = 1024; public static final int sinMax2 = sinMax * 2; public static final double PI2 = Math.PI /2.; public static int[] sinI = new int[ argMax4 + 1 ]; public static int[] cosI = new int[ argMax4 + 1 ]; public static final double wStep = PI2 / argMax; public static final int argMax2 = argMax * 2; public static final int argMax3 = argMax * 3; public static void generate() { double arg=0; for( int i=0; i<=argMax; i++ ) { int w = (int) ( sinMax * Math.sin(arg) ); //Debug: //GS.con("i=" + i + " w=" + w + " arg=" + arg ); sinI[ i] = w; sinI[argMax2-i] = w; sinI[argMax2+i] = -w; sinI[argMax4-i] = -w; cosI[argMax -i] = w; cosI[argMax +i] = -w; cosI[argMax3-i] = -w; cosI[argMax3+i] = w; arg += wStep; } } //generate() //Draw graphs. Only for test: public static void drawTest( Graphics g, int height) { g.setColor(new Color( (100<<16) | (100<<8) ) ); int i1=0, j1=0, k1=0; for( int i=0; i<=ICos.argMax4; i++ ) { int j = (ICos.sinMax-ICos.sinI[i]) * height / ICos.sinMax2; int k = (ICos.sinMax-ICos.cosI[i]) * height / ICos.sinMax2; if( i > 0 ) { g.drawLine( i, j, i1, j1 ); g.drawLine( i, k, i1, k1 ); } k1 = k; i1 = i; j1 = j; } } } // class