Diferencia entre revisiones de «cos()»

De ArduWiki
Saltar a: navegación, buscar
(Ejemplo)
(Retornos)
 
(No se muestran 3 ediciones intermedias del mismo usuario)
Línea 11: Línea 11:
  
 
== Retornos ==
 
== Retornos ==
El coseno del ángulo [[float]].
+
El coseno del ángulo [[float]]. Valores entre -1 y +1.
  
 
== Advertencias ==
 
== Advertencias ==
Nada.
+
* El angulo debe estar expresado en radianes entre 0 y [[PI|TWO_PI]].
  
== Ejemplo ==
+
== Ejemplo 1 ==
<pre>
+
<syntaxhighlight lang="c++">
 +
void setup(){
 +
  Serial.begin(115200);
 +
  Serial.println(cos(0), 3);            //1.000
 +
  Serial.println(cos(HALF_PI/2), 3);    //0.707
 +
  Serial.println(cos(HALF_PI), 3);      //0.000
 +
  Serial.println(cos(PI), 3);          //-1.000
 +
  Serial.println(cos(PI+HALF_PI), 3);  //0.000
 +
  Serial.println(cos(TWO_PI), 3);}      //1.000
 +
void loop(){
 +
  //Nada
 +
}
 +
</syntaxhighlight>
 +
 
 +
== Ejemplo 2 ==
 +
<syntaxhighlight lang="c++">
 
void setup(){
 
void setup(){
 
   Serial.begin(9600);
 
   Serial.begin(9600);
Línea 26: Línea 41:
 
   }
 
   }
 
}
 
}
</pre>
+
</syntaxhighlight>
  
 
== Vea también ==
 
== Vea también ==
Línea 39: Línea 54:
 
* [https://www.arduino.cc/reference/es/language/functions/time/millis/ Guia de referencia de Arduino]
 
* [https://www.arduino.cc/reference/es/language/functions/time/millis/ Guia de referencia de Arduino]
  
[[Category:Funciones]]
+
[[Category:Funciones trigonometricas]]

Revisión actual del 18:39 24 jun 2019

Descripción

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

Sintaxis

cos(rad);

Parámetros

rad
el ángulo en radianes float

Retornos

El coseno del ángulo float. Valores entre -1 y +1.

Advertencias

  • El angulo debe estar expresado en radianes entre 0 y TWO_PI.

Ejemplo 1

void setup(){
   Serial.begin(115200);
   Serial.println(cos(0), 3);            //1.000
   Serial.println(cos(HALF_PI/2), 3);    //0.707
   Serial.println(cos(HALF_PI), 3);      //0.000
   Serial.println(cos(PI), 3);           //-1.000
   Serial.println(cos(PI+HALF_PI), 3);   //0.000
   Serial.println(cos(TWO_PI), 3);}      //1.000
void loop(){
   //Nada
}

Ejemplo 2

void setup(){
   Serial.begin(9600);
}
void loop(){
   for (float n=0; n<TWO_PI; n+=0.01){
      Serial.println(cos(n));
   }
}

Vea también

Referencias