Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Graphing curves in C++

  1. Jan 3, 2008 #1
    I want to graph curves in C++. I can program them in, find the x,y,z coordinates, but I dont know how to graph them. Im using Dev C++. How would I go about graphing them? Is there some predefined graphics library that I can use or is it more complicated than that?
     
  2. jcsd
  3. Jan 3, 2008 #2

    Eus

    User Avatar

    When I face the same problem like this, I use OpenGL library to plot my graph.
    Certain version of Dev C++ are packaged with OpenGL library.
     
  4. Jan 3, 2008 #3

    HallsofIvy

    User Avatar
    Staff Emeritus
    Science Advisor

    What compiler/programming environment are you using? "Turbo-C++" and MicroSoft "Studio Net" have a "Graphics" object defined for each window you open. If you are not using Windows graphics, you will have to use a "device context". Check your documentation for one of those.
     
    Last edited: Jan 3, 2008
  5. Jan 5, 2008 #4
    how would you use an open gl library to plot the points?
     
  6. Jan 5, 2008 #5

    ranger

    User Avatar
    Gold Member

    Use a program like gnuplot. Have your C++ program output the coordinates into a text file, then feed that file into gnuplot
     
  7. Jan 6, 2008 #6

    t!m

    User Avatar

    I second ranger's suggestion. I use gnuplot for quick plotting, but (at least for xy plot) I prefer xmgrace for nice finished plots. Unfortunately, grace doesn't support surface plots.
     
  8. Jan 8, 2008 #7
    Years ago, for fun I painstakingly wrote out a short subroutine that plots output data directly to a text document using "*". After trying for some time, I gave up trying to do it in 3-D. May be I'll pick it up again and see if I can do it in 3-D.
     
  9. Jan 9, 2008 #8
    even i would suggest using a tool like GNUPlot if you are solely interested in the plotting part of it. If you are interested in the programming part of it, go to gamedev.net and get some primers on OpenGL or DirectX. Either of them is fine. On the other hand, if you use visual studio [you can download a free express version from the microsoft website], you can use the .NET framework and use the 'Graphics' object for plotting graphics. I'd suggest the 2nd method. OpenGL is intended for advanced applications.
     
  10. Jan 9, 2008 #9
    Could someone please explain homogeneous coordinates to me? Everything I come across is way way way beyond me...
     
  11. Jan 9, 2008 #10
    Basically what I understand is, that every variable representing a particular axis in n-dimentional space is divided by a constant w or r or whatever. This constant is actually the ratio by which the axes are contracted or expanded by. To represent a point in this "warped" space of sorts, we need to define n+1 variables. n variables for each of the independent axes in the space and one more variable to define the ratio by which they have been compressed or expanded.... is that right?
     
  12. Jan 18, 2008 #11

    malawi_glenn

    User Avatar
    Science Advisor
    Homework Helper


    How can I install and use GNUplot on M$ Vista?


    I downloaded gp422win32.zip from http://www.gnuplot.info/

    But i cant istall it, it contains a install - file which i can execute.

    How did you guys install it?

    I have GNUoctave since before, and that was easy to install and I run it almost every day.
     
  13. Jan 18, 2008 #12

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    I just use the cygwin environment. It comes with everything you'd expect of a unix workstation, including gnuplot.

    - Warren
     
  14. Jan 18, 2008 #13

    malawi_glenn

    User Avatar
    Science Advisor
    Homework Helper


    Ok so i must use cygwin.. I have not been sucsessful usin cygwin on vista yet. Any tips?
     
  15. Jan 18, 2008 #14

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Cygwin installs and runs just fine on Vista. If you have any odd permission problems, just set the envrionment variable NONTSEC.

    - Warren
     
  16. Jan 18, 2008 #15

    malawi_glenn

    User Avatar
    Science Advisor
    Homework Helper

    ok thanx, shall try right now =)
     
  17. Jan 18, 2008 #16

    malawi_glenn

    User Avatar
    Science Advisor
    Homework Helper

    VISTA state that it could not been installed correctly :S
     
  18. Jan 18, 2008 #17

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Well, I dunno, man. I've been running cygwin on Vista for probably three or four months now with zero problems.

    - Warren
     
  19. Jan 18, 2008 #18

    ranger

    User Avatar
    Gold Member

  20. Jan 18, 2008 #19

    malawi_glenn

    User Avatar
    Science Advisor
    Homework Helper

  21. Jan 18, 2008 #20

    ranger

    User Avatar
    Gold Member

    Well I don't know what you're doing then. I downloaded the latest win32 binaries from the link I gave you and I can successfully run them. Heres the catch, I'm on a linux manchine and the windows version runs perfectly using wine!

    Have you read the file README.Windows? In the directory bin/ there is the main windows executable called wgnuplot.exe. What happens when you try to run it?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Graphing curves in C++
  1. C++ graphing problem (Replies: 15)

  2. Graphs from C++ (Replies: 4)

Loading...