Trig Functions

Popular in previous forums place your programming snippets here
Post Reply
User avatar
Martin
Global Admin
Posts: 423
Joined: Mon Jan 02, 2023 5:18 pm

Trig Functions

Post by Martin »

While reminiscing elsewhere about surveying solutions on an Organiser II reminds me..

CM/XP version OPL
Although the Psion team included the normal set of Trig Functions SIN(), COS(), and TAN() they only included one inverse function ATAN().. Also as we in the UK generally like to work in Degrees rather than Radian or Gradians; the following snippets will work as a replacement..

Code: Select all

ASIN:(x)
RETURN DEG(ATAN((x/(SQR(1-x**2)))))

ACOS:(x)
RETURN DEG((ATAN((SQR(1-x**2))/x)))

ATAN:(x)
RETURN DEG(ATAN(x))
And including LZ OPL...

Code: Select all

DEG:(x)
RETURN DEG(RAD(x))

SIN:(x)
RETURN SIN(RAD(x))

COS:(x)
RETURN COS(RAD(x))

TAN:(x)
RETURN TAN(RAD(x))
If we need the calculated angle to de displayed in Deg,Min,sec we can use..

Code: Select all

DMS:(Dd)
LOCAL g%,d,m,s
d=INT(Dd)
m=INT((Dd-d)*60)
s=INT((((Dd-d)*60)-m)*60)
AT 1,2 :PRINT "                ";
AT 1,2 :PRINT "Angle ";d;CHR$(223);m;CHR$(39);s;CHR$(34)
g%=GET
RETURN g%  :REM Return KEY press for use in calling routine
Try this... The pitch of a domestic staircase, which you must prove to the the Building Inspector is less that the maximum allowed in the Building Regulations of 42 degrees, that has a tread going of 220mm and a rise of 190mm is... (TAN=Opp/Adj)

DMS:(ATAN:(190/220))

Post below if you try it!
In good faith
Martin
amenjet
Posts: 405
Joined: Tue Jan 03, 2023 7:54 pm

Re: Trig Functions

Post by amenjet »

I've been looking at this as well, and found a reference to the book 'Software Manual For The Elementary Functions" by Cody and Waite'.
This is what was used by Psion to implement the floating point functions, or at least some of them. The book isn't available online so I bought a copy.

I have for now used the built-in Pico functions for sin and cos and so oon, but am hoping to use the algorithms in the book, not least because the built-in functions don't give 12 digits as the Psion does. There is a random number generator in the book but it doesn't seem to be the Psion one.
Post Reply