Shop OBEX P1 Docs P2 Docs Learn Events
Combine SIN and SQR to perform TAN. — Parallax Forums

Combine SIN and SQR to perform TAN.

ArchiverArchiver Posts: 46,084
edited 2003-11-18 01:58 in General Discussion
As you all know, Basic stamp don't perform Tan calculation.
Still, I need to calculate the angle in a triangle with one 90 dgr
angle. *
**
* *
* *
c * *
* *b=50
* * Tan B= b/a
* *
* B 90*
**********************
a=100

If I only have the value b=50 and a=100, I could use Pythagoras to
calculate c, and then perform Sin B=b/c. So in theory I do
c=SQR((50*50)+(100*100)). Then do Sin B= b/c.

This calculation is far too heavy for my code experience. I can't
even get the BS2p to calculate Sin B=2/2.5 correctly.

Is there anybody with code experience done something this
complicated?

Stein.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-11-17 00:20
    Hi Stein,

    The Stamp only calculates with whole numbers, so 2.4 means 2 for the Stamp!

    Another thing is that the Stamp devides the angle into 255 'brads', this
    correspnds to the usual 360 degrees. (page 65/66 of my manual).

    So you have to keep the numbers in the sine-calculation high enough to get
    the desired precision and you have to take account for the somewhat strange
    (to me) units of the angles used by the Stamp.

    I hope this helps a little,

    Klaus



    Oorspronkelijk bericht
    Van:
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-17 02:11
    You need to find the angle B in the diagram below. You are in luck,
    because the Stamp does have an arctan function, not well documented,
    but it has been there all along. angleB = arctan (sideb/sidea)

    sideA var word
    sideB var word
    angleB var word

    sideA=100
    sideB=50
    angleB = ATN (sideB/sideA)
    DEBUG "brads=",dec angleB, CR
    DEBUG "degrees=",dec angleB */ 360, CR
    ' prints brads=18 degrees=25
    END

    Correct value of arctan (0.5) = 26.565 degrees. The resolution is
    not too great, but it is based on 256 brads in a full circle.
    Conversion from brads to degrees (360 per circle) is done by the */
    360 operator in the second DEBUG command.

    -- Tracy


    >As you all know, Basic stamp don't perform Tan calculation.
    >Still, I need to calculate the angle in a triangle with one 90 dgr
    >angle. *
    > **
    > * *
    > * *
    > c * *
    > * *b=50
    > * * Tan B= b/a
    > * *
    > * B 90*
    >**********************
    > a=100
    >
    >If I only have the value b=50 and a=100, I could use Pythagoras to
    >calculate c, and then perform Sin B=b/c. So in theory I do
    >c=SQR((50*50)+(100*100)). Then do Sin B= b/c.
    >
    >This calculation is far too heavy for my code experience. I can't
    >even get the BS2p to calculate Sin B=2/2.5 correctly.
    >
    >Is there anybody with code experience done something this
    >complicated?
    >
    >Stein.
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-17 16:13
    Hi Stein,

    The program should read
    angleB = sideA ATN sideB
    not
    > angleB = ATN (sideB/sideA)

    The syntax for the Stamp's built in ATN function is,

    angle = adjacent ATN opposite

    *
    **
    * *
    * *
    * *
    * *opposite
    * * Tan(angle)= opposite/adjacent
    * * angle = arctan (opposite/adjacent)
    * angle 90*
    **********************
    adjacent


    There is info about the command in the help system with the IDE and at
    http://www.emesystems.com/BS2math3.htm#ATN_HYP



    >
    > sideA var word
    > sideB var word
    > angleB var word
    >
    > sideA=100
    > sideB=50
    > angleB = ATN (sideB/sideA)
    > DEBUG "brads=",dec angleB, CR
    > DEBUG "degrees=",dec angleB */ 360, CR
    > ' prints brads=18 degrees=25
    > END
    >
    >Correct value of arctan (0.5) = 26.565 degrees. The resolution is
    >not too great, but it is based on 256 brads in a full circle.
    >Conversion from brads to degrees (360 per circle) is done by the */
    >360 operator in the second DEBUG command.
    >
    > -- Tracy
    >
    >
    >>As you all know, Basic stamp don't perform Tan calculation.
    >>Still, I need to calculate the angle in a triangle with one 90 dgr
    > >angle. *
    > > **
    >> * *
    >> * *
    >> c * *
    >> * *b=50
    >> * * Tan B= b/a
    >> * *
    > > * B 90*
    >>**********************
    >> a=100
    > >
    >>If I only have the value b=50 and a=100, I could use Pythagoras to
    >>calculate c, and then perform Sin B=b/c. So in theory I do
    >>c=SQR((50*50)+(100*100)). Then do Sin B= b/c.
    >>
    >>This calculation is far too heavy for my code experience. I can't
    >>even get the BS2p to calculate Sin B=2/2.5 correctly.
    > >
    > >Is there anybody with code experience done something this
    > >complicated?
    > >
    > >Stein.
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-17 18:44
    Thanks, Tracy.
    I'm astounded by your replies.
    Don't know what I done without this discussion grope.

    Stein.


    --- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
    > Hi Stein,
    >
    > The program should read
    > angleB = sideA ATN sideB
    > not
    > > angleB = ATN (sideB/sideA)
    >
    > The syntax for the Stamp's built in ATN function is,
    >
    > angle = adjacent ATN opposite
    >
    > *
    > **
    > * *
    > * *
    > * *
    > * *opposite
    > * * Tan(angle)= opposite/adjacent
    > * * angle = arctan (opposite/adjacent)
    > * angle 90*
    > **********************
    > adjacent
    >
    >
    > There is info about the command in the help system with the IDE
    and at
    > http://www.emesystems.com/BS2math3.htm#ATN_HYP
    >
    >
    >
    > >
    > > sideA var word
    > > sideB var word
    > > angleB var word
    > >
    > > sideA=100
    > > sideB=50
    > > angleB = ATN (sideB/sideA)
    > > DEBUG "brads=",dec angleB, CR
    > > DEBUG "degrees=",dec angleB */ 360, CR
    > > ' prints brads=18 degrees=25
    > > END
    > >
    > >Correct value of arctan (0.5) = 26.565 degrees. The resolution is
    > >not too great, but it is based on 256 brads in a full circle.
    > >Conversion from brads to degrees (360 per circle) is done by the
    */
    > >360 operator in the second DEBUG command.
    > >
    > > -- Tracy
    > >
    > >
    > >>As you all know, Basic stamp don't perform Tan calculation.
    > >>Still, I need to calculate the angle in a triangle with one 90
    dgr
    > > >angle. *
    > > > **
    > >> * *
    > >> * *
    > >> c * *
    > >> * *b=50
    > >> * * Tan B= b/a
    > >> * *
    > > > * B 90*
    > >>**********************
    > >> a=100
    > > >
    > >>If I only have the value b=50 and a=100, I could use Pythagoras
    to
    > >>calculate c, and then perform Sin B=b/c. So in theory I do
    > >>c=SQR((50*50)+(100*100)). Then do Sin B= b/c.
    > >>
    > >>This calculation is far too heavy for my code experience. I can't
    > >>even get the BS2p to calculate Sin B=2/2.5 correctly.
    > > >
    > > >Is there anybody with code experience done something this
    > > >complicated?
    > > >
    > > >Stein.
  • ArchiverArchiver Posts: 46,084
    edited 2003-11-18 01:58
    Hi,

    I wrote an example program that uses the Debug Terminal to
    demonstrate the ATN and HYP operators. It's been sitting on the
    StampsInClass group for a while, and I apologize for not thinking to
    post it here. The program is now in the files section for this group.

    Filename: AtnHypExample.bs2
    Path: http://groups.yahoo.com/group/basicstamps/files/

    The program allows you to enter Cartesian coordinates into the Debug
    Terminal's Transmit windowpane, and displays the hypotenuse magnitude
    and angle in degrees in the Receive windowpane. The values for the
    Cartesian coordinates can be from -128 to 128. For more information
    on the coordinates, see Tracy's explanation of opposite and adjacent
    below.

    Regards, Andy Lindsay
    Parallax, Inc.

    --- In basicstamps@yahoogroups.com,
Sign In or Register to comment.