Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
Floating point or double precision trigonometry is slow. Look up tables are fast! These functions do a good job approximating sine, cosine, and tangent.
The arguments are in degrees, not radians, and they return (1024 * the trigonometric function).
Call getSin1024(), getCos1024(), or getTan1024() with a degree between 0 and 359 inclusive. If the input degree is out of bounds, the result will be indeterminate.
The sin1024 and tan1024 arrays contain the first 91 elements of the respective functions and can be used directly if you're careful.
Go to the source code of this file.
Functions | |
int16_t | getSin1024 (int16_t degree) |
int16_t | getCos1024 (int16_t degree) |
int32_t | getTan1024 (int16_t degree) |
int32_t | cordicAtan2 (int32_t x, int32_t y) |
CORDIC approximation of arctan. | |
int16_t | getAtan2 (int32_t y, int32_t x) |
Calculate the angle of the line from the origin to (x, y), in degrees. | |
Variables | |
const int16_t | sin1024 [91] |
const uint16_t | tan1024 [91] |
int16_t getSin1024 | ( | int16_t | degree | ) |
Integer sine function
degree | The degree, between 0 and 359 |
int16_t getCos1024 | ( | int16_t | degree | ) |
Integer cosine function
degree | The degree, between 0 and 359 |
int32_t getTan1024 | ( | int16_t | degree | ) |
Integer tangent function
degree | The degree, between 0 and 359 |
int32_t cordicAtan2 | ( | int32_t | x, |
int32_t | y ) |
CORDIC approximation of arctan.
x | The x component |
y | The y component |
int16_t getAtan2 | ( | int32_t | y, |
int32_t | x ) |
Calculate the angle of the line from the origin to (x, y), in degrees.
If both x and y are 0, atan2 is undefined and will return 0.
y | The Y coordinate of the point to calculate the angle to |
x | The X coordinate of the point to calculate the angle to |
|
extern |
A table of the first 91 values of (1024 * sin(x)). Only 91 values are necessary because getSin1024() and getCos1024() handle symmetry to calculate the full wave
|
extern |
A table of the first 91 values of (1024 * tan(x)). Only 91 values are necessary because getTan1024() handles symmetry to calculate the full wave