Basic Library
Digital I/O
Analog I/O
Advanced I/O
Time
Math
Trigonometry
Random Numbers
Bits and Bytes
Interrupts
Communication
Standard Library
Servo Motor
Stepper
Liquid Crystal
EEPROM
SPI
I2C (Wire)
SD Card
SD Card (File Control)
Ethernet
Ethernet (Server)
Ethernet (Client)
Firmata
Periodic Operation
Power Save
Clock (RTC)
SoftwareSerial
Utility
Trigonometry
This library provides trigonometry functions, carrying out sin, cos and tan calculations.
sin
Description
Calculates the sine 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 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 of an angle (in radians).
Syntax
tan(rad)
Parameters
rad: The angle in radians (float)
Returns
The tangent of the angle (double)
Example
#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
}
}