Degrees in Qbasic

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
Guest
Degrees in Qbasic

Post by Guest » Fri Sep 19, 2003 7:13 pm

I have just finished writing my first program in Q basic.
I was dumbfounded that Q Basic does not allow trigonometrical functions that include inverse SIN (ASN)and COS,(ACS) yet allows inverse TAN (ATN). Not only that, it only gives trigonometrical results in RADIANS, not degrees. Whats the story here?
I acknowledge that I am only very new to this great programming medium and there is something I may have missed in the tutorials, but can someone point me in the right direction as to how I can include these functions in my programs, without having to convert degrees to radians.
Bill

User avatar
frankiebaby
Global Moderator
Posts:95
Joined:Tue Apr 30, 2002 1:38 am
Location:Pennsylvania
Contact:

Re: Degrees in Qbasic

Post by frankiebaby » Sat Sep 20, 2003 6:58 am

There are functions SIN and COS and TAN in qbasic, both 4.5 and 7(PDS). To convert a radian value to degrees, multiply it by 180/PI. It is not uncommon practise to build a lookup table of Trig funtions to speed up their uses to accessing ram rather than actually calculating every time.

Dr_Davenstein
QBasic God
Posts:166
Joined:Tue Mar 25, 2003 12:45 am
Location:U.S.A.
Contact:

Also...

Post by Dr_Davenstein » Tue Sep 23, 2003 11:03 am

You might check out one of the libraries. I know that DirectQB has the DQBangle function. It's a binary shift function though, so you have to understand that you still have to do an extra calculation because
DQB's angles are in the range of 0-255.  

Angle%= Any angle from 0 to 359............

SendAngle%= INT(Angle% / 1.40625)

I don't know if this helps at all, but DQB was coded with ASM. It has sprite rotation and the works. I'd check into LIBS if I were you.
Come check out [url=http://www.freebasic.net/forum/index.php]FreeBASIC[/url]. The syntax is based on QuickBasic, but it expands to use pointers, operator overloading, etc... The list goes on and on!

Guest

Re: Degrees in Qbasic

Post by Guest » Fri Oct 24, 2003 6:33 am

Hi,

you can get the other functions from ATAN:

ACOS(x) = ATAN((sqrt(1-x^2))/x)

and

ASIN(x) = ATAN(x/(sqrt(1-x^2)))

But you need to do some fiddling about for when the denominators are zero.

Cheers,

Chris

Guest

Post by Guest » Sat Nov 06, 2004 3:52 am

At the beginning of your program, define the conversion factors:

d2r = 3.14159/180 'd2r = degrees to radians
r2d = 180/3.14159 'r2d = radians to degrees

Then use the above factors as needed, for instance:

Code: Select all

PRINT " The value of sin(30) =";SIN(30*D2R)
PRINT " 30 degrees =";30*d2r;"radians, ";
PRINT "and 0.5 radians =";0.5*r2d;"degrees."

RalphA

Re: Degrees in Qbasic

Post by RalphA » Mon Nov 08, 2004 5:43 pm

Anonymous wrote:I have just finished writing my first program in Q basic.
I was dumbfounded that Q Basic does not allow trigonometrical functions that include inverse SIN (ASN)and COS,(ACS) yet allows inverse TAN (ATN). Not only that, it only gives trigonometrical results in RADIANS, not degrees. Whats the story here?
I acknowledge that I am only very new to this great programming medium and there is something I may have missed in the tutorials, but can someone point me in the right direction as to how I can include these functions in my programs, without having to convert degrees to radians.
Bill
When BASIC was first devised by two university professors, they used radians functions, as this is the "normal" mode for mathematical functions, in general. And, only the four tringonometric functions, SIN, COS, TAN and ATN were included, the others being left for students to derive, I guess as a challenge.

When QB, QBasic, BASICA, QuickBASIC and, yes, even Visual Basic came along, these little unpleasantries were not corrected, and, so, we are stuck with this, at least for the foreseeable future.

The other arc, or "inverse" functions, ASIN and ACOS have already been posted by the other "Guest" (not me), and a method of converting radians to degrees, and vice-versa also have been posted.

Finally, on could create the user-defined functions (UDF) for the various trigonemetric functions, for instance, one called SIND(angle in degrees), in which entering SIND(30) would be the equivalent of entering SIN(30-3.14159/180), and so on. Would that help you out, Guest No. 1? (the original poster, or OP, as "we" call them :) )

RalphA

RalphA

Degrees in QuickBASIC

Post by RalphA » Mon Nov 08, 2004 5:47 pm

Sorry about the error above. Please change the "equivalcy" to:

SIND(30) = SIN(30*3.14159/180)

Thank you for your patience. :(

RalphA

Post Reply