Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075922 Posts in 44152 Topics- by 36120 Members - Latest Member: Royalhandstudios

December 29, 2014, 03:48:33 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Packing points in a circle
Pages: [1]
Print
Author Topic: Packing points in a circle  (Read 1471 times)
BWG
Level 0
**



View Profile WWW Email
« on: July 04, 2012, 07:16:04 AM »

Hi there
Here is a screenshot from my WIP game Neoglobin:



The green and white mess shows the agents that are selected and the red circles show the target positions for those agents after giving a move command.
The challenge was to find a nice distribution for the points in a circle, so they wouldn't all bunch up once they got there.

As you can see from the image, I found a nice solution and I thought it might be of interest to people.

It is based on the packing of sunflower seeds. It's quite interesting actually and relates to fibonacci series and the golden ratio.

More info here.

Anyway, so that's what I did and it worked out rather well. I also wrote a little program in processing to experiment with it:




Code:
size(512, 512);
background(0);
smooth();

for (int i=0; i<600; ++i)
{
  float ang = 1.61803399*2.0*PI*i;
  float r = sqrt(i+1)*10;
  float x = width/2 + sin(ang)*r;
  float y = height/2 + cos(ang)*r;
  ellipse(x, y, 10, 10);
}

Please let me know if you find it useful or if you have ever used it before. I'd be interested to see what other uses can be made for it.

Cheers
Logged

Mattivc
Level 0
***

Level 21 Viking Programmer


View Profile WWW Email
« Reply #1 on: July 05, 2012, 06:10:12 AM »

Looks interesting. I think i will play around with this algorithm a bit later. Thanks for sharing.

Its kinda fun to think about, that some equivalent of this mathematical function lies somewhere within a sunflowers DNA.

Hmm, it might be interesting to use this for the tiles to a turn-based strategy game or something. Something other than grid or hexes Tongue
Logged
mokesmoe
Level 10
*****



View Profile WWW Email
« Reply #2 on: July 05, 2012, 07:21:16 AM »

Hexes would technically be packed better, but this probably fits a variable amount of circles better.


Its kinda fun to think about, that some equivalent of this mathematical function lies somewhere within a sunflowers DNA.
If you have a bunch of points that all repel each other and put them in the middle one at a time this pattern will form naturally. There's nothing fancy in the sunflowers DNA. Sorry to ruin your dreams.
Logged
FibonacciSpaghetti
Level 0
**



View Profile
« Reply #3 on: July 05, 2012, 12:47:16 PM »

Nice, I always loved that illustration of the math, but I've never seen it simply put before. May have to play around with it some time.
Logged
Sir Wolf
Level 0
***


A wolf cub growing up


View Profile
« Reply #4 on: July 05, 2012, 01:02:02 PM »

Its kinda fun to think about, that some equivalent of this mathematical function lies somewhere within a sunflowers DNA.
If you have a bunch of points that all repel each other and put them in the middle one at a time this pattern will form naturally. There's nothing fancy in the sunflowers DNA. Sorry to ruin your dreams.

I thought that was the point - not the specific about sunflower, but the fact that the pattern will form naturally. That a mathematical function describes such a natural pattern. That math is such a natural thing. It indeed is kinda fun to think about.
Logged

"We don't stop playing because we grow old; we grow old because we stop playing."
-George Bernard Shawn
BWG
Level 0
**



View Profile WWW Email
« Reply #5 on: July 05, 2012, 10:49:35 PM »

If you have a bunch of points that all repel each other and put them in the middle one at a time this pattern will form naturally. There's nothing fancy in the sunflowers DNA. Sorry to ruin your dreams.

Yeah. There's a great book from Biran Goodwin called "how the leopard changed its spots" and a much earlier book by D'Arcy Thompson, "on growth and form" (one of my all time fave books).
They both discuss how physical constraints and environmental interaction dictate the shape of a growing organism just as much as DNA. Very interesting stuff.
Logged

Prinsessa
Level 10
*****


Ava Skoog


View Profile WWW Email
« Reply #6 on: July 06, 2012, 11:19:23 AM »

Wow. Thanks for sharing. I have no idea when this could prove useful to me, but it's pretty. Bookmarked it.
Logged

dum mak gam
Vatnsmyrkr, deep sea exploration: devlog
avaskoog @ twitter
avaskoog.se

Maud'Dib Atreides
Level 4
****


Obsessed with space


View Profile WWW Email
« Reply #7 on: July 15, 2012, 02:39:47 PM »

I was reading something somewhere once where this can really come in useful.

Quote
To make a "slime ball" like in GISH is simple, just do like this:

(1) put a number of particles in a circle
(2) connect neighboring particles with Hooke's law damped springs, forming a rubberband
(3) calculate the area of the polygon formed by the particles using this equation
(4) set that area as the slime's rest area
(5) for each loop calculate the slimes new area using the same equation
(6) calculate slime pressure p = k * (area - rest area), where k is a stiffnes coefficient
(7) apply a normal ("inwards" / "outwards") pressure force to each particle pair
(Cool voila, now your slime actsas a peace of jelly!

All sorts of modifications can be made, but this is the gist of the idea. I might have a code sample lying around (BASIC dialect and C dialect), I'll post it if I fall over it.

Cheers,
Mike

http://www.gamedev.net/topic/621866-slime/

The thread was about the physics of a 2D Slime.
Logged

Guy: Give me all of your money.
Chap: You can't talk to me that way, I'M BRITISH!
Guy: Well, You can't talk to me that way, I'm brutish.
Chap: Somebody help me, I'm about to lose 300 pounds!
Guy: Why's that a bad thing?
Chap: I'M BRITISH.
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic