Product(s): | OpenBuildings Generative Components | ||
Version(s): | 10.06.03.04 | ||
Environment: | N\A |
Prime numbers can be fun to play with. As per Wikipedia, a prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. If all the prime numbers starting from 2 are plotted in polar coordinate system where both the radial coordinate and the angular coordinate are equal to the prime number, we would find an emergence of a beautiful spiral pattern. In the below section we will see how we can create such a pattern in Generative Components with a little help of GC scripting.
We will create a list containing all the prime numbers in first n numbers. For this, we will use the "Function" node and create a custom function. The script is as follows.
function (int n) { int prime= {2,3}; //corner case for (int j = 5; j < n; ++j) //check for number from 5 to n-1 { int a=1; for (int i = 2; i < j/2; ++i) { if(j%i==0) { a=0; break; } } if(a==1) { prime.Add(j); //adding number to list "prime" } } return prime; }
Here, naive algorithm is used for generating the prime numbers with little modification.
After having the list of prime numbers, we will be using it as input for a Point node with technique ByCylindricalCordinates. The prime number list will be used as input for both the Radius and the Theta. However, for the input Theta prime number list should be converted to its corresponding degrees. For this, we use the function Degrees().
Please go through the sample file communities.bentley.com/.../Prime-number-pattern.gct