PDA

View Full Version : Maths problem Cosine

kevinb2050
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
·

Tracy Allen
09-09-2008, 11:44 PM
Maybe this tutorial will help:
www.emesys.com/BS2math3.htm#arcCos (http://www.emesys.com/BS2math3.htm#arcCos)

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.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com (http://www.emesystems.com)

erco
09-10-2008, 01:13 AM
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."

kevinb2050
09-10-2008, 06:59 AM
Thanks Guys, I will go read Tracy's tutorial -

Zoot
09-10-2008, 07:26 AM
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.

e.g.

x VAR Word ' signed x position or cosine
y VAR Word ' signed y position or sine

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

1uffakind.com/robots/povBitMapBuilder.php (http://1uffakind.com/robots/povBitMapBuilder.php)