well I am relatively new to C, Z88dk and trigonometry, but as I may have some kind of pleasure in suffering I decided to develop something using all three of them.. just to keep my mind doing something besides the daily work..
I could make my first C codes and successfully compile them (not without some forum help).. but results were not the expected (as expected:D)..
then I discovered thad results of simple sin() and cos() functions are given in radians .. (I wonder why in first place someone invented that radian thing ).. that would be easy to convert them but adding a multiplication and a division to every function in the loop will kill the already slow performance..
is there any way to tell the thing to calculate in degrees? how will compiler take that in speed terms.. I am thinking of using a look up table for speed purposes in the future but need to develop it easy at first.. I am slow coding, taking it easy,, having fun.. (I am kind of stressing myself now
thanks!!
radians to degreees ..
Yes, it's clear to me you are new to trigonometry. The results of simple sin() and cos() are not in radians; it's the inputs for those functions that are in radians. The outputs of the functions are between -1 and 1.Bolador wrote:then I discovered thad results of simple sin() and cos() functions are given in radians .. (I wonder why in first place someone invented that radian thing ).. that would be easy to convert them but adding a multiplication and a division to every function in the loop will kill the already slow performance..
Conversion between degrees and radians is as simple as miles to kms, or gallons to litres; it's just one multiplication with a fixed number (you'll have to figure it out which ) The problem of course is that your poor z80 machine doesn't have multiplications nor divisions built-in. And if you've had any maths at school you would know that divisions are harder (and slower) to do than multiplications, so don't do divisions in computers if possible.
And yes, all trigonometry is slow on 8 bit computers. That's why people never do them there.
You can write your own functions in C too, but what your sin function would do is to multiply that degrees number with some other number so that it becomes a radian. What else would you have expect? It may make you feel better but the sine of 0.7372773 radians is just the same as the sine of 47.5 degrees. (Yes, degrees have fractions, too )is there any way to tell the thing to calculate in degrees? how will compiler take that in speed terms..
If you only use less than say, 361 different degrees, then you can probably just use a lookup table for speed purposes. Let's assume each result takes 2 bytes, then you'd just need at most, 360*2=720 bytes to store the sines.I am thinking of using a look up table for speed purposes in the future but need to develop it easy at first.. I am slow coding, taking it easy,, having fun.. (I am kind of stressing myself now
thanks!!
Good luck, and that's why most people never really do sines and cosines on 8 bit machines. And don't worry about the speed problem, doing maths is hard on 8 bit processors. It's why sometimes later, that math co-processors were created (I think it's around the time of 80386/80486 machines).
I had a look at lib3d but documentation is so scarce.... I've found the demo too so I'll try to figure out. I think that not to reinvent the wheel is a good advice!!!..stefano wrote:You can use lib3d, it has a lookup table already prepared.
See clock.c
I what to move certain vector by an angle, that is: vector x0,y0 x1,y1 to a new position where x1,y1 was moved a known angle from it's current position. Keeping x0,y0 in the original position need to know the new x1,y1. (all in 2D)
Regards