Shop OBEX P1 Docs P2 Docs Learn Events
Maths problem Cosine — Parallax Forums

Maths problem Cosine

kevinb2050kevinb2050 Posts: 56
edited 2008-09-10 00:26 in BASIC Stamp
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
·

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2008-09-09 16:44
    Maybe this tutorial will help:
    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
  • ercoerco Posts: 20,256
    edited 2008-09-09 18:13
    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."
  • kevinb2050kevinb2050 Posts: 56
    edited 2008-09-09 23:59
    Thanks Guys, I will go read Tracy's tutorial -
  • ZootZoot Posts: 2,227
    edited 2008-09-10 00:26
    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
    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

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php


    Post Edited (Zoot) : 9/10/2008 12:32:41 AM GMT
Sign In or Register to comment.