Plotting points by coordinates.

Hello everyone,

I'm working on a shortest-route finder program and I've gotten most of it to work. However, to verify my results, there is currently a tedious amount of manual drawing and calculating required because I can't visually inspect my results as I don't know how to plot them using C++. I've looked around but found mostly math function plotters which only accept an X-range and a Y-function as input, while I simply wish to plot them based on X and Y coordinates. Is there such a function, or a library to support this?

The minimal requirements are very limited: as long as I can plot the points, I'm completely satisfied. If I can choose colours for separate points, that would also help me. In the best scenario, I'd also love a way to visually "connect the dots" so I can plot the actual routes rather than just the points it consists of.

If anyone can point me towards a library or built-in function that can help me with this, I'd be incredibly happy.

Thanks in advance.
What do you want to plot them on?

Graphics in C++ is not usually very trivial. You might want to play with a wish interpreter instead, and use a canvas object to plot your stuff. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package require Tk
canvas .c -bg white
pack .c -fill both -expand yes

# plot from (10 10) to (50 50) using an orange color
.c create line 10 10 50 50 -fill #FF5500

# here's a list of points we'll plot in green
set pts {
  100  10
  200  10
  100 110
  200 110
  }
.c create line $pts -fill darkgreen

http://wiki.tcl.tk/
http://www.tcl.tk/man/tcl8.5/TkCmd/canvas.htm

Hope this helps.
I sometimes use GraphVis : http://www.graphviz.org/

It accepts a text description file like this:

digraph graphname
{
"*" -> "+";
"+" -> "x";
"+" -> "1";
"*" -> "^";
"^" -> "y";
"^" -> "2";
}


It is displayed using dotty:

user$ dotty output.dot
Last edited on
Hello,

Thank you both for your answers. Duoas' option seems the easiest, so I'll read up on that and see if it's sufficient. I'll keep GraphViz in mind for more advanced uses, in case I need it.

I'll post back here to let you know how it worked out!
Topic archived. No new replies allowed.