Arctg table!

Started by
18 comments, last by shaolinspin 14 years, 8 months ago
Anyone could past here, a harcoded Arctg table as array of 360 entries? Would apreciate your help! Thanks.
Advertisement
Do you mean a table with the tangent of each angle that is an integer number of degrees?
DIY:

-- lua5.1local f = assert( io.open( "invtan.txt", "w" ) )for i=0, 360 do	f:write( 1 / math.tan( i * math.pi / 180 ) .. ' ' )end


Output.

EDIT:
Did you want atan, tan or 1 / tan?

[Edited by - _fastcall on August 3, 2009 3:11:01 PM]
surely you could make that list yourself via a program? :P

shouldnt be too hard, esp not for someone who knows asm (;
Quote:Original post by alvaro
Do you mean a table with the tangent of each angle that is an integer number of degrees?



I mean the Arc tangent values for the selected angle entry, so ArcTg[0] will store the ArcTg value of angle 0, and ArcTg[359] will store the ArcTg value of angle 259.

See, I have a circle(x0,y0), a point in the circle(x,y).
What I want to do is to detrmine the angle with this formula:

Angle= ArcTg (y-y0/x-x0)

so with the lookup table I can simply do this to get the angle:

float Angle= ArcTgArray[(y-y0/x-x0)];


Thanks.
But that slope will not always be in [0,360]... You can't have a table that covers all the reals. You could have a table for values between 0 and 1 (in however many steps you want) and reduce all the other cases to this one. Could that be roughly what you want?
const int step = 361;double arctan[step];// Create a table that uses values from -1 to 1for ( int i = 0; i < step; ++i )	arctan = std::atan( (double)(i*2 - step) / (double)step );// Then:double angle = arctan[ std::min( step-1, std::max( 0, (int)( (test * step + step)/2 ) ) ) ];


You should be using atan2( y-y0, x-x0 ) anyways ...
If you don't have atan2, you can use something like this:
double atan2(double y, double x) {  double alpha=3.141592653589793238462643383279;  double gx=-1.0, gy=0.0, result=-alpha;  static double cosine_and_sine[32][2]={    {-1,0},    {0,1},    {0.70710678118654757274,0.70710678118654746172},    {0.92387953251128673848,0.38268343236508978178},    {0.98078528040323043058,0.19509032201612824808},    {0.99518472667219692873,0.098017140329560603629},    {0.99879545620517240501,0.049067674327418014935},    {0.99969881869620424997,0.024541228522912288124},    {0.99992470183914450299,0.012271538285719925387},    {0.99998117528260110909,0.0061358846491544752691},    {0.99999529380957619118,0.0030679567629659761432},    {0.99999882345170187925,0.0015339801862847655001},    {0.99999970586288222663,0.0007669903187427044855},    {0.99999992646571789212,0.00038349518757139556321},    {0.99999998161642933425,0.00019174759731070329153},    {0.99999999540410733356,9.5873799095977344669e-05},    {0.99999999885102686115,4.793689960306688131e-05},    {0.99999999971275665978,2.3968449808418219318e-05},    {0.99999999992818922046,1.1984224905069705298e-05},    {0.9999999999820472496,5.9921124526424275272e-06},    {0.9999999999955118124,2.9960562263346608352e-06},    {0.99999999999887800861,1.4980281131690111427e-06},    {0.99999999999971944664,7.490140565847157414e-07},    {0.9999999999999298339,3.7450702829238412872e-07},    {0.99999999999998245848,1.8725351414619534661e-07},    {0.99999999999999567013,9.3626757073098083589e-08},    {0.99999999999999888978,4.6813378536549088116e-08},    {0.99999999999999977796,2.3406689268274550676e-08},    {0.99999999999999988898,1.1703344634137276992e-08},    {1,5.8516723170686384961e-09},    {1,2.925836158534319248e-09},    {1,1.462918079267159624e-09}  };  for(int i=0;i<32;++i) {    double c=cosine_and_sine[0], s=cosine_and_sine[1];    double nx=gx*c-gy*s, ny=gy*c+gx*s;    if(x*ny<y*nx) {      result += alpha;      gx=nx;      gy=ny;    }    alpha*=.5;  }  return result;}
@alvaro: I can have only 360 array's entry, and then check for the nearest array value to the value i got from calculating x-x0/y-y0.

@_fastcall: Could you please provide me with the output as you did in your first post? My environement compiler does not have a math library (no cos, sin... functions) and I cannot install other compilers.

Thanks.
Program:
#include <iterator>#include <fstream>#include <iomanip>#include <cmath>int main(){	const int step = 361;	double arctan[step];	// Note:  Range is from -1 to 1 inclusive.	for ( int i = 0; i < step; ++i )		arctan = std::atan( (double)(i*2 - step) / (double)(step-1) );	std::ofstream fs( "out.txt" );	fs.precision( 16 );	std::copy( arctan, arctan + step, std::ostream_iterator<double>( fs, " " ) );	fs.flush();}


The output:
Output.

You can use the binary interpreters that come with lua or python to generate your tables for you, as shown in my first post.

This topic is closed to new replies.

Advertisement