Talk:Design ideas

Rotating by random angle: Couldn't you do this?

Important page, but not easy to find!
I don't think this page is linked to from anywhere prominent. It would be helpful to newbies to add a link to it on the Main Page. I sort of found it by chance.

A Table of Contents for the whole site would be useful.

--Deking101 21:50, 14 August 2007 (PDT)

(I just found a link to it on the CFDG HOWTO page.--Don 21:56, 14 August 2007 (PDT) )

Random rotation
The above code for random rotation is not uniform, as if X is the random variable that is the number of times the first rule for RandomRotate is called before the "bail out" rule is called, then X is distributed according to a Geometric distribution with p=1/361. If Y=X mod 360, so that Y is the apparent angle of rotation, then Y is a rescaled version of X restricted to [0;360), which varies in probability for various outcomes from p(Y=0)=0.00439 to p(Y=359)=0.00162. In effect, small angles are far more likely than large angles.

However, things are not all bad - you can modify the above so that the likely angles are intermixed with unlikely angles. Due to a nice property of the golden ratio (google "leaf placement golden ratio") this can be done by having a rotation of 360/1.6180339=222.49 degrees instead of 1 degree. I tend to use either 222, 223 or 137, and refer to these as "churn" rules. The angle 222 is easy to remember and type, but will only produce even angles. Both 137 and 223 produce similar distributions (clockwise vs counterclockwise) and cover all angles (since both are coprime to 360 .. prime actually) and the probability of being inside any 10 degree band varies between 2.5% and 3%, giving a reasonable approximation to a uniformly distributed angle. It is not as efficient in terms of execution-time as the cascade approach, so which you use depends on where it is being used in the design.

Hybrid approaches are also possible, such as using as cascade of "churn" rules with different angles.