0

If I have a set of nodes with ids and pointers to other nodes like this:

1 -> 2
2 -> 4
2 -> 3
3 -> 4
5 -> 1
...

How can I display this graph in 2 dimensions (on an x-y plane)? Is there a way to project these 1d points into 2d? I'm looking looking for someone to point me to an algorithm that I can use.

Thanks in advance.

2
  • 1
    What sort of 2D view do you want? Is there some particular property you want the 2D view to show off? Commented Oct 27, 2014 at 19:03
  • @templatetypedef I'm just looking to make all of the edges visible. If I keep them in 1-d, they will only look like one big edge connecting them all. This is why I need another dimension. The other details don't really matter. Commented Oct 27, 2014 at 19:05

1 Answer 1

1

See PolygonFactory.createPolygon

You can then use the points in the Polygon return value and draw the connections you want.

Sign up to request clarification or add additional context in comments.

4 Comments

The thing is that I want the nodes that are one step away to be next to each other. It looks like this just makes a shape out of the points that approaches a circle.
Like I said (or intended to say) rather than using the actual Polygon as a polygon, just use the points that are generated and draw your edges in a loop based on your data using Graphics.drawLine(x1,y1,x2,y2)
@Josh In the general case, this is geometrically impossible, without reducing every point to the same, single point... Imagine a fully connected network of 8 nodes. And unless you know something specific about the kind of connections your network is always going to have, there's no simple algorithm for this
Oh, I thought I remembered GNUPlot being about to do this. Maybe I'm thinking of similar functionality.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.