# Thread: Need to draw sine waves using C

1. ## Need to draw sine waves using C

I want to draw lot of electrical signals like sine wave with phase shifts, cos wave and 3 phase currents and voltages. i want to use C to draw and visualize this graphs. i know it has been asked several times but please tell me how should i proceed. I read that openGL is available and also C supports graphics. which one shall i use? I don't want to spend too much time on C code but the analysis of this waveform and also to present to someone. please help.

2. Which OS and compiler are you using?

Are you free to choose and install 3rd party libraries if necessary?

3. I am using windows and mingw (gcc). Yes i can install 3rd party libraries provided they are free softwares.

4. If you want to avoid the discomfort of talking directly to windows GDI, then perhaps one of these
Cairo (graphics) - Wikipedia
Direct2D - Wikipedia
Skia Graphics Engine - Wikipedia

Study a few examples of each, and see which is easiest for you to plot lines, points, curves or whatever.

5. awesome thank you.

6. Originally Posted by Satya
I want to draw lot of electrical signals like sine wave with phase shifts, cos wave and 3 phase currents and voltages. i want to use C to draw and visualize this graphs. i know it has been asked several times but please tell me how should i proceed. I read that openGL is available and also C supports graphics. which one shall i use? I don't want to spend too much time on C code but the analysis of this waveform and also to present to someone. please help.
Please take a look at this question:

Graphics library in C - Stack Overflow

7. You could use gnuplot.

Example:
Code:
```set xrange [0:6.28]
set xtics ("0" 0, "0.5{/Symbol p}" pi/2, "{/Symbol p}" pi, \
"1.5{/Symbol p}" 1.5*pi, "2{/Symbol p}" 2*pi)
set xzeroaxis
set yrange [-2:2]
plot sin(x),cos(x),tan(x)```

8. Vow eager to learn quickly.

9. I recommend Cairo, I have used both the native C library and the Python interface. Very good, IMO. +1 for Cairo!

I actually once got quite into it, and ended up writing a (very simple) graphing class in Python, which allowed the user to graph different kinds of functions (rectangular, polar, and parametric -- defined in Python, of course), that were then ultimately superimposed and rendered to a .PNG image.

I'll be glad to post the code if anyone is interested...