What is Cosine?
The Cosine function, also written as cos or cos(x), reduces the hypotenuse of a right triangle to the projection onto the x-axis. cosine signal waveform with a shape identical to that of a sine wave it’s occurring exactly before one by four(1/4) cycle of the sine wave.
Cos θ = Adjacent side/Hypotenuse
The Cosine graph, and their degree
degree | convert to radians | Cos x |
---|---|---|
0 | 0 | 1 |
30 | π/6 | √3/2 |
45 | π/4 | √1/2 |
60 | π/3 | 1/2 |
90 | π/2 | 0 |
Cos Waveform:
Example 1: Generating Cosine wave
In this example, we will import the required module and set the coordination, after that we will draw vertical and horizontal lines to draw our cosine wave.
Python3
import math import turtle win = turtle.Screen() win.bgcolor( "white" ) # coordinate setting win.setworldcoordinates( 0 , - 2 , 3600 , 2 ) t = turtle.Turtle() # Draw a vertical line t.goto( 0 , 2 ) t.goto( 0 , - 2 ) t.goto( 0 , 0 ) # Draw a Horizontal line t.goto( 3600 , 0 ) t.penup() t.goto( 0 , 1 ) t.pendown() t.pencolor( "blue" ) t.pensize( 4 ) # Generate wave form for x in range ( 3600 ): y = math.cos(math.radians(x)) t.goto(x, y) |
Output:
Contact Us