# Difference between revisions of "COS"

Jump to navigation
Jump to search

Code by Ted Weissgerber

imported>Clippy m |
imported>Clippy m |
||

Line 1: | Line 1: | ||

− | The '''COS''' function returns the cosine of an angle in radians | + | The '''COS''' function returns the cosine of an angle measured in radians. |

Line 8: | Line 8: | ||

* Angle must be in radians. To convert from degrees to radians, multiply by π/180. | * 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(x) is calculated in either single or double precision depending on its argument. | ||

::: COS(4) = -.6536436 ...... COS(4#) = -.6536436208636119 | ::: COS(4) = -.6536436 ...... COS(4#) = -.6536436208636119 | ||

Line 41: | Line 42: | ||

{{Cl|CIRCLE}} (cx% + 320, cy% + 240), 3, 12 | {{Cl|CIRCLE}} (cx% + 320, cy% + 240), 3, 12 | ||

{{Cl|PAINT}} {{Cl|STEP}}(0, 0), 9, 12 | {{Cl|PAINT}} {{Cl|STEP}}(0, 0), 9, 12 | ||

− | NEXT | + | NEXT '' '' |

{{CodeEnd}} | {{CodeEnd}} | ||

− | + | {{small|Code by Ted Weissgerber}} | |

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

## Revision as of 05:09, 14 October 2010

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 * *

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

*See also:*

*Navigation:*