base:trigonometric_functions
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:trigonometric_functions [2015-04-17 04:34] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Trigonometric Functions ====== | ||
+ | okay, well there' | ||
+ | |||
+ | a little pseudo c64 basic code here: | ||
+ | |||
+ | < | ||
+ | c=2*pi/256 | ||
+ | |||
+ | for x=0 to 2*pi step c | ||
+ | |||
+ | value=(sin(x)*128) | ||
+ | |||
+ | if value<0 then value=255-value+1 | ||
+ | |||
+ | poke 8192+q,sine | ||
+ | |||
+ | q=q+1 | ||
+ | |||
+ | next x | ||
+ | </ | ||
+ | |||
+ | the c64 trigonometric functions think in radian, which means that the sin/cos functions repeats themselves after 2*pi. To make that 256 steps we simply make our for/next loop advance at 2*pi/256 steps. | ||
+ | |||
+ | then as we cannot represent numbers <1 on 8 bits we simply multiply the sine value by 128. This means when we will multiply with these lookup sine values we will have to also divide by 128 to get our ' | ||
+ | |||
+ | Remember sin/cos functions results in numbers in the range 1> | ||
+ | |||
+ | However there are no strict rules on how you do your sin/cos tables. You might want 16 bit values and then you have to multiply with 65535 for maximum accuracy, and change the whole precalculation process accordingly. (ie you need 2 8 bit tables with 256 entries). | ||
+ | |||
+ | Also dont forget that the cos/sin functions are almost the same: cos(x)=sin(x+2*pi/ |
base/trigonometric_functions.txt · Last modified: 2015-04-17 04:34 by 127.0.0.1