Python_2  1.0
Classes | Functions | Variables
_08a_pack_circles Namespace Reference

Packing circles is a method for filling a rectangle with non-intersecting circles of different sizes. More...

Classes

class  Timer
 

Functions

def randomPoint (xmax, ymax)
 
def randomRadius (x, y, xmax, ymax, rmin, rmax)
 
def distance2Circles (p, l)
 
def draw ()
 
def animation (p)
 
def main ()
 

Variables

int wsize = 1000
 Canvas size. More...
 
 task = None
 Drawing process. More...
 
list circles = []
 List of circles given as tuples (x,y,r). More...
 

Detailed Description

Packing circles is a method for filling a rectangle with non-intersecting circles of different sizes.

A simple method consists in generating random points into the rectangle and computing the distance \(d\) to the closest circle.

Author
Paulo Roma Cavalcanti
Date
25/04/2018

Function Documentation

◆ animation()

def _08a_pack_circles.animation (   p)
Toggle animation state.

Referenced by main().

◆ distance2Circles()

def _08a_pack_circles.distance2Circles (   p,
  l 
)
Return the distance between a point p given as a tuple
(x,y), and the closest circle among all circles kept in 
the list l. Each circle in l is represented as a tuple 
(x,y,r), where x,y are the coordinates of its center
and r is the radius. 
If p is inside a circle of radius r, this function
returns 0. If l is empty, it returns a big number.

Referenced by draw().

◆ draw()

def _08a_pack_circles.draw ( )
Create a random circle and draw it,
if its radius is greater than 2.

References distance2Circles(), randomPoint(), and randomRadius().

◆ main()

def _08a_pack_circles.main ( )
Create a canvas and keep drawing new circles at 
a rate of approximately 30 circles per second.

References animation().

◆ randomPoint()

def _08a_pack_circles.randomPoint (   xmax,
  ymax 
)
Return a tuple (x,y) representing a random point,
such as 0 <= x <= xmax and 0 <= y <= ymax.

Referenced by draw().

◆ randomRadius()

def _08a_pack_circles.randomRadius (   x,
  y,
  xmax,
  ymax,
  rmin,
  rmax 
)
Return a random radius in the range [rmin, rmax], 
so a circle centered at (x,y) is contained into the
rectangle given by 0 <= x <= xmax and 0 <= y <= ymax.

Referenced by draw().

Variable Documentation

◆ circles

list _08a_pack_circles.circles = []

List of circles given as tuples (x,y,r).

◆ task

_08a_pack_circles.task = None

Drawing process.

◆ wsize

int _08a_pack_circles.wsize = 1000

Canvas size.