Note that there are some explanatory texts on larger screens.

plurals
  1. POJava : evenly spread out nodes on the circumference of a circle
    primarykey
    data
    text
    <p>I am working on a simple game in Java, everything goes fine, except I have a situation where I need to evenly spread out nodes on the circumference of a circle.</p> <p>For instance, if there are exactly 4 nodes, then one would go straight to the north, one to the south, one to the east and one to the west. Of course there could be an "offset", i.e., the first node would go slightly away from the north, but the 90 degree angle between two adjacent nodes and the center of circle must be kept.</p> <p>Below is the code I got so far.</p> <pre><code>private void randomizePositions(Set&lt;Node&gt; set) { Random rand = new Random(); for(Node n : set) { n.x = XCENTER + rand.nextDouble() * MINRADIUS; n.y = YCENTER + rand.nextDouble() * MINRADIUS; System.out.println("for node : " + n.lbl + " x = " + n.x + " y = " +n.y); } } </code></pre> <p>Yes, the positions for the nodes in the set are randomized, as shown in the test output:</p> <blockquote> <p>================================================</p> <p>~/Desktop/applet $ javac Graph.java</p> <p>~/Desktop/applet $ appletviewer Graph.java</p> <p>for node : Bird_Food x = 200.97455004134613 y = 205.08056219463253</p> <p>for node : Groceries x = 204.4727596409387 y = 206.26252504672223</p> <p>for node : Fish_Food x = 203.22828002758823 y = 202.30400672172576</p> <p>for node : Pet_Food x = 208.8749664329499 y = 203.43454377979435</p> <p>for node : Dog_Food x = 207.72724954244495 y = 202.9273879239392</p> <p>for node : Cat_Food x = 209.55574149936908 y = 209.61827066724257</p> <p>================================================</p> </blockquote> <p>So I am wondering how could I calculate the positions correctly, given only the total number of nodes in a set? Any idea?</p> <p>Many thanks to the suggestions in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload