Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
  • Welcome
  • Products
  • Support
  • About
  • More
  • Cancel
GenerativeComponents
  • Product Communities
  • More
GenerativeComponents
GenerativeComponents Community Wiki Ulam Spiral From A Rectangular Spiral
    • Sign in
    • +An Overview of GenerativeComponents
    • +Addin Content
    • +Bentley BIM Modeler Accreditation – Program Overview
    • +C# Sample Solution and other Add-ins
    • +GenerativeComponents Solutions
    • +Reference Material
    • Support for GenerativeComponents
    • -Tutorials
      • 3D array copy surface
      • Add RFA data as BuildingContent to ABD with GC Extension
      • Cell Feature
      • Create a Set of Random Points
      • Creation of Parabolic curve
      • Extrude Surface from Curve
      • Free Form Roof Example
      • GC Excel Feature
      • GenerativeComponents Essentials Course
      • How To Create Surface From Lines & Curves
      • Landscape Bridge Example
      • +LawCurve
      • List Of Points With A Loop Example
      • Mesh feature 3d print
      • Modular Multiplication On Circle
      • +Optimization with the Optimizer node type
      • Palm Tree Modeler
      • Point By Function Example
      • Points On Curve
      • Prime Number Pattern
      • Scripting Data Structures For Use With Features Example
      • Selection of Points
      • Selection of points based on Query Expressions
      • Selection of points based on range of indices
      • Set a New Property Value to a Set of Selected Nodes
      • Simple Bridge Example
      • Simple Equations To Describe Form Example
      • Simple Free Form Roof Example
      • Sin Tower
      • Skeleton
      • Sunflower Seed Pattern Modelling
      • Surface Division Basic Steps
      • Surface from Rails and Swept Sections
      • Tangent 3d print
      • +Tools and Techniques
      • Ulam Spiral From A Rectangular Spiral
      • Video Tutorials
      • Video Tutorials - Short Techniques
    • +User Projects
    • +Visualized Parametric Experimentations
    • +zed_Older Content

     
     Questions about this article, topic, or product? Click here. 

    Ulam Spiral From A Rectangular Spiral

      Product(s): OpenBuildings Generative Components
      Version(s): 10.06.03.04
      Environment:  N\A

     

    Background

    Prime numbers never fail to amaze us. One example of this would be the Ulam Spiral. If we have a rectangular spiral where each point represents a number. The starting point denotes 1 and the next point is 2 and so on so for as the spiral proceeds. We would find that some set of prime numbers line up in a series of straight lines. If we only display the points that represent the prime numbers we can notice an amazing pattern emerging out.

    Steps to Accomplish

    Step 1

            Create a list of Prime numbers. This is discussed in the wiki Prime Numbers Pattern.

    Step 2

    Create the required set of points for constructing the rectangular spiral. This is done using by function techniques of point node.
    The GC script for the ByFunction technique of the point node as follows.

    function (CoordinateSystem CS, int no_of_loops, int dist, var NumberSeries)
    {
        Point pt;
        int a=1;
        int y_up;
        int x_left;
        int y_down;
        int x_right;
        pt= new Point(this);
        pt.ByCartesianCoordinates(CS, dist, 0, 0.0);            //Starting point
        for (int i = 1; i <= no_of_loops; ++i)
        {
            a=a+1;
            if (NumberSeries.Contains(a))
            {
                pt= new Point(this);
                pt.ByCartesianCoordinates(CS, (i+1)*dist, (-i+1)*dist, 0.0);
            }
                   
            
            for (int j = 2; j <= 2*i; ++j)         //Positive y Up
            {
                a=a+1;
                y_up=(-i*dist)+j*dist;
                if (NumberSeries.Contains(a))
                {
                    pt= new Point(this);
                
                    pt.ByCartesianCoordinates(CS, (i+1)*dist, y_up, 0.0);
                }
                
            }
            for (int k = 1; k <= 2*i; ++k)         //Positive x left
            {
                a=a+1;
                x_left=(i+1)*dist-k*dist;
                if (NumberSeries.Contains(a))
                {
                    pt= new Point(this);
                
                    pt.ByCartesianCoordinates(CS, x_left, y_up, 0.0);
                }
                
            }
            for (int l = 1; l <= 2*i; ++l)         //Positive y down
            {
                a=a+1;
                y_down=y_up-l*dist;
                if (NumberSeries.Contains(a))
                {
                    pt= new Point(this);
                
                    pt.ByCartesianCoordinates(CS, x_left, y_down, 0.0); 
                }
                
            }
            for (int m = 1; m <= 2*i; ++m)         //Positive y down
            {
                a=a+1;
                x_right=x_left+m*dist;
                if (NumberSeries.Contains(a))
                {
                    pt= new Point(this);
                
                    pt.ByCartesianCoordinates(CS, x_right, y_down, 0.0);
                }
                
            }
        }
        
    }


             Please go through the sample file Rectangular Spiral.gct

    Step 3

    Once we have the point set for the rectangular spiral, we can further modify its script to only display the points that represent prime numbers. This could be done with an if statement which will check a condition before creating each point. Here the condition would be to check before creating the nth point if n exists in the previously created prime number list. In this way, we can get the Ulam's spiral from the rectangular spiral.
    The GC script for the ByFunction technique of the point node as follows.

    function (CoordinateSystem CS, int no_of_loops, int dist, var prime)
    {
        Point pt;
        int a=1;
        int y_up;
        int x_left;
        int y_down;
        int x_right;
        for (int i = 1; i <= no_of_loops; ++i)
        {
            a=a+1;
            if (prime.Contains(a))
            {
                pt= new Point(this);
                pt.ByCartesianCoordinates(CS, (i+1)*dist, (-i+1)*dist, 0.0);
            }
            
            for (int j = 2; j <= 2*i; ++j)         //y-direction Up
            {
                a=a+1;
                y_up=(-i*dist)+j*dist;
                if (prime.Contains(a))
                {
                    pt= new Point(this);
                
                    pt.ByCartesianCoordinates(CS, (i+1)*dist, y_up, 0.0);
                }
                
            }
            for (int k = 1; k <= 2*i; ++k)         //x-direction left
            {
                a=a+1;
                x_left=(i+1)*dist-k*dist;
                if (prime.Contains(a))
                {
                    pt= new Point(this);
                
                    pt.ByCartesianCoordinates(CS, x_left, y_up, 0.0);
                }
                
            }
            for (int l = 1; l <= 2*i; ++l)         // y-direction down
            {
                a=a+1;
                y_down=y_up-l*dist;
                if (prime.Contains(a))
                {
                    pt= new Point(this);
                
                    pt.ByCartesianCoordinates(CS, x_left, y_down, 0.0); 
                }
                
            }
            for (int m = 1; m <= 2*i; ++m)         // x-direction right
            {
                a=a+1;
                x_right=x_left+m*dist;
                if (prime.Contains(a))
                {
                    pt= new Point(this);
                
                    pt.ByCartesianCoordinates(CS, x_right, y_down, 0.0);
                }
                
            }
        }
        
    }

    Ulam's Spiral of 669 Prime Numbers 
                    Ulam's Spiral of 669 Prime Numbers

    669 Random Points
                      Just 669 Random Points

    Please go through the sample file Ulam's Spiral.gct

    • Rectangular Spiral
    • GenerativeComponents
    • GCscript
    • Prime Number
    • GenerativeComponents CONNECT Edition
    • Share
    • History
    • More
    • Cancel
    • Anik Mal Created by Bentley Colleague Anik Mal
    • When: Wed, Apr 1 2020 7:56 AM
    • Anik Mal Last revision by Bentley Colleague Anik Mal
    • When: Thu, Jun 11 2020 9:54 AM
    • Revisions: 3
    • Comments: 0
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2021 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies