Shop OBEX P1 Docs P2 Docs Learn Events
Tired of no SIN/COS/TAN/ARCSIN/ARCCOS/ARCTAN/ARCTAN2 support in SPIN? Try the S — Parallax Forums

Tired of no SIN/COS/TAN/ARCSIN/ARCCOS/ARCTAN/ARCTAN2 support in SPIN? Try the S

KyeKye Posts: 2,200
edited 2010-07-04 23:45 in Propeller 1
Mmm, so I'm going to post this driver up right now and later soon it in the obex for all the people who keep asking for SIN/COS/TAN/ARCSIN/ARCCOS/ARCTAN/ARCTAN2·in SPIN. Currently there is no object in the obex that allows simple integer math trig calculations (weird?), so this object should fill a void that has been arround for a while.

The obex allows blazingly fast SIN, COS, and TAN operations in spin using the sin table and works using degrees which everyone should be·comfortable with.

For example, if you want to do a sin calculations you pass the sin function the degree you want to take the sin of and a radius of a polar plane circle. Thus what the sin function then does is (radius * sin(degree) = result). This basically allows you to scale the output of the sin function up and down with respect to integer math.

Also included are ARCSIN, ARCCOS, ARCTAN, and ARCTAN2... (And the·Pythagorean Theorem Function).·All of the ARC functions·work off using ARCSIN to calculate the degree of something given·the radius of a·polar plane right triangle and some length of one side of the triangle. ARCTAN does this without knowing the radius however as thats·what·ARCTAN is good for... and ARCTAN2.

Anyway, the ARC rountines are not as fast as the·SIN, COS, ans TAN rountines as the ARC rountines use an inverse table lookup algorithm to BSearch through the·Propeller·Chip's·SIN table to figure out the proper angle. The BSearch algorithm is tuned*** slightly to produce more accurate results so when you look at it remember that its·operation has been modified slightly so that the ARC functions return the correct and exact answer also all of the time.

And... also in the library is a random in range function and an integer power function.

Thanks for reading,

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,

Comments

Sign In or Register to comment.