Trigonometry

This library provides trigonometry functions, carrying out sin, cos and tan calculations. Other than this, you can use the operations provided by the C standard math library, such as acos, asin, atan, exp, and log.

sin

Description
Calculates the sine (sin) of an angle (in radians).
Syntax
sin(rad)
Parameters
rad: The angle in radians (float)
Returns
The sine of the angle (double)

cos

Description
Calculates the cosine (cos) of an angle (in radians).
Syntax
cos(rad)
Parameters
rad: The angle in radians (float)
Returns
The cosine of the angle (double)

tan

Description
Calculates the tangent (tan) of an angle (in radians).
Syntax
tan(rad)
Parameters
rad: The angle in radians (float)
Returns
The tangent of the angle (double)

Sample Program


#include <Arduino.h>
void setup(){
    Serial.begin(9600);
}
 
void loop(){
     // print labels 
    Serial.print("RAD");       // prints a label
    Serial.print("\t");        // prints a tab
    
    Serial.print("SIN");  
    Serial.print("\t");      
  
    Serial.print("COS"); 
    Serial.print("\t");   
  
    Serial.print("TAN");
    Serial.print("\t");
    Serial.println("");
     
    for(float x=0; x< PI; x+=0.01){    // only part of the ASCII chart, change to suit
  
    // print it out in many formats:
        Serial.print(x);       // print as an ASCII-encoded decimal - same as "DEC"
        Serial.print("\t");    // prints a tab
  
        Serial.print(sin(x));  // print as an ASCII-encoded decimal
        Serial.print("\t");    // prints a tab
  
        Serial.print(cos(x));  // print as an ASCII-encoded hexadecimal
        Serial.print("\t");    // prints a tab
  
        Serial.print(tan(x));  // print as an ASCII-encoded octal
        Serial.print("\t");    // prints a tab
  
        Serial.println("");      // prints another carriage return
        delay(100);            // delay 100 milliseconds
    }
  
}