跳转到主要内容

Trigonometry

Trigonometry

This library provides trigonometry functions for carrying out sin, cos and tan calculations.

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
    }
    
}

支持

支持社区

支持社区

在线询问瑞萨电子工程社群的技术人员,快速获得技术支持。
浏览文章

知识库

浏览我们的知识库,获取文章、常见问题解答及其他实用资源。
提交工单

提交工单

需要咨询技术性问题或提供非公开信息吗?