Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: Raylin on April 05, 2010, 11:39:17 pm
-
I just now looked at a tech demo BuilderBoy released with an old update of Axe.
I am in need of some explanation of said technique.
Or is this physics magic again?
-
Which one?
-
You would prbly need Builderboy help directly, but now his forum posting activity is getting more and more sparse (he will post a lot on a day, then not post for 3 or 4 days, then post like 30 times one day and go in hiatus again) so good luck x.x
-
Hiya, and yeah, right now is a pretty busy time in school for me, so activity will probably be pretyt low until AP testing is all finished and my teachers stop giving me all this review homework X.X
As for the rotating sprites, it uses a custom Sin routine that is located both early in the routines section, and at the end of the program. It inputs a value from 0-63 (0 to 2PI) and outputs the result in 0-10. Using this sin routine, it is fairly easy to generate a roaring sprite loop, using the sin routine for Y, and offsetting the angle by 90 to change it into a Cos routine (cos(ang) = sin(ang+90)) for X. Do you want me to go into more detail about the specifics of the code, and how the Sin routine works?
-
When does AP testing ends?
It would be cool if you wrote some kind of tutorial, especially for ppl who didn't do trig for years like me (we only skimmed through it in math, during a few days, then moved on, in 2002)
-
In a couple of weeks. Its a big deal right now since its Senior year and i'm taking 3 AP classes.
I think i will include a trig tutorial in my physics thread, as it is sooo useful that i use it all the time in complex physics and even basic rotational movement. I might post that while i'm still getting the collision section finished (its more complicated to explain than i thought)
-
Ouch x.x, I sure hope the same thing that happened to Liazon, nitacku and the like won't happen to you x.x (they took that many and eventually moved on completly from other stuff like calcs x.x)
-
I could possibly help with some explanations of trigonometry things.
@Builderboy
If you know what kind of things you might wanna explain or anything like that you could send me a list or something and I could start working on explanations/tutorials or something. If ya want :)
-
Axe doesn't have sin() and cos() yet. I'm adding those when I switch to singed numbers. Builderboy used the first 2 terms of the taylor series expansion of sin to get approximations. That's probably why the code doesn't make much sense at first glance. If you haven't taken calculus then its probably best you wait until I get the trig functions supported becasue the actual math involved is a lot more complicated.
-
I thought Axe alerady switched to signed numbers a few versions ago?
-
Nope x.x The only one I did so far was multiplication. I still have to write about 15 new routines from scratch for signed math, but I'll see if I can do them all (or most) by next version.
-
Oh ok, I guess when I heard about the multiplication part I misunderstood and thought it was Axe as a whole x.x. Take your time, though (since there's school and stuff)
-
Well, if you find a viable sine and cosine routine, then these equations are used to rotate, where x and y are the position, and x' and y' are the resulting position:
x' = x*cos(angle) - y*sin(angle)
y' = x*sin(angle) + y*cos(angle)
-
so for example something like this? (TI-BASIC)
9->X
9->Y
ClrDraw
While 1
For(Z,0,359
Pt-On(X*cos(Z)-y*sin(Z),X*sin(Z)-y*cos(Z
End
End
right?
(Altough this example appears to be kinda buggy... the first time the dot is displayed at the highest top value it can be as well as the farthest to the right x.x)
-
That looks almost right.
The Pt-On line should look like this:
Look here↓
Pt-On(X*cos(Z)+Y*sin(Z),X*sin(Z)-Y*cos(Z
And, it can be optimized to this as well:
Pt-On(Xcos(Z)+Ysin(Z),Xsin(Z)-Ycos(Z // Removed "*" tokens
Keep in mind that it rotates around the origin, or the 0, 0 point. Also, you can keep adding 1 to Z, and it will still work. Z does not have to be between 0 and 360, 361 will rotate it 1 degree.
-
You can optimize that further to this:
Pt-On(RCos(Z),Rsin(Z
Where Z is the angle to rotate, starting from the X axis, and R is the distance from the origin. This uses less trig, but then you have to do a bit more math to start from a specific location.
I will be going over a lot more in my upcoming Trig tutorial, it should be up by the end of the day, i had a lot of free time in CompSci today ^^
-
so for example something like this? (TI-BASIC)
9->X
9->Y
ClrDraw
While 1
For(Z,0,359
Pt-On(X*cos(Z)-y*sin(Z),X*sin(Z)-y*cos(Z
End
End
right?
(Altough this example appears to be kinda buggy... the first time the dot is displayed at the highest top value it can be as well as the farthest to the right x.x)
Well your code only really seems to be buggy in the sense that "Y" gets erased do the the glitch. (So you were constantly adding or subtracting zero.)
As for the "+" and "-" it doesn't really matter which one is where, as long as you have both it will work. It will just start in a different quadrant.
This is what I kinda changed your code to (this uses what SirCmpwn said):
ZSquare
ClrDraw
For(Z,0,359
Pt-On(5cos(Z)+5sin(Z),5sin(Z)-5cos(Z
End
But like Builderboy said you can simplify the code to:
ZSquare
ClrDraw
For(Z,0,359
Pt-On(5cos(Z),5sin(Z
End
-
I tried making a version of this in Axe, didn't really turn out too well, just looked like an hourglass. Here's my code:
(note:I know this isn't optimized, I just wanted to get it to work at all, then optimizations)
[8000000000000000->Pic1
9->x->Y
0->Z
repeat getkey(15)
Z+90Sub(S)->D
ZSub(S)->E
Pt-On(5*D+30,5*E+30,Pic1
Z+1->Z
DispGraph
End
Return
Lbl S
->A^64/16->B
A^16->A
If B^2
16-A->A
End
A-(A*A*A/600->A
If B/2^2
-A->A
End
A
Return
-
Is routine S supposed to return the sine of Ans?
-
yes, I'm using builderboy's sin routine
-
Oh its because the input is not in degrees. Add 16, not 90, as a full rotation is 64, not 360.
-
now it just displays a plus sign?
-
Actually, cos(Z) = sin(90-Z), not sin(Z+90)
Edit:
Er, I meant 16 in this case :P
-
It still shows a plus for some reason... Here's my code again:
[8000000000000000->Pic1
9->x->Y
0->Z
repeat getkey(15)
16-ZSub(S)->D
ZSub(S)->E
Pt-On(5*D+30,5*E+30,Pic1
Z+1->Z
DispGraph
End
Return
Lbl S
->A^64/16->B
A^16->A
If B^2
16-A->A
End
A-(A*A*A/600->A
If B/2^2
-A->A
End
A
Return
Edit: Calc84 found the bug
A-(A*A*A/600->A
should be
A-(A*A*A/600)->A
the '->' doesn't close parenthesis
-
You can approximate sin(x) with the parabola: y = 4/pi x - 4/pi^2 x^2 over the range [0,pi]
I have an implementation in z80 in my math.inc file. Not sure how axe does sin and cos.
-
Axe doesn't have a built in sin routine yet. I'll have to try what you were saying.
*looks for Will_W's math.inc file*
-
calc84 made some wicked optimizations to it, maybe he'll post them here if we're lucky.
Sin_A:
;input a in pi/256 radians from [0,pi)
;output l is a binary value in the range [0,1)
;destroys h,de
;a is unmodified
;Will West
ld h,a
ld e,h
call HtimesE;hl=x^2
ex de,hl;x^2
ld l,a
ld h,0
or a;reset carry
sbc hl,de
add hl,hl
add hl,hl
ret
HtimesE:
ld l,0
ld d,0
sla h ; optimised 1st iteration
jr nc,$+3
ld l,e
add hl,hl ;1
jr nc,$+3 ;
add hl,de ;
add hl,hl ;2
jr nc,$+3 ;
add hl,de ;
add hl,hl ;3
jr nc,$+3 ;
add hl,de ;
add hl,hl ;4
jr nc,$+3 ;
add hl,de ;
add hl,hl ;5
jr nc,$+3 ;
add hl,de ;
add hl,hl ;6
jr nc,$+3 ;
add hl,de ;
add hl,hl ;7
jr nc,$+3 ;
add hl,de ;
ret
;;=================================================================================
;;does sin(a) where a is between (-pi,pi) and is in units of
;;128/pi radians
;;inputs a
;;outputs a
;;destroys bc,de,hl
;;=================================================================================
Sin_A_Signed:
bit 7,a
jr z,Sin_A_Signed2
neg
sla a
call Sin_A
ld a,l
neg
ret
Sin_A_Signed2:
sla a
call Sin_A
ld a,l
ret
-
That looks almost right.
The Pt-On line should look like this:
Look here↓
Pt-On(X*cos(Z)+Y*sin(Z),X*sin(Z)-Y*cos(Z
And, it can be optimized to this as well:
Pt-On(Xcos(Z)+Ysin(Z),Xsin(Z)-Ycos(Z // Removed "*" tokens
Keep in mind that it rotates around the origin, or the 0, 0 point. Also, you can keep adding 1 to Z, and it will still work. Z does not have to be between 0 and 360, 361 will rotate it 1 degree.
woops lol why did I forgot about those *? :D, I guess when I am used more to Axe, if I decide to go back to BASIC afterward, I'll have to be careful ^^