I made a digital thermometer some time ago using PIC microcontroller. I would like to conncet it to my PC via serial port. I want to write some thing in C# to be able to achive that.

I am having problem in designing the graphics in C#. I have got a meter in .jpg format. I wanto draw the niddle and want the niddle to move according to the temperature. For drawing the nidle - I used 'Graphics.DrawLine Method (Pen, Point, Point)' method where second point is fixed. As I want to keep the lenth of the niddle same every where I have to find a way to calculate how it's 'x' and 'y' coordinates change according to the temperature.

Just wondering any one can cast a light here please. Any tutorial or any thing I can use! Please find attached screen shot.

Thanks in advance.


What you will probably need to do is to get a vector that will tell you the new x,y position. Since the needle is always going to be the same length (I guess) then the only thing that will change is the angle, something like this should do:

radians = (Math.PI / 180) * angle;
double x = Math.Abs(magnitude) * Math.Cos(radians);
double y = Math.Abs(magnitude) * Math.Sin(radians);

And the angle should be scaled: 0 to max value --> 0 to 360 degrees.

Hope it helps

Thanks williamrojas78. Here what I am going to do. For one change in temerature value, the change in angle would be 6 deegree. Yes, the lenth would be the same which is 142 when it would look like the photo above. As I said the second point is fixed which is (
208,232), so the new x position will be 208+lenth*cos6 and y position will be (232-lenth*sin6).

I guess this is right thing to do. I will have to put everything together. Possibly I will need your help again.

Thanks a lot again.