The SIN function returns the sine of an angle in radians; that is, the vertical component of a unit vector in the direction θ.
- Syntax: value! = SIN(radian_angle)
- Angle must be in radians. To convert from degrees to radians, multiply degrees by π/180.
- Accuracy can be determined as DOUBLE by following the parameter value with a # suffix.
Example 1: Displays rotating gears made using SIN and COS to place the teeth lines.
SCREEN 9 DIM SHARED Pi AS SINGLE Pi = 4 * ATN(1) DO FOR G = 0 TO Pi * 2 STEP Pi / 100 CLS 'erase previous CALL GEARZ(160, 60, 40, 20, 4, G, 10) CALL GEARZ(240, 60, 40, 20, 4, -G, 11) CALL GEARZ(240, 140, 40, 20, 4, G, 12) CALL GEARZ(320, 140, 40, 20, 4, -G, 13) CALL GEARZ(320 + 57, 140 + 57, 40, 20, 4, G, 14) CALL GEARZ(320 + 100, 140 + 100, 20, 10, 4, -G * 2 - 15, 15) _DISPLAY _LIMIT 20 'regulates gear speed and CPU usage NEXT G LOOP UNTIL INKEY$ <> "" END SUB GEARZ (XP, YP, RAD, Teeth, TH, G, CLR) t = 0 x = XP + (RAD + TH * SIN(0)) * COS(0) y = YP + (RAD + TH * SIN(0)) * SIN(0) PRESET (x, y) m = Teeth * G FOR t = -Pi / 70 TO 2 * Pi STEP Pi / 70 x = XP + (RAD + TH * SIN((Teeth * t + m)) ^ 3) * COS(t) y = YP + (RAD + TH * SIN((Teeth * t + m)) ^ 3) * SIN(t) LINE -(x, y), CLR IF INKEY$ <> "" THEN END NEXT t PAINT (XP, YP), CLR 'gear colors optional END SUB
Made by: DarthWho, revised by: Clippy.
Example 2: Displaying the current seconds for an analog clock. See COS for the clock face hour markers.
SCREEN 12 Pi2! = 8 * ATN(1): sec! = Pi2! / 60 ' (2 * pi) / 60 movements per rotation DO Seconds% = VAL(RIGHT$(TIME$, 2)) - 15 ' update seconds S! = Seconds% * sec! ' radian from the TIME$ value Sx% = CINT(COS(S!) * 60) ' pixel columns (60 = circular radius) Sy% = CINT(SIN(S!) * 60) ' pixel rows LINE (320, 240)-(Sx% + 320, Sy% + 240), 12 DO: Check% = VAL(RIGHT$(TIME$, 2)) - 15: LOOP UNTIL Check% <> Seconds% ' wait loop LINE (320, 240)-(Sx% + 320, Sy% + 240), 0 ' erase previous line LOOP UNTIL INKEY$ = CHR$(27) ' escape keypress exits
The value of 2 π is used to determine the sec! multiplier that determines the radian value as S! The value is divided by 60 second movements. To calculate the seconds the TIME$ function is used and that value is subtracted 15 because the 0 value of pi is actually the 3 hour of the clock (15 seconds fast). SIN and COS will work with negative values the same as positive ones! Then the column and row coordinates for one end of the line are determined using SIN and COS multiplied by the radius of the circular line movements. The minute and hour hands could use similar procedures to read different parts of TIME$.