cos()

Sintaxis

cos(rad)

Descripción

Calcula el coseno de un ángulo (en radianes). El resultado está comprendido entre -1 y 1.

Parámetros

  • rad: el ángulo en radianes (float)

Retornos

  • El coseno del ángulo ("double")

Ejemplo

void setup() { Serial.begin(9600); for (int angle = 0; angle <= 180; angle += 15) { float angle_rad = angle * M_PI / 180; float cos_result = cos(angle_rad); Serial.print("cos("); Serial.print(angle); Serial.print("°) = "); Serial.println(cos_result); } } void loop() { }

The result in Serial Monitor:

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
cos(0°) = 1.00 cos(15°) = 0.97 cos(30°) = 0.87 cos(45°) = 0.71 cos(60°) = 0.50 cos(75°) = 0.26 cos(90°) = -0.00 cos(105°) = -0.26 cos(120°) = -0.50 cos(135°) = -0.71 cos(150°) = -0.87 cos(165°) = -0.97 cos(180°) = -1.00
Ln 11, Col 1
Arduino Uno on COM15
2

ARDUINO BUY RECOMMENDATION

Arduino UNO R3
Arduino Starter Kit
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables .

※ OUR MESSAGES