Difference between revisions of "User talk:Rednaxela/FastTrig"

From Robowiki
Jump to navigation Jump to search
(New section: My take)
(Negative angles need fixing indeed)
Line 2: Line 2:
  
 
It shouldn't. It will always be as fast or faster than standard trig functions at least so long as you do the following:
 
It shouldn't. It will always be as fast or faster than standard trig functions at least so long as you do the following:
* 'inline' the index calculations like was said and used in the example test
+
* 'inline' the index calculations like was said and used in the example testfor
 
* Run init() BEFORE the battle begins (i.e. in static initialization code of your bot class)
 
* Run init() BEFORE the battle begins (i.e. in static initialization code of your bot class)
 
An example of that static initialization code is like this:
 
An example of that static initialization code is like this:
Line 21: Line 21:
  
 
Nice work. From what I remember Simonton did something similar. I'm not sure if he had any luck though. One thing I noticed, I'm not sure if it works properly for negative angles, you will be rounding the wrong way. Also, the most useful trig function would be atan2. --[[User:Skilgannon|Skilgannon]] 20:43, 3 March 2009 (UTC)
 
Nice work. From what I remember Simonton did something similar. I'm not sure if he had any luck though. One thing I noticed, I'm not sure if it works properly for negative angles, you will be rounding the wrong way. Also, the most useful trig function would be atan2. --[[User:Skilgannon|Skilgannon]] 20:43, 3 March 2009 (UTC)
 +
 +
Ahh yes, sine doesn't work right at all yet for negative numbers. Cosine does work correctly except for rounding. I'll fix this now. :) --[[User:Rednaxela|Rednaxela]] 21:51, 3 March 2009 (UTC)

Revision as of 22:51, 3 March 2009

Sound good! But, will it skipped turns at first tick of the first round? » Nat | Talk » 10:41, 3 March 2009 (UTC)

It shouldn't. It will always be as fast or faster than standard trig functions at least so long as you do the following:

  • 'inline' the index calculations like was said and used in the example testfor
  • Run init() BEFORE the battle begins (i.e. in static initialization code of your bot class)

An example of that static initialization code is like this:

public class SomeBot extends AdvancedRobot {
    static {
        FastTrig.init();
    }

    public void run() {
        // Not in here
    }
{

The initialization code doesn't take long (0.0017 seconds on my computer at 2880 divisions) but just to be sure it doesn't hurt to place the initialization outside of where the bot is timed --Rednaxela 16:27, 3 March 2009 (UTC)

My take

Nice work. From what I remember Simonton did something similar. I'm not sure if he had any luck though. One thing I noticed, I'm not sure if it works properly for negative angles, you will be rounding the wrong way. Also, the most useful trig function would be atan2. --Skilgannon 20:43, 3 March 2009 (UTC)

Ahh yes, sine doesn't work right at all yet for negative numbers. Cosine does work correctly except for rounding. I'll fix this now. :) --Rednaxela 21:51, 3 March 2009 (UTC)