views:

122

answers:

3

Is there a C++ graphing library that can display visual graphs (such as hyperbolas and parabolas and linear equations) based on the equation it is given and that is cross platform? Or am I just asking for too much...

+1  A: 

Have a look at QT. It might have some graph capabilities. And there is gnuplot. It's very extensive, so it might be a bit too complex for your needs though. It is cross-platform and there is a C++ API.

Bozhidar Batsov
Qt does not have one of it's own. However, there is an open source library at http://qwt.sourceforge.net/ that is very complete and easy to use. For 3d charts, look at http://qwtplot3d.sourceforge.net/.
photo_tom
+1  A: 

Let's take your question step by step.

  1. "based on the equation [that] it is given" This would require you to write an expression parser; C++ cannot interpret equations "on the fly" without you writing a procedure to do so. For this, I recommend you look at Bison (go straight to the example RPN calc to get the idea).

  2. For the libraries, you can get any GUI toolkit for C++; there are dozens; the recommendation for QT is probably the most honest one. Check also Wikipedia. You need any toolkit which will provide you with a canvas where you can paint or render lines or splines. This is not trivial, but also not difficult.

Your program would probably work as follows:

  1. Get a mathematical expression (or the parameters for a known function; like the axes and center of an ellipse).
  2. Generate a set of points (this is done with a loop in C++)
  3. Pack those points and sent them to the paint or render method of your toolkit (with the appropriate scaling/normalization

Again, this is not trivial but not difficult either.

You are reinventing the wheel, but I commend you for that.

Cheers,

J.

Arrieta
A: 

If all you are interested in is the final output, rather than the programming side of things; you might want to try interfacing with something like gnuplot ( http://www.gnuplot.info/ ).

If you're interested in more, I'd recommend looking at their 'Links' page. This offers a bunch of either interface libraries and re-implementations (mostly for non-C languages from what I can see).

Hope that helps.

Grey