# Command: Cos

Cos (Number) Definition:

The Cos command is a trigonometry function, that returns a number between -1 and 1. This value represents the "X" coordinate of point x,y.

Parameter Description:

number=float or integer representing a value in degree

Command Description:

This command is used for translating angle values to coordinates, but there are a few things you have to take into account when doing it. First of all the Cos() command assumes the point you want is at radius 1 (pixel), next it uses a circle where 0 degrees is due EAST and increases in a counterclockwise direction, then you've got to take into account the the Y axis on a computer screen is up-side-down compared to a normal mathematical coordinate system.
See also ASin, Cos, ACos, Tan, Atan, ATan2

Example:

Graphics 640,480; Change to graphics mode, nothing tricky yet.
Origin 320,240 ; Move the point of orign for all drawing commands to the middle of the screen.
For degrees=0 To 359; Step though all the degrees in a circle (360 in all)
Delay(5); Wait 5 milli secsonds.
; The next line calculates the Y coordinate of the point of the circle using the Sin
; command, and multiplies it by 100 (to get a larger radius, try and change it).
y=Sin(degrees)*100
y=-y ; Invert Y coordinate to represent it properly on screen.
; The next line calculates the X coordinate of the point of the circle using the Cos,
; command, and multiplies it by 100 (to get a larger radius, try and change it).
x=Cos(degrees)*100
Rect x,y,1,1 ; Draw the current point on the circle.
Next ; Give us another angle
MouseWait ; Wait for the mouse.
End ; Terminate the program.

Index