Tired of no SIN/COS/TAN/ARCSIN/ARCCOS/ARCTAN/ARCTAN2 support in SPIN? Try the S
Kye
Posts: 2,200
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,
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
(Uploading pictures is not working for the obex... that should be fixed).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
You are spoiling us with all these great objects you keep creating - keep it up!· We love them!
Chris
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:
· Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
· Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
· Prop Tools under Development or Completed (Index)
· Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
· Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
I was really happy getting those operational. Also the SIN/COS/TAN are pretty much the most accurate and fast versions you'll find in spin. I managed to do the SIN table lookup in one line using only ~30 bytes or so.
Thanks,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller