Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com graphs drawing using coordinates (need to space out what I draw)

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 04-20-2008, 09:08 PM PM User | #1 nickyfraggle Regular Coder   Join Date: Mar 2006 Posts: 198 Thanks: 27 Thanked 2 Times in 2 Posts graphs drawing using coordinates (need to space out what I draw) 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. Code: ```/* 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
04-21-2008, 06:13 AM   PM User | #2
shyam
Senior Coder

Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
Quote:
 Originally Posted by nickyfraggle 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.
the algorithms are pretty simple if you understand your math and trigonometry right...
assuming
n is the number of circles you want to draw
(x, y) is the center of the central circle which has a radius of cr
dOff is the average space that you want between individual surrounding circles
r is the radius of the surrounding circles

the radius of the external circle on which the surrounding circles will be positioned can be calculated as

Code:
`R = ((n * r) + ((n-1) * dOff)) / (2 * Math.PI);`
now that you know the value of R you can start calculating the position of the individual surrounding circles

Code:
`delta = (2 * Math.PI) / n;`
using delta as the increment you can get the polar coordinates for centers for each of the surrounding circles like (R, delta), (R, 2*delta), (R, 3*delta)...you convert the polar coordinates to cartesian coordinates and add offsets for the central circles radius and draw the surrounding circles
__________________
You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 07:27 AM.