Graphing Curves in C++ w/ Dev C++

  • Context: C/C++ 
  • Thread starter Thread starter chaoseverlasting
  • Start date Start date
  • Tags Tags
    C++ Curves Graphing
Click For Summary

Discussion Overview

The discussion revolves around methods for graphing curves in C++ using the Dev C++ environment. Participants explore various libraries and tools available for plotting, including OpenGL, gnuplot, and other graphical options, while addressing challenges related to installation and usage.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • Some participants suggest using the OpenGL library for plotting graphs, noting that certain versions of Dev C++ come packaged with it.
  • Others propose using gnuplot, recommending that the C++ program output coordinates to a text file for gnuplot to process.
  • Some participants mention using xmgrace for nicer plots, although it lacks support for surface plots.
  • A participant shares their experience of creating a subroutine for plotting data directly to a text document but expresses difficulty with 3D plotting.
  • There are inquiries about using OpenGL and requests for clarification on how to implement it for plotting points.
  • Several participants discuss installation issues with gnuplot on Windows Vista, with some suggesting the use of Cygwin as an alternative environment.
  • Others mention the availability of precompiled binaries for gnuplot in a Win32 environment, questioning the necessity of Cygwin.
  • One participant emphasizes that gnuplot is independent of programming languages and requires data to be formatted correctly in a text file.
  • There are suggestions for reading README files and tutorials for better understanding and usage of gnuplot.
  • A suggestion is made to download the graphic.h header to code custom graphics solutions.

Areas of Agreement / Disagreement

Participants express a variety of approaches to graphing in C++, with no consensus on a single method. Some advocate for OpenGL, while others prefer gnuplot or other tools, indicating multiple competing views.

Contextual Notes

Participants mention various programming environments and libraries, highlighting the dependency on specific setups and the challenges of installation. There are unresolved issues regarding the best practices for plotting and the technical details of using different libraries.

Who May Find This Useful

This discussion may be useful for C++ programmers interested in graphical plotting, particularly those using Dev C++ or facing installation challenges with gnuplot or OpenGL.

chaoseverlasting
Messages
1,051
Reaction score
3
I want to graph curves in C++. I can program them in, find the x,y,z coordinates, but I don't know how to graph them. I am 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?
 
Technology news on Phys.org
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.
 
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 by a moderator:
how would you use an open gl library to plot the points?
 
chaoseverlasting said:
I want to graph curves in C++. I can program them in, find the x,y,z coordinates, but I don't know how to graph them. I am 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?

Use a program like gnuplot. Have your C++ program output the coordinates into a text file, then feed that file into gnuplot
 
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.
 
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.
 
chaoseverlasting said:
how would you use an open gl library to plot the points?

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.
 
Could someone please explain homogeneous coordinates to me? Everything I come across is way way way beyond me...
 
  • #10
Basically what I understand is, that every variable representing a particular axis in n-dimensional 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?
 
  • #11
ranger said:
Use a program like gnuplot. Have your C++ program output the coordinates into a text file, then feed that file into gnuplot


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


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

But i can't 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.
 
  • #12
I just use the cygwin environment. It comes with everything you'd expect of a unix workstation, including gnuplot.

- Warren
 
  • #13
chroot said:
I just use the cygwin environment. It comes with everything you'd expect of a unix workstation, including gnuplot.

- Warren


Ok so i must use cygwin.. I have not been sucsessful usin cygwin on vista yet. Any tips?
 
  • #14
Cygwin installs and runs just fine on Vista. If you have any odd permission problems, just set the envrionment variable NONTSEC.

- Warren
 
  • #15
chroot said:
Cygwin installs and runs just fine on Vista. If you have any odd permission problems, just set the envrionment variable NONTSEC.

- Warren

ok thanx, shall try right now =)
 
  • #16
VISTA state that it could not been installed correctly :S
 
  • #17
Well, I dunno, man. I've been running cygwin on Vista for probably three or four months now with zero problems.

- Warren
 
  • #19
  • #20
malawi_glenn said:
Well iam a newbie and have still not got ANY of those on the link you gave me working:(

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?
 
  • #21
ranger said:
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?


i think i got it work now=) thanx!

Shall read the tutorials on GNUplot homepage. Do you recommend any perticular for a beginner who wants to do 2D and 3D plots with Java, C++ and Fortran?
 
  • #22
gnuplot has nothing to do with any specific language. You just dump out your data to a text file and use gnuplot to plot it.

- Warren
 
  • #23
chroot said:
gnuplot has nothing to do with any specific language. You just dump out your data to a text file and use gnuplot to plot it.

- Warren

yes I know =)
 
  • #24
malawi_glenn said:
i think i got it work now=) thanx!

Shall read the tutorials on GNUplot homepage. Do you recommend any perticular for a beginner who wants to do 2D and 3D plots with Java, C++ and Fortran?

Thou shalt always read README files :smile:

As chroot said. There should be nothing to worry about with regards to any particular programming language. Just have all relevant data points dumped into a text file in right manner so that gnuplot can understand. The most important is "one data point per line".
 
  • #25
download the graphic.h header and code your own.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 13 ·
Replies
13
Views
5K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
69
Views
11K