Hi all.
I have a question that is doing my head in trying to figure it out.
Heres the scenario. I have a GPS unit and I have a color LCD that I am displaying the heading on....using TinyGPS library for this.

What I want to do is, I have a circle showing N E S W on it, like a compass, but what I want to do is show an indicator on the circle to show the course, i.e. 45 deg,145deg etc.

What I am having trouble with is how to work out where to put a colored pixel to show what way I am heading.

I am also using the GLCDI2C library for the LCD.

So I draw the circle as below:
maxX=160
MaxY=128
45 = the radius

lcd.circle(maxX >> 1, (maxY-15) >> 1, 45);

If I wanted to put a colored pixcel to show 25deg for example, what is the math calculation I need to used to work out where to draw the pixcel?

Actually its easy.
You just have to know how to plot a circle in the first place.
You just plot sin(a) against cos(a) over 360 degrees or 2PI radians depending on your trig functions.

try

plot(x_center_offset + R * sin(a), y_center_offset + R * cos(a));
or draw a line from xCenter, yCenter to the above 2

dont know if its plot(), havent look at your lib, but the principle is correct.
you may have to play with the + or - and swap the sin and cos depending on where your origin is.
Top left, bottom left etc

Thanks heaps for that. I managed to get is SORT of working by that I mean, I see pixels now, but not quit going in the right direction
But I can figure that one out :*

The sin and cos parameter is radians, not degrees. You must convert from degrees to radians.

edit: Using an array to store the sin/cos values (lookup table) has proven to be much faster and simpler to use for me. It works well when accuracy required is a degree or two. A second hand on an analog clock moves 6 degrees per second. Last I checked, that is 16 entries in a lookup table.

Now all you would need to do is compute the quadrant to tell whether to add or subtract each value. That is the sine table, and "backwards" is the cosine. I see a division and a modulus to get the quadrant and the offsets for that quadrant.

I had a little spare time and curiosity. Here is a sketch that prints all the important stuff for a clock. For heading, divide degrees by 6. It is a 25 pixel radius centered at 25,25.

SurferTim:
edit: Using an array to store the sin/cos values (lookup table) has proven to be much faster and simpler to use for me. It works well when accuracy required is a degree or two.

Funny I did something like that few days ago, unfortunately it's slower than calling sin/cos directly, because I put that array in progmem... If array is in ram of course it's much faster

guix:
Funny I did something like that few days ago, unfortunately it's slower than calling sin/cos directly, because I put that array in progmem... If array is in ram of course it's much faster

There is no way those sin/cos functions are faster than a lookup table. It had to have been your coding.

Funny I did something like that few days ago, unfortunately it's slower than calling sin/cos directly, because I put that array in progmem... If array is in ram of course it's much faster

please post your code, as

You can check my sin/cos lookup table [182 bytes] + code here - Arduino Forum -
factor 2.5 faster, and without interpolation even more.

Sorry, I was wrong (and that’s cool!) I don’t know what I did wrong in my previous test but I remember using an array in progmem was a little slower than using sin directly :S

Now…

Chrono 01 - { for (float j = 0.0; j < 360.0; j+=0.1) x = sinDegree1(j); } - 10 calls...
Average (microseconds) : 43075.20
Chrono 02 - { for (float j = 0.0; j < 360.0; j+=0.1) x = sinDegree2(j); } - 10 calls...
Average (microseconds) : 43074.80
Chrono 03 - { for (float j = 0.0; j < 360.0; j+=0.1) x = sinDegree3(j); } - 10 calls...
Average (microseconds) : 589187.63
0.84
0.84
0.83