Sexagesimal arithmetic, that is. I can get my head around degrees (360 in a circle), minutes (1/60th of a degree) and seconds (1/60th of a minute), but it sure gets confusing when you begin doing arithmetic with deg°min'sec" and trying to add/subtract or multiply/divide with them. Fooey on the ancient Sumerians who invented the sexagesimal system and three cheers for the Arabian mathematicians who gave us the decimal system!
The ancient Sumerians used the sexagesimal (base 60) form of arithmetic somewhere between 3000 and 6000 BCE. That was quite a few years back! Ancient Babylonians adopted and improved upon the sexagesimal system as they were excellent astronomers and very interested in the motion of planetary bodies as they moved through the 12 astrological houses. The Babylonians knew the Earth and planets revolved around the sun, and used that knowledge to predict the position of the planets for any given date. Europeans, however, were still wedded to the concept of the Earth being the center of the solar system until well into the 17th century.
Current use of the sexagesimal system is pretty much limited to astronomy, telling time and plotting the users geographic coordinates of latitude and longitude on the surface of the Earth. Many pocket calculators can make the conversion between angles using the decimal system and angles using the sexigesimal system with the push of a button.
We can also write simple routines using Just Basic to make the conversions. I wrote two methods to accomplish this task, and displayed the results in the console or MAINWIN. You can apply the same techniques to your "Golly-Gee!" converter, using a GUI to get input from the user and display the results on the GUI.
First Example:
'Convert a decimal angle to DMS
'by Welo, 1/03/06
[redo] 'Return here to convert a new value
CLS
INPUT "Enter an angle using decimals... "; angle
decFrac=(angle-INT(angle)) 'Separate degrees from decimal fraction
deg=INT(angle)
PRINT deg; " degrees"
min=decFrac*60 'Multiply decFrac by 60 to obtain minutes
PRINT INT(min); " minutes"
sec=min-INT(min) 'Separate minutes from decFrac
sec=INT((sec*60)+.0005) 'Multiply remaining decFrac by 60 to obtain seconds
PRINT sec; " seconds"
PRINT
INPUT "Do again? (Y/N) "; usrResp$ 'Perform another calculation?
usrResp$=UPPER$(usrResp$)
IF LEFT$(usrResp$,1)="Y" THEN
GOTO [redo]
ELSE
PRINT
PRINT "Okay, have a nice day!"
END IF
END
In the example above, we begin by having the user input any angle with decimal fractions as part of the angle. The first thing we do is separate the whole number from the decimal fraction and use this to display degrees.
Next, we multiply decFrac by 60 (minutes of arc) and use the INT() function to retain only the whole number of minutes to be displayed. Finally, we subtract the INT value of minutes from the decFrac, multiply by 60 and add .0005 to round up if needed, then use the INT value to display the resulting seconds of arc.
The above procedure is very straight forward and is probably the method you would use if making the conversion using paper and pencil. When Carl released JB Ver 1.01, he included the MOD function which is useful for making this sort of conversion.
Second Example:
'Using the MOD function to convert to DMS
'by Welo, 1/03/06
[redo]
CLS
PRINT "Using decimal notation (EX: 121.135 degrees) "
INPUT "Enter any angle: "; angle
deg=INT(angle) 'Separate whole degrees from decimal fraction
decFrac=angle-deg
sec=INT(((decFrac*3600) MOD 60)+.0005) 'Add .0005 to round up
min=INT((decFrac*3600)/60)
PRINT angle; " = " ; deg ;CHR$(176); min ;CHR$(39); sec;CHR$(34)
PRINT
INPUT "Do again? (Y/N) "; usrResp$
usrResp$=UPPER$(usrResp$)
IF LEFT$(usrResp$,1)="Y" THEN
GOTO [redo]
ELSE
PRINT
PRINT "Okay, have a nice day!"
END IF
END
This code performs the same conversion as above, however I first multiplied the decFrac by 3600 (60 minutes times 60 second of arc measurement). When dividing (decFrac*3600) MOD 60, the result yields the seconds remaining after all the minutes have been factored out. I added .0005 again in the event it was necessary to round up to obtain the most accurate answer.
Next, (decFrac*3600) is divided by 60 to yield the number of minutes, which will be displayed as an INT value. Finally, the results are concatenated using the characters appropriate for displaying the degrees, minutes, and seconds.
The conversion can be made in a FUNCTION or SUB, as long as you remember to pass angle to the FUNCTION or SUB and return the result BYREF, or you can use the FUNCTION or SUB to print results to the MAINWIN or GUI without getting a return value.
Most of your arithmetic conversions will be from degrees with a decimal fraction to DMS. If your value is in radian measurement, simply convert to degrees using radians times 57.29577951 = degrees, then convert to DMS with one of the methods above.
The Babylonians used the sexagesimal system to calculate square and cube roots. Probably the complexity of calculating interest in Babylonian banks, or taxes by the Babylonian Internal Revenue Service, eventually led to the downfall of Babylonia. Or it could have been because of Val Kilmer...? No, I guess not... the decimal system was not in general use until much later than the time of Alexander.