Created
December 31, 2019 18:53
-
-
Save captnlarzuk/87e7b6765628a4aec4ac8a8bd22e5e9d to your computer and use it in GitHub Desktop.
Bash script which generates C code array of unsigned trigonometry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script generates a C code wchich creates | |
# an unsigned int array of pre calculated cos/sin... | |
# It's crappy, but you can tweak it. | |
export LC_NUMERIC="en_US.UTF-8" # use . instead of , | |
# Increments between 0 ans 2pi | |
RESOLUTION=0.01 | |
# Max value | |
MAX=1024 | |
O=0; | |
STRING="" | |
for i in `seq 0 $RESOLUTION 1`; | |
do N=$(echo "scale=5; b=$MAX/2; c($i*4*a(1)*2 )*b+b" | bc -l | cut -d"." -f1 ); | |
STRING=$(echo -e "$STRING$N,\t") | |
O=$(($O+1)) | |
done | |
# Remove last coma from the string list | |
CLEANSTRING=$(echo $STRING |sed 's/,\([^,]*\)$/ \1/') | |
# Output the code | |
echo "uint8_t COS[$O]={ $CLEANSTRING };" | fold -w80 -s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment