View Full Version : Maths problem Cosine
09-09-2008, 02:28 PM
How do you convert a cosine number into an angle with a basic stamp BS2e
The maths function is Inverse Cosine or arc cosine (acos) for example
The COS of 80 degrees is 0.17365
So if I have the number 0.17365 I want to convert it back into the angle 80 degrees
09-09-2008, 11:44 PM
Maybe this tutorial will help:
The Stamp uses integer math for everything, and angles and fractional lengths are no exception. 0.17365 will be 22 on the Stamp, because 22/128 = 0.172. Full scale is -127 to +127. Angles are in brads, 0 to 255 for a full circle. It is not very precise, but okay for some applications.
There are Basic Stamp-ish clones that offer floating-point math and on-board math libraries that may appear easier to use, but they don't have the documentation and wealth of support that the Stamp has to draw off. Their own online forums are filled with complaints about how they feel abandoned by the support staff.
Use the force. Stick with the Stamp. This online forum is the most amazing resource of friendly, educated, and helpful people I have ever found. You'll find useful workarounds for any features the Stamp may lack.
·"If you build it, they will come."
09-10-2008, 06:59 AM
Thanks Guys, I will go read Tracy's tutorial -
Tracy's material contains one slightly outdated set of notes -- ATN and HYP and the like *are* currently documented. The built-in ATN operator gets fed cos/sin e.g. x/y a and returns the angle.. See the Pbasic manual under operators. The real pain here is that the X/Y coordinates need to be -127 to 127 so any coordinates you feed to ATN need to be normalized first (if either value is > 127 or < -127). Like cos/sin on the Stamp, ATN deals with angles as "brads" -- 256 to a circle.
x VAR Word ' signed x position or cosine
y VAR Word ' signed y position or sine
angle VAR Byte ' angle in brads (0-128-255 instead of 0-180-359)
x = 100 ' in regular trig, I would expect an angle of 45 degrees, which is 32 in "brads", 1/4 of the way to 128
y = 100
angle = x ATN y ' angle will equal 32
x = -100 ' in regular trig, I would expect an angle of 45 degrees, which is 32 in "brads", 1/4 of the way to 128
y = 100
angle = x ATN y ' angle will equal 96 brads, equiv to 135 degrees
angle = 64 ' equivalent to 90 degrees
x = COS angle ' = 0 or "0.0" on the unit circle
y = SIN angle ' = 127 or "1.0" on the unit circle
When the going gets weird, the weird turn pro. -- HST
Post Edited (Zoot) : 9/10/2008 12:32:41 AM GMT