Page 1 of 1

Degrees in Qbasic

Posted: Fri Sep 19, 2003 7:13 pm
by Guest
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

Re: Degrees in Qbasic

Posted: Sat Sep 20, 2003 6:58 am
by frankiebaby
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.

Also...

Posted: Tue Sep 23, 2003 11:03 am
by Dr_Davenstein
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.

Re: Degrees in Qbasic

Posted: Fri Oct 24, 2003 6:33 am
by Guest
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

Posted: Sat Nov 06, 2004 3:52 am
by Guest
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."

Re: Degrees in Qbasic

Posted: Mon Nov 08, 2004 5:43 pm
by RalphA
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

Degrees in QuickBASIC

Posted: Mon Nov 08, 2004 5:47 pm
by RalphA
Sorry about the error above. Please change the "equivalcy" to:

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

Thank you for your patience. :(

RalphA