nickyfraggle

04-20-2008, 08:08 PM

Hello,

I am drawing directed graphs using Java.

At the moment, I'm struggling to work out how to space out the circular nodes I am drawing.

I will be drawing on circle in the center, and several circles around it. The number of circles will vary, so my program takes the number of circles to draw as input, and I need the program to decide how to space them out so they don't overlap. (Within reason, obviously if I had 100 nodes to draw it would be impossible to draw them without overlaps!)

I have a class to draw circles, it takes 2 coordinates as input... the x and y of where to start drawing it, and draws the circle.

I just need to know how to write something that will space out the circles drawn depending on how many their are. I think I need some kind of algorithm but I don't know how to do this.

Any help is really appreciated, or links to anywhere that might help.

Here is my circles class incase it helps.

/* DRAW AND LABEL CIRCLES */

//draw circles. needs input of setName and what the circle is to be labelled as. This is elementLabel. Element is the object returned and might not be needed. xy are Coordinates that say where to start drawing the circle

public class draw(Graphics g, String SetName, String elementLabel, element, x, y) {

//draw circle MouseXN and YN are both set to 20 to draw a circle of this size

g.drawOval(x,y,mouseXN,mouseYN);

}

Thanks!

Nicky

I am drawing directed graphs using Java.

At the moment, I'm struggling to work out how to space out the circular nodes I am drawing.

I will be drawing on circle in the center, and several circles around it. The number of circles will vary, so my program takes the number of circles to draw as input, and I need the program to decide how to space them out so they don't overlap. (Within reason, obviously if I had 100 nodes to draw it would be impossible to draw them without overlaps!)

I have a class to draw circles, it takes 2 coordinates as input... the x and y of where to start drawing it, and draws the circle.

I just need to know how to write something that will space out the circles drawn depending on how many their are. I think I need some kind of algorithm but I don't know how to do this.

Any help is really appreciated, or links to anywhere that might help.

Here is my circles class incase it helps.

/* DRAW AND LABEL CIRCLES */

//draw circles. needs input of setName and what the circle is to be labelled as. This is elementLabel. Element is the object returned and might not be needed. xy are Coordinates that say where to start drawing the circle

public class draw(Graphics g, String SetName, String elementLabel, element, x, y) {

//draw circle MouseXN and YN are both set to 20 to draw a circle of this size

g.drawOval(x,y,mouseXN,mouseYN);

}

Thanks!

Nicky