BBC BASIC
Programming >> BBC BASIC Language >> Trigonometry Woes...
http://bbcbasic.conforums.com/index.cgi?board=language&action=display&num=1513614863

Trigonometry Woes...
Post by jimcroisdale on Dec 18th, 2017, 3:34pm

Hi all,

Using BBC BASIC for Windows, evaluation version.

Trying to get one of the angles in a right angled triangle. I know the length of all three sides (two being user inputs and the hypotenuse being worked out from those using Pythagoras).

So just need a line of code that works to give me one of the angles (other than the right angle smiley )

Any clues?

Cheers,

Jim


Re: Trigonometry Woes...
Post by jimcroisdale on Dec 18th, 2017, 4:07pm

To expand, I have three variables:

OPPOSITE - length of the side opposite the angle i want to calculate
ADJACENT - length of the side next to the angle i want to calculate
HYPO - the hypotenuse

So I need some code that will work out the variable"ANGLE".

regards,
Jim
Re: Trigonometry Woes...
Post by Richard Russell on Dec 18th, 2017, 4:25pm

on Dec 18th, 2017, 4:07pm, jimcroisdale wrote:
So I need some code that will work out the variable"ANGLE".

Back more years than I care to admit, the 'helpful' mnemonic was OHMS: Opposite over Hypotenuse Means Sine (well, helpful if you knew that Ohms was the unit for resistance I suppose, or was it On Her Majesty's Service?).

So it follows that you need inverse-Sine (ASN) to get back to the angle:

Code:
      ANGLE = ASN(OPPOSITE / HYPOTENUSE) 

Though since you say you know all three sides you can equivalently use:

Code:
      ANGLE = ACS(ADJACENT / HYPOTENUSE) 

or:

Code:
      ANGLE = ATN(OPPOSITE / ADJACENT) 

Richard.

Re: Trigonometry Woes...
Post by jimcroisdale on Dec 18th, 2017, 4:35pm

Thankyou for the reply! I've addded that in but it doesnt seem to work.

490 PRINT " Ackermann Angle Calculator"
500 PRINT " **************************"
510 PRINT '
520 INPUT " Enter Distance Between Kingpins in MM: " TRACK
530 INPUT " Enter Distance Between Front and Back Axle in MM: " LONG
540 ADJACENT = TRACK / 2
550 OPPOSITE = LONG
560 HYPO = SQR((ADJACENT*ADJACENT)+(OPPOSITE*OPPOSITE)) REM Pythagoras Bit!
595 ANGLE = ASN(OPPOSITE/HYPO)
600 PRINT ADJACENT
610 PRINT OPPOSITE
620 PRINT HYPO
630 PRINT ANGLE

I'm running the program and entering the sides as 500 and 500. it's working out the hypo to 707 which is right. But then the angle (which should be 45deg) is coming out at 0.785.

Any ideas what I'm doing wrong? smiley

Re: Trigonometry Woes...
Post by Richard Russell on Dec 18th, 2017, 4:40pm

on Dec 18th, 2017, 4:35pm, jimcroisdale wrote:
But then the angle (which should be 45deg) is coming out at 0.785. Any ideas what I'm doing wrong?

Nothing. 0.785 radians is approximately 45 degrees:

Code:
      ANGLE = DEG(ASN(OPPOSITE/HYPO)) 

Richard.
Re: Trigonometry Woes...
Post by jimcroisdale on Dec 18th, 2017, 4:40pm

Haha, yes! Just figured that out myself! smiley

All working now - thankyou!