Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 03 August 2009 - 09:11 AM
-- lua5.1
local f = assert( io.open( "invtan.txt", "w" ) )
for i=0, 360 do
f:write( 1 / math.tan( i * math.pi / 180 ) .. ' ' )
end
Posted 03 August 2009 - 09:36 AM
Quote:
Original post by alvaro
Do you mean a table with the tangent of each angle that is an integer number of degrees?
float Angle= ArcTgArray[(y-y0/x-x0)];
Posted 03 August 2009 - 09:50 AM
Posted 03 August 2009 - 10:12 AM
const int step = 361;
double arctan[step];
// Create a table that uses values from -1 to 1
for ( int i = 0; i < step; ++i )
arctan[i] = std::atan( (double)(i*2 - step) / (double)step );
// Then:
double angle = arctan[ std::min( step-1, std::max( 0, (int)( (test * step + step)/2 ) ) ) ];
Posted 03 August 2009 - 10:22 AM
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[i][0], s=cosine_and_sine[i][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;
}
Posted 03 August 2009 - 10:29 AM
Posted 03 August 2009 - 10:38 AM
#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[i] = 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();
}
Posted 03 August 2009 - 11:00 AM
Posted 03 August 2009 - 11:17 AM
Posted 03 August 2009 - 12:31 PM
Quote:
Original post by Maze Master
What alvaro is saying is that you have tangent and arctangent mixed up. Arctangent takes in the ratio of sides on the triangle, which could be anything, and then returns the angle, which is between 0 and 360. It is regular tangent that takes the angle as input.
Tangent:[0,360]->[-inf,inf]
Arctangent:[-inf,inf]->[-90,90]
So it sounds like you want tangent(x) for x from 0 to 360, right?
Posted 04 August 2009 - 01:42 AM
Quote:
Original post by asmcoder
@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.
Quote:
[...]My environement compiler does not have a math library (no cos, sin... functions) and I cannot install other compilers.
Posted 04 August 2009 - 12:38 PM
Quote:
Original post by asmcoder
I've done that using this formula: Degree=Radian*180/Pi
Btw, why don't you recommend getting degree answers?
Posted 05 August 2009 - 01:47 AM
Quote:
I'm very interested on your article. Could you please point me a link to it?
Quote:
I've been meaning to write a little article advocating the use of the most natural representation in several types of variables. In short, it would say
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.