90 lines
1.8 KiB
C
Raw Normal View History

2023-11-02 15:13:39 +01:00
#pragma once
2021-01-29 12:31:58 +01:00
//
// FILE: FastTrig.h
// AUTHOR: Rob Tillaart
2023-11-02 15:13:39 +01:00
// VERSION: 0.3.3
2021-01-29 12:31:58 +01:00
// PURPOSE: Arduino library for a faster approximation of sin() and cos()
// DATE: 2011-08-18
// URL: https://github.com/RobTillaart/FastTrig
// https://forum.arduino.cc/index.php?topic=69723.0
2021-04-25 19:56:44 +02:00
2021-01-29 12:31:58 +01:00
2022-12-03 12:59:56 +01:00
#ifdef ESP_PLATFORM
#include <math.h>
#include <stdint.h>
#include <stdbool.h>
#else
2021-01-29 12:31:58 +01:00
#include "Arduino.h"
2022-12-03 12:59:56 +01:00
#endif
2021-01-29 12:31:58 +01:00
2022-11-07 10:20:54 +01:00
2023-11-02 15:13:39 +01:00
#define FAST_TRIG_LIB_VERSION (F("0.3.3"))
2022-04-15 16:43:05 +02:00
2022-12-03 12:59:56 +01:00
#ifdef __cplusplus
extern "C"
{
#endif
extern uint16_t sinTable16[];
extern uint8_t sinTable8[];
2021-01-29 12:31:58 +01:00
2021-12-18 13:14:58 +01:00
2022-12-17 15:04:42 +01:00
///////////////////////////////////////////////////////
//
2023-11-02 15:13:39 +01:00
// GONIO INT EXPERIMENTAL
2022-12-17 15:04:42 +01:00
//
int isin256(uint32_t v);
int icos256(uint32_t v);
// calculate both in one call.
2022-12-22 13:44:04 +01:00
void isincos256(uint32_t v, int *si, int *co);
2022-12-17 15:04:42 +01:00
2021-01-29 12:31:58 +01:00
///////////////////////////////////////////////////////
//
2023-11-02 15:13:39 +01:00
// GONIO LOOKUP
2021-01-29 12:31:58 +01:00
//
2022-04-15 16:43:05 +02:00
float isin(float f);
float icos(float x);
2022-12-17 15:04:42 +01:00
// calculate both in one call.
2022-12-22 13:44:04 +01:00
void isincos(float v, float *si, float *co);
2022-04-15 16:43:05 +02:00
float itan(float f);
2022-12-03 12:59:56 +01:00
// 0 returns NAN but we have a icot(x) cotangent.
2022-04-15 16:43:05 +02:00
float icot(float f);
2021-08-10 21:24:22 +02:00
2021-01-29 12:31:58 +01:00
///////////////////////////////////////////////////////
//
2022-12-03 12:59:56 +01:00
// INVERSE GONIO LOOKUP
2021-01-29 12:31:58 +01:00
//
2022-04-15 16:43:05 +02:00
float iasin(float f);
float iacos(float f);
2022-12-08 17:32:53 +01:00
// PLACEHOLDER (might be obsolete due to atanFast() formula.
2022-04-15 16:43:05 +02:00
float iatan(float f);
2022-12-08 17:32:53 +01:00
// fast atan() formula, in fact a modified Taylor expansion
// input = -1 .. 1
float atanFast(float f);
inline float atanHelper(float x);
// atan2Fast() folds and mirrors => calls atanFast() + offset.
float atan2Fast(float y, float x);
2021-12-18 13:14:58 +01:00
2022-12-18 16:36:10 +01:00
///////////////////////////////////////////////////////
//
// HYPOT
// related but not strict gonio.
//
// hypotFast() formula for faster hypot() at the price of accuracy
// experimental!
float hypotFast(float x, float y);
2022-12-03 12:59:56 +01:00
#ifdef __cplusplus
}
#endif
// -- END OF FILE --