As long as I can remember, angles measured in degrees have been taught in school and used in trigonometry. The 360° circle was defined by the ancient Babylonians, who used it to calculate the position of astrological houses, very important to their culture. This caused me no end of grief when I was in high school, because I do not have 360 fingers!
Needless to say I was pleased to find I would be working with radians when I began programming with JB and LB. The only thing I had to do was figure out just what the heck a radian is!
The radian was defined and named by James Thomson in 1873. Why do we need another unit of angular measurement? Angles expressed as radians are directly proportional to the radius of a circle and the value of pi. When we use radians, it is no longer necessary to compute an arc using pi (3.14159.... to infinity). This simplifies many calculations if the trigonometric functions (SIN, COS, TAN, etc.) are expressed in radians, as is the case for JB and LB.
One radian is the angle at the origin of a circle which cuts off an arc equal to the radius. Oops! Run that past me again, please.
Okay, I'll speak very slowly.... The circumference of a circle is 2pi*r. If r=1, then C=2pi*1, or 6.28318... to infinity. A radian is the proportion of the circumference described by the angle (in radians). Angle(radians)/6.28318 = r/C. When we know the radius of a given circle, we can calculate the length of any arc without using pi in the equation. A circle with radius 5 has a circumference of (6.28318 * 5) = 31.4159. Isn't that simple? Angle(radians) * r produces the length of any arc, and we don't need to ask that snotty Artie Abacii to get out his binary-abacus and do the work.
Thanks to James Thomson and radians, I can now do trigonometry counting on only 6.28318 fingers, which is my new constant, every bit as useful as pi, though not quite as tasty.
Next, I'll use my new understanding of radians, to calculate the end point of an angle for printing with the LINE statement of JB. At no time will my fingers leave the end of my hand!
In this demo, I'll OPEN a WINDOW FOR DIALOG AS #1, in order that I may use a default button hidden off screen. We also have a textbox, statictext, and graphicbox where the resulting angle will be printed. The window width and window height are given in the code, and the origin of the angle to be printed is (right) 250 (down) 250, in the lower right corner of the window.
'Illustrate a calculated angle
NOMAINWIN
WindowWidth=300
WindowHeight=300
BUTTON #1.default, "", [doMath], UL, 0, 0, 0, 0 'Hidden button
TEXTBOX #1.tbx, 25, 5, 50, 25 'Textbox for input
STATICTEXT #1.stx, "Enter an angle (0 to 90°)", 90, 10, 180, 25 'Prompt for input
GRAPHICBOX #1.gbx, 0, 0, 300, 300 'Where to print the result
BackgroundColor$="white"
OPEN "Angle Illustration" FOR DIALOG AS #1
PRINT #1, "trapclose [quit]"
[reDo] 'Return here if error
PRINT #1.tbx, ""
PRINT #1.gbx, "down"
PRINT #1.gbx, "COLOR blue"
PRINT #1.gbx, "SIZE 3" 'Fatter lines have fewer "jaggies"
PRINT #1.gbx, "LINE 25 250 250 250" 'length of line is 250-25 = 225
PRINT #1.tbx, "!setfocus"
WAIT
[doMath]
PRINT #1.tbx, "!contents? angle"
IF angle<0 OR angle>90 THEN
NOTICE "Human ERROR!"+CHR$(13)+"The angle is less than 0, or greater"+CHR$(13)+ _
"than 90. Please try again!"
GOTO [reDo]
END IF
GOSUB [getXY]
PRINT #1.gbx, "COLOR blue"
PRINT #1.gbx, "LINE 250 250 "; x2; " "; y2
PRINT #1.gbx, "COLOR black"
PRINT #1.gbx, "PLACE "; (x2+8); " "; (y2+8) 'Fudge factor for line ID's
PRINT #1.gbx, "\B"
PRINT #1.gbx, "PLACE 10 250"
PRINT #1.gbx, "\A"
PRINT #1.gbx, "PLACE 255 250" 'Origin of angles
PRINT #1.gbx, "\O"
PRINT #1.gbx, "FLUSH"
WAIT
[quit]
CLOSE #1
END
[getXY]
angle=(angle/57.29577951) 'Convert angle to radians
x2=250-(cos(angle)*225) 'r = 225
y2=250-(sin(angle)*225)
RETURNWe get the user defined angle and check to see if it falls between 0 and 90°. JB can calulate polar coordinates for any quadrant, but this window is sized for angles between 0 and 90°. When an angle has been accepted, it is first converted to radians, then the x2 y2 coordinates are calculated as with any triangle. Because the x1 origin is 250, the calculated position of x2 is subtracted from 250, the right coordinate of the line. Coordinate y2 is calculated in the same fashion and subtracted from the y1 coordinate for down. We use the same coordinates, with a slight fudge factor to print the letters identifying the end points of the line.
If you choose an origin of (right) 25 and (down) 250 for an angle you are drawing, your values would be x2=25+(cos(angle)*225) and y2=250-(sin(angle)*225)). Sometimes it's helpful to make a sketch of your window, mark the x and y coordinate values of origin, then you can more easily grasp whether your x2 y2 coordinates should be added or subtracted. ("Wrong Way Corrigan" was a Worble who had no sketch!)
If your application has a need to calculate and display any angle, including those less than or greater than 360°, see the code for the Clock Graphic DEMO here, where a second hand, minute hand, and hour hand are simultaneously displayed for different values.