• Create Account

lookup

Old topic!

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.

13 replies to this topic

#1Pseudo_Code  Members

122
Like
Likes
Like

Posted 13 February 2000 - 06:05 AM

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

122
Like
Likes
Like

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.

#3Pseudo_Code  Members

122
Like
Likes
Like

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?

#4Wrathnut  Members

466
Like
Likes
Like

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];

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

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

#5Wrathnut  Members

466
Like
Likes
Like

Posted 13 February 2000 - 07:26 AM

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

122
Like
Likes
Like

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.

#7Pseudo_Code  Members

122
Like
Likes
Like

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!

#8Nedelman  Members

166
Like
Likes
Like

Posted 13 February 2000 - 06:00 PM

float* sin_table = new float[360];

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

#9Nedelman  Members

166
Like
Likes
Like

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];

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

#10Nedelman  Members

166
Like
Likes
Like

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];

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

#11Gromit  Members

144
Like
Likes
Like

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.

#12Gecko  Members

122
Like
Likes
Like

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___

#13SiCrane  Moderators

11526
Like
Likes
Like

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.

#14LordFoul  Members

122
Like
Likes
Like

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
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.

Old topic!

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.