Author Topic: Trig in Axe  (Read 12258 times)

0 Members and 1 Guest are viewing this topic.

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Trig in Axe
« on: November 19, 2010, 07:55:10 pm »
Ok, so I'm looking at these trig routines, and so I see that the period is 256 and that the amplitude is 127. What does this mean? As in, how can I use them to behave the same way as the 'normal' trig functions? I suppose that.....it's like a new 'measurement' of angles, in addition to radians and degrees....?

So if 1 period in radians = 2pi
1 period in degrees = 360 = 180/pi times radian measure

1 period in Axe = 256 = 256/360 times degree measure = 256(180)/360pi times radian measure = 128/pi times radian measure....or 32/45 times degree measure

amplitude in degrees=1
amplitude in Axe= 127 times 1

So does this mean that I should take my number , multiply by 32/45, take the sine of it, and divide by 127? But then, that would probably give me 0 all the time since Axe rounds down...

« Last Edit: November 19, 2010, 08:03:04 pm by squidgetx »

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Trig in Axe
« Reply #1 on: November 19, 2010, 08:03:04 pm »
Yeah, that's pretty much it. They're called binary degrees, if you're wondering. You can't really have an amplitude of 1 since that would involve decimals, which could get nasty. But you can always divide it by whatever number applies so you get the amplitude you want.

And as for the period, it's actually really convenient if you think about it. For example, say you want something that draws a line going in a circle, like a hand on a clock. You'd do something like

Code: (Axe) [Select]
:For(A,0,255)
:Line(47,31,sin(A)//8+47,31-cos(A)//8)
:DispGraph
:End

As you can see, having 255 be the period works because a single-byte number can just keep looping on forever, and each time it gets back to zero again, the sine function goes on unbroken. And because of this, you can store both the angle value and the function value as a single byte with maximal accuracy.
« Last Edit: November 19, 2010, 08:15:19 pm by Deep Thought »




Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Trig in Axe
« Reply #2 on: November 19, 2010, 08:06:12 pm »
So if I inflate all my numbers by a factor of 128, then I could take the sine of 32/45's of whatever degree measure and it would be fine then, right?

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Trig in Axe
« Reply #3 on: November 19, 2010, 08:09:16 pm »
So if I inflate all my numbers by a factor of 128, then I could take the sine of 32/45's of whatever degree measure and it would be fine then, right?

Yeah, just multiply the degree measure by 45/32 (not 32/45) and treat the result as inflated by 128, and it'll work just like degrees.
« Last Edit: November 19, 2010, 08:09:29 pm by Deep Thought »




Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Trig in Axe
« Reply #4 on: November 19, 2010, 08:12:35 pm »
Wait, shouldn't it be 32/45 ???

For example, 90 degrees times 32/45 = 64, which I think corresponds correctly to a period of 256 whereas 90 degrees times 45/32 is 126.5625...

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Trig in Axe
« Reply #5 on: November 19, 2010, 08:14:16 pm »
Wait, shouldn't it be 32/45 ???

For example, 90 degrees times 32/45 = 64, which I think corresponds correctly to a period of 256 whereas 90 degrees times 45/32 is 126.5625...

Er, sorry. I got them confused. Just watch me fail my next math test by doing everything by 256s x.x
« Last Edit: November 19, 2010, 08:14:54 pm by Deep Thought »




Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Trig in Axe
« Reply #6 on: November 19, 2010, 08:16:03 pm »
Lol nice.

Is it true then that inflating all numbers by 128 would give the best precision too?

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Trig in Axe
« Reply #7 on: November 19, 2010, 08:17:34 pm »
In this case, in a single byte, yeah. That way, it uses the entire scale (0 to 255) to fit decimals from -1 to 1 with as much precision as possible.
« Last Edit: November 19, 2010, 08:18:20 pm by Deep Thought »




Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Trig in Axe
« Reply #8 on: November 19, 2010, 08:20:28 pm »
Wait, the output-ed value is only 1 byte?

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Trig in Axe
« Reply #9 on: November 19, 2010, 08:24:39 pm »
Wait, the output-ed value is only 1 byte?

Well, no, never mind. Guess it's just more convenient to work with than 0-65535 :D

EDIT: Good point, why not make the range from -255 to 255? That could make it match the fixed point math stuff...

Feature request?
« Last Edit: November 19, 2010, 08:40:51 pm by Deep Thought »




Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Trig in Axe
« Reply #10 on: November 19, 2010, 11:34:01 pm »
If you need really accurate sine and cosine routines, might I suggest this? :)

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Trig in Axe
« Reply #11 on: November 19, 2010, 11:39:52 pm »
If you need really accurate sine and cosine routines, might I suggest this? :)

Runer, would these be accurate enough to use in a triangle solver?


Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Trig in Axe
« Reply #12 on: November 20, 2010, 12:40:01 am »
They provide pretty good accuracy, probably less than 0.01% or so error :P The accuracy is just about as good as you can get with 2-byte values.
« Last Edit: November 20, 2010, 12:49:12 am by Runer112 »

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Trig in Axe
« Reply #13 on: November 20, 2010, 04:00:13 am »
If you're trying to make a triangle solver, it would be much easier to write in BASIC.  Axe is designed for games and so the math functions are optimized for speed and size instead of precision.  Trig functions are uncommon in calculator games (unless its an attempt at 3D) which is why there is only minimal support for them.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Trig in Axe
« Reply #14 on: November 20, 2010, 04:46:48 am »
You could always implement the functions in Assembly.

For example, this guy did it in ARM:

http://www.coranac.com/2009/07/sines/
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ