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

In summary: WarrenHave you...checked to see if you have the proper dependencies installed?- WarrenYes, I installed the dependencies using the cygwin package manager.- WarrenYes, I installed the dependencies using the cygwin package manager.- WarrenIn summary, to graph curves in C++, you can use a program like gnuplot, or use a tool like GNUPlot if you are solely interested in the plotting part of it. 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
  • #1
chaoseverlasting
1,050
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
  • #2
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.
 
  • #3
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:
  • #4
how would you use an open gl library to plot the points?
 
  • #5
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
 
  • #6
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.
 
  • #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.
 
  • #8
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.
 
  • #9
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-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?
 
  • #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 :rofl:

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.
 

1. How do I create a graph in C++ using Dev C++?

To create a graph in C++ using Dev C++, you will need to use a graphics library such as OpenGL or SDL. These libraries provide functions for drawing shapes and lines on the screen. You can also use a third-party library specifically designed for graphing, such as the C++ Graph Library.

2. Can I plot multiple curves on the same graph?

Yes, you can plot multiple curves on the same graph by using different colors or different line styles for each curve. You can also use a legend to identify each curve on the graph.

3. How do I label the axes and add a title to my graph?

To label the axes, you can use the built-in functions for text drawing in your chosen graphics library. For example, you can use the "glutBitmapCharacter" function in OpenGL to draw text on the screen. To add a title, you can use the same method or create a separate text box and position it above the graph.

4. Is it possible to save my graph as an image file?

Yes, it is possible to save your graph as an image file using the functions provided by your graphics library. For example, you can use the "glReadPixels" function in OpenGL to capture the contents of the screen and save it as an image file.

5. Can I customize the appearance of my graph?

Yes, you can customize the appearance of your graph by using different colors, line styles, and fonts. You can also add grid lines, change the scale of the axes, and adjust the size and position of the graph on the screen.

Similar threads

  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
13
Views
3K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
2
Views
377
  • Calculus and Beyond Homework Help
Replies
3
Views
124
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
Back
Top