Difference between revisions of "COS"

The COS function returns the cosine of an angle measured in radians.

Syntax: value! = COS(angle)

• Angle must be in radians. To convert from degrees to radians, multiply by π/180.
• COSINE is the horizontal component of a unit vector in the direction theta (θ).
• COS(x) is calculated in either single or double precision depending on its argument.
COS(4) = -.6536436 ...... COS(4#) = -.6536436208636119

Example 1:

PI = 4 * ATN(1) PRINT COS(PI) DEGREES = 180 RADIANS = DEGREES * PI / 180 PRINT COS(RADIANS)

-1 -1

Example 2: Creating 12 analog clock hour points using CIRCLEs and PAINT

PI2 = 8 * ATN(1) '2 * π arc! = PI2 / 12 'arc interval between hour circles SCREEN 12 FOR t! = 0 TO PI2 STEP arc! cx% = CINT(COS(t!) * 70) ' pixel columns (circular radius = 70) cy% = CINT(SIN(t!) * 70) ' pixel rows CIRCLE (cx% + 320, cy% + 240), 3, 12 PAINT STEP(0, 0), 9, 12 NEXT

Code by Ted Weissgerber

Explanation: The 12 circles are placed at radian angles that are 1/12 of 6.28318 or .523598 radians apart.