Thread: Need to draw sine waves using C

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    347

    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. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,526
    Which OS and compiler are you using?

    Are you free to choose and install 3rd party libraries if necessary?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    I am using windows and mingw (gcc). Yes i can install 3rd party libraries provided they are free softwares.
    Last edited by Satya; 05-18-2017 at 03:09 AM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,526
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    awesome thank you.

  6. #6
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    92
    Quote Originally Posted by Satya View Post
    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. #7
    Registered User
    Join Date
    Jun 2015
    Posts
    1,643
    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)
    Need to draw sine waves using C-plot-png

  8. #8
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    Vow eager to learn quickly.

  9. #9
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    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...
    Last edited by MacNilly; 05-20-2017 at 12:15 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 10-30-2013, 11:34 PM
  2. How can I generate simple sound waves in C++?
    By Fernando Aires in forum C++ Programming
    Replies: 2
    Last Post: 11-20-2010, 06:38 AM
  3. Replies: 8
    Last Post: 10-06-2010, 03:24 PM
  4. C Programming for sine waves drawing
    By pattop in forum C Programming
    Replies: 11
    Last Post: 05-13-2004, 03:52 AM
  5. mp3 and waves
    By vhf in forum C Programming
    Replies: 2
    Last Post: 03-26-2002, 09:29 AM

Tags for this Thread