org.cybertory.MSS
Class PolygonFactory

java.lang.Object
  extended byorg.cybertory.MSS.PolygonFactory

public class PolygonFactory
extends java.lang.Object

An object instance of PolygonFactory is a factory to create polygons of a specified degree of variability. The method createPolygon(float) produces a Polygon whose approximate radius is specified in the call, centered at (0,0). Pseudo-random polygons serve as polygons. The formulae for calculating polar coordinates (rn, Θn) representing the location of Vertexn with the polygon centered at (0,0) are shown below. Reference to variables passed into the constructor or method createPolygon are in boldface.


(RADIUS)

rn = (1+dn) * R
d0 = v / (1+s)
dn = v + dn-1*s / (1+s)

where:

R
is refRadius (the reference radius), passed into the createPolygon(float) method
dn
is the fractional deviation from the reference radius for vertex n
v
is a random number from a gaussian distribution whose standard deviation is specified by radiusVariability, but with a floor (minimum value) of -0.8. A different value is generated for the calculation of each vertex.
dn-1
is the fractional deviation of the previously calculated vertex
s
radiusStickiness, how much to weight the previous vertex radius in the calculation of the current radius; this number must be >= 0 and is usually much less than 1.

(ANGLE)

Θ0 = 0
Θn = Θn-1 + (1 + v) * 2*Π/n

where:

Θn
is the angle of vertex n in radians
Θn-1
is the angle of the previous vertex
v
is a random number from a gaussian distribution whose standard deviation is specified by angleVariability, but with a floor (minimum value) of -0.9. A different value is generated for the calculation of each vertex.
n
is the approxNumVertices (approximate number of vertices)


Constructor Summary
PolygonFactory(java.util.Random rand, float radiusVariability, float radiusStickiness, int approxNumVertices, float angleVariability)
          Constructor: See class documentation for formulas to see how these parameters are used.
PolygonFactory(java.util.Random rand, int variabilityLevel)
          Constructor with pre-packaged variability parameters.
 
Method Summary
 void addAngleBias(AngleBias bias)
           
 java.awt.Polygon createPolygon()
          Creates a polygon with the default radius (which must have been set up with a previous call to setDefaultRadius(float).
 java.awt.Polygon createPolygon(float refRadius)
          Creates a polygon with the specified (approximate) radius.
 org.cybertory.MSS.PolarCoords[] createPolygonPolar()
           
 org.cybertory.MSS.PolarCoords[] createPolygonPolar(float refRadius)
           
 void setDefaultRadius(float defaultRadius)
          Set up a default radius for use with calls to the createPolygon() without a radius parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PolygonFactory

public PolygonFactory(java.util.Random rand,
                      float radiusVariability,
                      float radiusStickiness,
                      int approxNumVertices,
                      float angleVariability)
Constructor: See class documentation for formulas to see how these parameters are used.

Parameters:
rand - a random number generator object
radiusVariability - a measure of polygon radius variability
radiusStickiness - how much the radius of one vertex effects the radius of the subsequent vertex
approxNumVertices - the approximate number of vertices in the polygon polygon (affects smoothness)
angleVariability - a measure of variability of angles between vertices

PolygonFactory

public PolygonFactory(java.util.Random rand,
                      int variabilityLevel)
Constructor with pre-packaged variability parameters.

Parameters:
variabilityLevel - one of the following constants:
Method Detail

addAngleBias

public void addAngleBias(AngleBias bias)

setDefaultRadius

public void setDefaultRadius(float defaultRadius)
Set up a default radius for use with calls to the createPolygon() without a radius parameter.

Parameters:
defaultRadius - default radius in pixels

createPolygonPolar

public org.cybertory.MSS.PolarCoords[] createPolygonPolar()

createPolygonPolar

public org.cybertory.MSS.PolarCoords[] createPolygonPolar(float refRadius)

createPolygon

public java.awt.Polygon createPolygon()
Creates a polygon with the default radius (which must have been set up with a previous call to setDefaultRadius(float).

Returns:
a Polygon object for the polygon.

createPolygon

public java.awt.Polygon createPolygon(float refRadius)
Creates a polygon with the specified (approximate) radius.

Parameters:
refRadius - the reference (approximate) radius of the polygon
Returns:
a Polygon object for the polygon.