SIN - mkilgore/QB64pe GitHub Wiki
The SIN function returns the vertical component or sine of an angle measured in radians.
- value! = SIN(radian_angle!)
- The radian_angle must be measured in radians from 0 to 2 * Pi.
- To convert from degrees to radians, multiply degrees * π/180.
- SINE is the vertical component of a unit vector in the direction theta (θ).
- Accuracy can be determined as SINGLE by default or DOUBLE by following the parameter value with a # suffix.
'' '' SCREEN 12 PI = 4 * ATN(1) PRINT "PI = 4 * ATN(1) ="; PI PRINT "COS(PI) = "; COS(PI) PRINT "SIN(PI) = "; SIN(PI) DO PRINT INPUT "Enter the degree angle (0 quits): ", DEGREES% RADIANS = DEGREES% * PI / 180 PRINT "RADIANS = DEGREES% * PI / 180 = "; RADIANS PRINT "X = COS(RADIANS) = "; COS(RADIANS) PRINT "Y = SIN(RADIANS) = "; SIN(RADIANS) CIRCLE (400, 240), 2, 12 LINE (400, 240)-(400 + (50 * SIN(RADIANS)), 240 + (50 * COS(RADIANS))), 11 DEGREES% = RADIANS * 180 / PI PRINT "DEGREES% = RADIANS * 180 / PI ="; DEGREES% LOOP UNTIL DEGREES% = 0 '' '' |
PI = 4 * ATN(1) = 3.141593 COS(PI) = -1 SIN(PI) = -8.742278E-08 Enter the degree angle (0 quits): 45 RADIANS = DEGREES% * PI / 180 = .7853982 X = COS(RADIANS) = .7071068 Y = SIN(RADIANS) = .7071068 DEGREES% = RADIANS * 180 / PI = 45 |
- Explanation: When 8.742278E-08(.00000008742278) is returned by SIN or COS the value is essentially zero.
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...NEXT 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 '' '' |
Example 3: 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 CIRCLE (320, 240), 80, 1 DO LOCATE 1, 1: PRINT TIME$ 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 |
- _PI (QB64 function)
- COS (cosine)
- ATN (arctangent)
- TAN (tangent)
- Mathematical Operations
- Derived Mathematical Functions
Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page