Treeviz 0.37 2010-10-17

ch.randelshofer.tree.circlemap
Class Circles

java.lang.Object
  extended by ch.randelshofer.tree.circlemap.Circles

public class Circles
extends java.lang.Object

Utility functions for Circle objects.

Author:
Werner Randelshofer  @version 1.2 2008-07-05 Method boundingCircle treats now 3 circles as a special case.
1.1 2008-06-12 Make pair.innerSoddyRadius smaller every time we fail to insert a circle at it.
1.0 Jan 17, 2008 Created.

Method Summary
static java.awt.geom.Rectangle2D.Double boundingBox(java.util.ArrayList<Circle> circles)
          Calculate the bounding box of all circles.
static Circle boundingCircle(java.util.ArrayList<Circle> circles)
          Calculate the bounding circle of all circles.
static double circumradius(double ra, double rb, double rc)
          Computes the circumradius of the reference triangle for three tightly packed circles.
static double innerSoddyRadius(double ra, double rb, double rc)
          Computes the radius of the inner soddy circle for three tightly packed circles.
static void main(java.lang.String[] arg)
           
static Circle outerSoddyCircle(Circle circleA, Circle circleB, Circle circleC)
          Computes the outer soddy circle for three tightly packed circles.
static double outerSoddyRadius(double ra, double rb, double rc)
          Computes the radius of the outer soddy circle for three tightly packed circles.
static void pairPack(java.util.ArrayList<Circle> circles)
          Packs circles closely together into a circle around the center of the coordinate system by creating a list of already packed pairs of circles.
static void phyllotacticPack(java.util.ArrayList<Circle> circles)
          Packs circles closely together into a circle around the center of the coordinate system using a phyllotactic pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

boundingBox

public static java.awt.geom.Rectangle2D.Double boundingBox(java.util.ArrayList<Circle> circles)
Calculate the bounding box of all circles.

Parameters:
circles -
Returns:
the bounding box.

boundingCircle

public static Circle boundingCircle(java.util.ArrayList<Circle> circles)
Calculate the bounding circle of all circles.

Parameters:
circles -
Returns:
the bounding circle.

phyllotacticPack

public static void phyllotacticPack(java.util.ArrayList<Circle> circles)
Packs circles closely together into a circle around the center of the coordinate system using a phyllotactic pattern.

Phyllotactic patterns occur in nature, for example in the seeds of a sunflower.

In a phyllotactic pattern, the polar coordinates for the nth object are:

 radius = rc * Math.sqrt(i+1),
 ra = (i+1) * 137.5°
 
Where rc is the spacing constant, and 137.5° is the angular constant.

The current implementation yields only good results, if all circles are of the same size.

Parameters:
circles -

pairPack

public static void pairPack(java.util.ArrayList<Circle> circles)
Packs circles closely together into a circle around the center of the coordinate system by creating a list of already packed pairs of circles.

The following algorithm is used:

  1. Sort the circles from largest to smallest.
  2. Arrange the first three circles in a triangle with corners A, B, C.
  3. Create a list of 6 pairs for the 3 edges of the triangle: A-B, B-C, C-A, B-A, C-B, A-C
  4. For each remaining circle: try out all possible triangle arrangements with the available pairs. Among the arrangements for which the circle does not overlap with existing circles, choose the one, which places the circle closest to the center of the first triangle. Add 4 pairs for the two new triangle edges we have found to the pair list.

Parameters:
circles -

innerSoddyRadius

public static double innerSoddyRadius(double ra,
                                      double rb,
                                      double rc)
Computes the radius of the inner soddy circle for three tightly packed circles.

Parameters:
ra - Radius of circle A
rb - Radius of circle B
rc - Radius of circle C
Returns:
radius of the inner soddy circle

outerSoddyRadius

public static double outerSoddyRadius(double ra,
                                      double rb,
                                      double rc)
Computes the radius of the outer soddy circle for three tightly packed circles.

Parameters:
ra - Radius of circle A
rb - Radius of circle B
rc - Radius of circle C
Returns:
radius of the outer soddy circle

circumradius

public static double circumradius(double ra,
                                  double rb,
                                  double rc)
Computes the circumradius of the reference triangle for three tightly packed circles.

Parameters:
ra - Radius of circle A
rb - Radius of circle B
rc - Radius of circle C
Returns:
circumradius of the reference triangle.

outerSoddyCircle

public static Circle outerSoddyCircle(Circle circleA,
                                      Circle circleB,
                                      Circle circleC)
Computes the outer soddy circle for three tightly packed circles.

Parameters:
circleA - Circle ra
circleB - Circle rb
circleC - Circle rc
Returns:
Outer soddy circle. The Outer soddy circle has a radius of 0, if there is no solution, that is, if the outer soddy circle is a straight line.

main

public static void main(java.lang.String[] arg)

Copyright 2007-2008 (c) Werner Randelshofer.
All rights reserved.