Register    Login    Forum    Search    FAQ

Board index » QBasic Forums (english) » QBasic / QuickBasic related




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Degrees in Qbasic
 Post Posted: Fri Sep 19, 2003 6: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


Top 
  
 
 Post subject: Re: Degrees in Qbasic
 Post Posted: Sat Sep 20, 2003 5:58 am 
Offline
Global Moderator

Joined: Tue Apr 30, 2002 12:38 am
Posts: 94
Location: Pennsylvania
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.


Top 
 Profile  
 
 Post subject: Also...
 Post Posted: Tue Sep 23, 2003 10:03 am 
Offline
QBasic God

Joined: Tue Mar 25, 2003 12:45 am
Posts: 165
Location: U.S.A.
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 FreeBASIC. The syntax is based on QuickBasic, but it expands to use pointers, operator overloading, etc... The list goes on and on!


Top 
 Profile  
 
 Post subject: Re: Degrees in Qbasic
 Post Posted: Fri Oct 24, 2003 5: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


Top 
  
 
 Post subject:
 Post Posted: 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:
PRINT " The value of sin(30) =";SIN(30*D2R)
PRINT " 30 degrees =";30*d2r;"radians, ";
PRINT "and 0.5 radians =";0.5*r2d;"degrees."


Top 
  
 
 Post subject: Re: Degrees in Qbasic
 Post Posted: 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


Top 
  
 
 Post subject: Degrees in QuickBASIC
 Post Posted: 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


Top 
  
 
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 7 posts ] 

Board index » QBasic Forums (english) » QBasic / QuickBasic related


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
SitemapIndex SitemapIndex  RSS Feed RSS Feed  Channel list Channel list


phpBB SEO