No problem, probably should have done that in the first place.
Use the includes for trig.inc at the beginning of the program
When you are doing an atan2 (you get the hypotenuse for free) load up values x and y.
For instance
what do these numbers mean? Well for atan2 they mean a point at location x,y from origin. This function accepts numbers up to from -32,767 to 32,767Code:x = 25980 y = 15000
now call your atan subroutine
result, ang = 5461 or about 30 degrees radian (60 degrees deg).Code:call atan
You will get your result in the variable called "ang" for angle and "x" for hypotenuse. Now hypotenuse will be in the same scale as your x and y coordinates, but the angle is represented by 0 = 0 and 32,767 = 180 degrees. I believe that -5461 will be 120 degrees. So to figure your angle, 1 degree = 46602/256 (or about 182) of these radians. Update, since radians start at 90 degrees, you have to do a little math to calc degrees.
Now for sincos. This calculates the sin and cos simultaneously.
Load you angle "ang" with an angle value using the funky radians from above
results, sin(60 degrees) = x = 25981 , cos(60 degrees) = y = 15004Code:ang = 5461 call sincos
Now to make sense of your results, instead of using the strange radians from above, you get a result of -30,000 to 30,000. So converting the above results by dividing by 30,000, you get
sin(60) = .8660333 and cos(60)= .5001333 . These results are pretty close to what I get on my calculator, .8660254 and .500000 respectively.
Bookmarks