Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Quick Basic - ARCCOS

143 views
Skip to first unread message

UgeneA5

unread,
Mar 19, 1996, 3:00:00 AM3/19/96
to
In article <23...@storm.LakeheadU.Ca>, cc...@lakeheadu.ca writes:

>Does anyone out there know how to get ARCCOS(inverse cos) in
>quickbasic? Thanks Tim

--------------------------------------------------------------------------
--------
DECLARE FUNCTION arcsin# (arg#)
DECLARE FUNCTION arccos# (arg#)

CLS
INPUT "What is argument: -1<= arg# <=1 "; x#
IF ABS(x#) > 1 THEN PRINT "The argument is not valid": END
y = arccos#(x#)
PRINT "The arccos of "; x#; " = "; y
PRINT "this is an angle of ";
PRINT y * 180 / (4 * ATN(1)); " Degrees";

FUNCTION arccos# (arg#)
pi# = 4 * ATN(1)
arccos# = pi# / 2 - arcsin#(arg#)
END FUNCTION

FUNCTION arcsin# (arg#)
pi# = 4 * ATN(1)
IF arg# < 1 AND arg# > -1 THEN
nnn# = ATN(arg# / SQR(1! - arg# * arg#))
ELSEIF arg# = 1 THEN nnn# = pi# / 2
ELSEIF arg# = -1 THEN nnn# = -pi# / 2
END IF
IF arg# > 1 THEN nnn# = 0
IF arg# < -1 THEN nnn# = 0
arcsin# = nnn#

END FUNCTION


Steve Legg

unread,
Mar 20, 1996, 3:00:00 AM3/20/96
to

C>Does anyone out there know how to get ARCCOS(inverse cos) in
C>quickbasic? Thanks Tim

Hi Tim.

Here're a couple of trig functions you'll find useful. These are for
PowerBASIC but should work in QuickBASIC. They need doctoring for use
with QBASIC however.

DECLARE FUNCTION ACos(BYVAL DOUBLE) AS DOUBLE
DECLARE FUNCTION ATan(BYVAL DOUBLE, BYVAL DOUBLE) AS DOUBLE

DIM pi AS SHARED DOUBLE
pi = 4 * ATN(1)

PRINT ACos(.5) * 180./pi
PRINT ATan(1, 1) * 180./pi
END


FUNCTION ACos(BYVAL CosTheta AS DOUBLE) LOCAL AS DOUBLE
'+----------------------------------------------------------------------------+
'| This function accepts a double precision real number (using either a |
'| variable name, an expression or a value). It calculates an angle in |
'| radians for a given COSINE. |
'| |
'| Any program using this function must establish a global variable for pi. |
'| |
'| eg. DIM pi AS SHARED DOUBLE ' a global variable for
|
'| pi = 4 * ATN(1) ' 3.14159265358979 |
'| |
'| ACos is valid for a CosTheta whose absolute value is < 1. |
'+----------------------------------------------------------------------------+

ACos = pi/2. - ATN(CosTheta / SQR(1 - CosTheta * CosTheta))

END FUNCTION


FUNCTION ATan(BYVAL BaseLn AS DOUBLE, BYVAL PerpLn AS DOUBLE) LOCAL AS DOUBLE
'+----------------------------------------------------------------------------+
'| This function accepts two double precision real numbers (using either |
'| variable names, expressions or values). It calculates an angle in |
'| radians for a given base (X-axis) and perpendicular (Y-axis) distance. |
'| |
'| Any program using this function must establish a global variable for pi. |
'| |
'| eg. DIM pi AS SHARED DOUBLE ' a global variable for
|
'| pi = 4 * ATN(1) ' 3.14159265358979 |
'| |
'| ATan returns a positive angle between 0 and 2
radians. |
'+----------------------------------------------------------------------------+

IF PerpLn = 0 AND BaseLn >= 0 THEN ' angle must be 0 or 360
ATan = 0
ELSEIF BaseLn = 0 AND PerpLn > 0 THEN ' angle must be 90
ATan = pi/2.
ELSEIF PerpLn = 0 AND BaseLn < 0 THEN ' angle must be 180
ATan = pi
ELSEIF BaseLn = 0 AND PerpLn < 0 THEN ' angle must be 270
ATan = 3 * pi/2.

' otherwise ...
ELSE
IF PerpLn > 0 THEN ' angle must be between 0 and 180
ATan = pi/2. - ATN(BaseLn/PerpLn)
ELSE ' angle must be between 180 and 360
ATan = 3 * pi/2. - ATN(BaseLn/PerpLn)
END IF
END IF

END FUNCTION

-= Steve Legg -=- RelayNet ->1347 =-
-= Oshawa, Ontario CANADA -=- steve...@westonia.com =-
---
* OLXWin 1.00b * We're lost, but we're making good time.

0 new messages