Started by Feb 13 2000 06:05 AM

,
13 replies to this topic

Posted 13 February 2000 - 06:05 AM

how do you create lookup tables for stuff? Anything, just, how?

Posted 13 February 2000 - 07:15 AM

Lookup tables are just pre-computed arrays that you use instead of computing everything in real-time. For example, you could create an array of 360 floats and fill it in with sin(0), sin(1), etc. and instead of having to call the sin function when you need it, you just reference this array.

Simple lookup tables like this can be created when your program starts, but more complicated lookup tables are usually stored on a file somewhere and read in.

Simple lookup tables like this can be created when your program starts, but more complicated lookup tables are usually stored on a file somewhere and read in.

Posted 13 February 2000 - 07:18 AM

What type of file could someone use should they need this information. And how would they read it in?

Posted 13 February 2000 - 07:20 AM

Say you wanted to create a lookup table for sin values from

0 - 360 it would be something like this(BTW this is in java but it's almost the same as C++)..

sinus = new float[360];

deg2rad = Math.PI/180;

for(int i=0; i<360; i++){

Sinus* = (float)Math.sin(i*deg2rad);*

}

where deg2rad is assinged as a float also.

What this does is fill an array full of cosine values. the only thing you would need to do to find the cos(15) would be to use cos[15]. It's actually pretty slick cause it saves alot of computation time if you are doing a lot of trig.

Anyway I hope this helps.. if you need me to do something like this in C++ I could give you an example too.

Edited by - Wrathnut on 2/13/00 1:24:14 PM

0 - 360 it would be something like this(BTW this is in java but it's almost the same as C++)..

sinus = new float[360];

deg2rad = Math.PI/180;

for(int i=0; i<360; i++){

Sinus

}

where deg2rad is assinged as a float also.

What this does is fill an array full of cosine values. the only thing you would need to do to find the cos(15) would be to use cos[15]. It's actually pretty slick cause it saves alot of computation time if you are doing a lot of trig.

Anyway I hope this helps.. if you need me to do something like this in C++ I could give you an example too.

Edited by - Wrathnut on 2/13/00 1:24:14 PM

Posted 13 February 2000 - 07:26 AM

Sorry about that the above:

Sinus = (float)Math.sin(i*deg2rad);

should read

Sinus[j] = (float)Math.sin(i*deg2rad);

where j = i ..

the damn thing here wants to make my source code an html tag... grr

Edited by - Wrathnut on 2/13/00 1:31:36 PM

Sinus = (float)Math.sin(i*deg2rad);

should read

Sinus[j] = (float)Math.sin(i*deg2rad);

where j = i ..

the damn thing here wants to make my source code an html tag... grr

Edited by - Wrathnut on 2/13/00 1:31:36 PM

Posted 13 February 2000 - 07:31 AM

Use whatever file type is easiest for you. I''ve seen nearly 10,000 normal vectors defined in an array in a header file before.

Posted 13 February 2000 - 08:34 AM

thanks, that helped. But, if you could, do it in C++. It''s a bit confusing in JAVA. Thanks!

Posted 13 February 2000 - 06:00 PM

float* sin_table = new float[360];

float deg2rad = 3.1415927/180;

for(int i=0; i<360; i++)

{

sin_table* = sin(i*deg2rad);*

}

float deg2rad = 3.1415927/180;

for(int i=0; i<360; i++)

{

sin_table

}

Posted 13 February 2000 - 06:03 PM

Whoa. The thing removed my subscripts in the "for" loop. Should have read Wrathnut''s post

float* sin_table = new float[360];

float deg2rad = 3.1415927/180;

for(int x=0; i<360; i++)

{

sin_table[z] = sin(x*deg2rad);

}

float* sin_table = new float[360];

float deg2rad = 3.1415927/180;

for(int x=0; i<360; i++)

{

sin_table[z] = sin(x*deg2rad);

}

Posted 13 February 2000 - 06:05 PM

Okay, if at first you don''t succeed...this was supposed to be a simple post

float* sin_table = new float[360];

float deg2rad = 3.1415927/180;

for(int z=0; z<360; z++)

{

sin_table[z] = sin(z*deg2rad);

}

float* sin_table = new float[360];

float deg2rad = 3.1415927/180;

for(int z=0; z<360; z++)

{

sin_table[z] = sin(z*deg2rad);

}

Posted 13 February 2000 - 08:09 PM

use the code tags to display your examples.

like this. everything is mono spaced and nothing disapears on you.

Posted 14 February 2000 - 11:54 AM

ok, but what about when you are using fractions and such and you want precision? i want to make a lookup table for sines of distances to a point. the distance function will frequently return a fraction. so how would i create a lookup table for fractions (e.g. sin(.88624132))?

_________________Gecko___

_________________Gecko___

Posted 14 February 2000 - 06:00 PM

In practice you wouldn''t create a lookup that would match .88624132 exactly. You''d have a lookup for .886 or .8862 maybe. Then when you''d want to index .886 you''d multiply the .886 by say a 1000 to get 886. And use the 886 to index your lookup table. How closely you want to match your fractions depends on how large you want your lookup-tables. The alternative would be to use a hash-table that accepted floating point arguments.

Posted 15 February 2000 - 04:29 AM

If you want a little more precision at the cost

of a little speed, consider interpolating your

answer from the two closest lookup in the table.

For example, if you have a result that is 1.4 and

your lookup only shows answers for 1 and 2, your

result should be

lookup[1] + ((lookup[2] - lookup[1]) * 0.4)

This assumes that your functions is a "continuous"

function, but sine and cosine are.