# Atari BASIC: difference between DEG & RAD, and when to use

## Recommended Posts

How do we know when to use each?

##### Share on other sites

They change the transcendental functions between degrees (a full circle is 360) and radians (a full circle is 2*pi). So after a DEG, SIN(180) returns 0 and COS(180) will return -1. If you switch to radians with RAD, you need to use pi (eg SIN(3.1415927)) to get the same results.

##### Share on other sites

It's just 2 ways of expressing the same thing, like using feet or metres.

But it comes in handy as systems of the day tended to use one or the other, so converting programs was made easier given the option to choose which one.

##### Share on other sites

Mathematicians like to use radians (a full circle is 0 to 2*pi radians) because it makes exotic formulae a little bit simpler.
Normal people use degrees (a full circle is 360 degrees) for historical reasons (ancient Babylonians used it, therefore we use it).

Easy to convert between them:

radians = degrees * pi / 360.0

degrees = radians * 360.0 / pi

##### Share on other sites

360 degrees - conveniently that has lots of factors and is also the number of days a year was believed to have at some point.

##### Share on other sites
3 hours ago, stepho said:

Mathematicians like to use radians (a full circle is 0 to 2*pi radians) because it makes exotic formulae a little bit simpler.
Normal people use degrees (a full circle is 360 degrees) for historical reasons (ancient Babylonians used it, therefore we use it).

Easy to convert between them:

radians = degrees * pi / 360.0

degrees = radians * 360.0 / pi

I think you mean that radians = degrees * pi / 180 and degrees = radians * 180 / pi.

##### Share on other sites

Great! Thanks for the info, guys.

I expect that most of my Atari trigonometry will be for games, so I think that I'll stick to DEG, unless somebody says otherwise.

I assume that we use can X on the screen to calculate Y, and vice versa, so DEG should make it easier. Feel free to let me know otherwise.

##### Share on other sites
On 3/6/2020 at 3:26 PM, StickJock said:

I think you mean that radians = degrees * pi / 180 and degrees = radians * 180 / pi.

Yes, you are correct.

##### Share on other sites
On 3/6/2020 at 10:57 PM, eugenetswong said:

I assume that we use can X on the screen to calculate Y, and vice versa, so DEG should make it easier.

It probably depends what you're trying to do. Since none of the resolutions to my knowledge is 360x360 anyway you would need to scale everything:

10 DEG:FOR I=0 TO 359:PLOT 80+SIN(I)*30,40+COS(I)*30:NEXT I

15 RAD:PI=ATN(1)*4:FOR I=0 TO 2*PI STEP PI/58:PLOT 80+SIN(I)*20,40+COS(I)*20:NEXT I

Since 180/PI = 57.29, I rounded the second loop to PI/58 steps to get a full circle.

##### Share on other sites

DEG is more practical in that you can do useful things just using integer angle values which makes the program somewhat more readable.

Performance - a quick & dirty Basic program that assigns B=SIN(45) in a 1000 times loop, and the equivalent with RAD sees deg mode win out by about 66 seconds to 63.

The penalty could be in that the radians equivalent is a long fraction.

Trying the same with the reverse advantage - SIN(1) in radians vs the equivalent in degrees sees rad win out by about 72 seconds to 74.

So, I would theorise that there's probably an advantage if the angle in question is an integer which should mean DEG mode wins out most of the time.

##### Share on other sites
5 hours ago, Rybags said:

Performance - a quick & dirty Basic program that assigns B=SIN(45) in a 1000 times loop, and the equivalent with RAD sees deg mode win out by about 66 seconds to 63.

The trigonometric functions are evaluated as power series that takes arguments in radiants. This is mostly because it is simpler to make this series well-behaving and converging. If DEG is active, Atari Basic includes an additional multiplication for ATN to convert the output from radiants to degrees. For SIN and COS, it is a bit more complicated as the first step is an argument reduction to the quarter period of SIN (or COS), and this is a division, no matter whether it is in degrees or radiants. However, numbers are typically smaller for radiants, and thus, it is probably faster.

##### Share on other sites

If your using degrees in a game and know the angles will always be an integer, you can speed things considerably

by pre-calculating the values in the range you need and use a lookup table in your code in an array.

##### Share on other sites

Guys, thanks for your info. I appreciate the input.

I am confident that most uses of DEG and RAD would be used for real time calculations, such as in 2 programs in the older magazines, since we could use arrays and loops to draw the shape.

This info makes me excited.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.