Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: squidgetx on November 19, 2010, 07:55:10 pm

Title: Trig in Axe
Post by: squidgetx 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...

Title: Re: Trig in Axe
Post by: Deep Toaster 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.
Title: Re: Trig in Axe
Post by: squidgetx 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?
Title: Re: Trig in Axe
Post by: Deep Toaster 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.
Title: Re: Trig in Axe
Post by: squidgetx 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...
Title: Re: Trig in Axe
Post by: Deep Toaster 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
Title: Re: Trig in Axe
Post by: squidgetx 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?
Title: Re: Trig in Axe
Post by: Deep Toaster 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.
Title: Re: Trig in Axe
Post by: squidgetx on November 19, 2010, 08:20:28 pm
Wait, the output-ed value is only 1 byte?
Title: Re: Trig in Axe
Post by: Deep Toaster 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?
Title: Re: Trig in Axe
Post by: Runer112 on November 19, 2010, 11:34:01 pm
If you need really accurate sine and cosine routines, might I suggest this (http://ourl.ca/4129/130460)? :)
Title: Re: Trig in Axe
Post by: nemo on November 19, 2010, 11:39:52 pm
If you need really accurate sine and cosine routines, might I suggest this (http://ourl.ca/4129/130460)? :)

Runer, would these be accurate enough to use in a triangle solver?
Title: Re: Trig in Axe
Post by: Runer112 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.
Title: Re: Trig in Axe
Post by: Quigibo 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.
Title: Re: Trig in Axe
Post by: AngelFish 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/ (http://www.coranac.com/2009/07/sines/)
Title: Re: Trig in Axe
Post by: nemo on November 20, 2010, 03:47:09 pm
i know, but it'd be cool to write a triangle solver in axe. regardless, i have one (almost) finished in BASIC which is only missing the ambiguous case.
Title: Re: Trig in Axe
Post by: DJ Omnimaga on November 20, 2010, 05:36:38 pm
I fear the grayscale quadratic solver axe port is next...
Title: Re: Trig in Axe
Post by: AngelFish on November 20, 2010, 06:20:48 pm
It'd be difficult to do in Axe. The first imaginary number might crash the program. You'd have to go into ASM to handle those.
Title: Re: Trig in Axe
Post by: Quigibo on November 20, 2010, 10:58:01 pm
Someone should write a quadratic solver.  Maybe I'll do it if I have time.

Off topic, but Qwerty.55, your sig is bringing back horrible memories of quantum physics, having to solve for the energy levels of multi-electron atoms.  The DE's got really really ugly...
Title: Re: Trig in Axe
Post by: DJ Omnimaga on November 20, 2010, 11:02:46 pm
lol that would be funny in some ways actually, although not as much as if the first Axe program ever released on ticalc.org was a quadratic solver. That happened to BBC Basic. :P
Title: Re: Trig in Axe
Post by: AngelFish on November 20, 2010, 11:09:25 pm
Someone should write a quadratic solver.  Maybe I'll do it if I have time.

Off topic, but Qwerty.55, your sig is bringing back horrible memories of quantum physics, having to solve for the energy levels of multi-electron atoms.  The DE's got really really ugly...

Glad to hear it ;D

I use that bloody equation more than I'd like to (IE more than not at all).
Title: Re: Trig in Axe
Post by: ztrumpet on November 22, 2010, 06:58:56 am
The DE's got really really ugly...
For some reason, all I can think of is the register. :P
Title: Re: Trig in Axe
Post by: Deep Toaster on November 22, 2010, 11:27:18 am
The DE's got really really ugly...
For some reason, all I can think of is the register. :P

Same here. I got confused there for a bit :D
Title: Re: Trig in Axe
Post by: SirCmpwn on March 29, 2011, 06:54:34 pm
Okay, bumping this.
I'm struggling to understand.  According to Axe the cosine of 0 is 127.  How do I get 1 out of this?
Title: Re: Trig in Axe
Post by: squidgetx on March 29, 2011, 07:01:49 pm
Divide by 128. Unfortunately, you'll lose 1/128th :( Read my slope physics tutorial for more help on this :) (Edit; I see you are. Never mind then :P)
Title: Re: Trig in Axe
Post by: SirCmpwn on March 29, 2011, 07:04:03 pm
I thought that was the case, however, cos(45) returns 63 in Axe.  cos(45) is approximately equal to .7071, however, 63/128 is .4922.
Title: Re: Trig in Axe
Post by: Runer112 on March 29, 2011, 07:07:50 pm
The sine and cosine functions in Axe use binary degrees because they're much more optimized. That means 256 degrees in a circle instead of 360. cos(32) would return a value much closer to what you're expecting.
Title: Re: Trig in Axe
Post by: SirCmpwn on March 29, 2011, 07:09:09 pm
Hmm.  Okay, I think I understand better.
Thanks!