Forgot password?

Create an account!

Forum

« back

RhinoScript – Point Dispersion script

Messages

Please log in to write a message.

  • 2. Hanno (Oct 19, 2008 19.33):

    Hi andru,

    I took a quick look at your code: what are you trying to do in the "declare arrays" part? Do you want to use "max" as a variable or as function?
    I cannot comment on the whole script - How deep are you are into rhinoscript? I would suggest starting with a small part of your idea and getting this to work and then expanding it bit by bit.

  • 1. andru (Oct 18, 2008 03.50):

    Hi, I'm trying to write a point dispersion script that would allow me to generate a facade based on parameters. My methodology is to define a surface, randomly place points, and then within each placed point, another layer of randomized points (of a different type) are then dispersed. The intent is to use each point to place a window on a wall, with a definable parameter affecting the density of the dots (i.e. 60% of the surface)

    Currently I'm having problems trying to work the script - my arrays seem to be the problem which I'm having trouble solving. I'm translating a MATLAB script into Rhinoscript in order to guide my logic.

    Code as it is now:

    Option Explicit
    'Script written by
    'Script copyrighted by <>
    'Script version October-17-08 8:37:10 PM

    Call Main()

    Sub Main()

            'declare Grid
            Dim row ' declare X grid
            Dim col ' declare Y grid
            Dim StartingPtX 'declare starting point X
            Dim StartingPtY 'declare starting point Y
            Dim adjuster 'Dot density factor
            Dim i
            Dim j
            Dim k
            Dim h
            Dim d
                   
            row = 50 'Area size
            col = 50 'Area size
           
            StartingPtX = 25 ' Starting point for now, set to 25 for centre based on 50
            StartingPtY = 25 'Starting point for now, set to 25 for centre based on 50
           
            'declare arrays
           
            ReDim ArrPoints(row, col)
            ReDim max(i,j)
            ReDim dmax(max(max((row-StartingPtY, StartingPtY), max(col-StartingPtX,StartingPtX))))
           
                    'adjuster = Rhino.GetObjects("What is the intensity of the dots?", 3) 'Get input for dot concentration
                    adjuster = 3
           
            '------------------------------
           
            For k = 0 to row
                    For h = 0 To col
                            d = Sqr((row-StartingPtY)^2+(col-StartingPtX)^2)
                            If rnd(1) < 1 - (d/dmax)^adjuster
                                    Rhino.Addpoint = ArrPoints(row, col)
                            End If
                    Next
            Next
    End Sub

    And here is the MatLab code:

    m = 50;
    n = 50;

    array = zeros(m,n);
    givenx = 25;
    giveny = 25;


    dmax = max(max(m-giveny, giveny), max(n-givenx,givenx))
    adjuster = 3;

    for row = [1:m]
        for col = [1:n]
            d = sqrt((row-givenx)^2+(col-giveny)^2);
            if rand(1) < (1-(d/dmax))^adjuster
                array(row,col) = 1;
            end
        end
    end

    f = fopen('c:\out5.txt', 'wt');

    for row = [1:m]
        for col = [1:n]
            fprintf(f,int2str(array(row,col)));
        end
        fprintf(f, '\n');
    end

    fclose(f);

    In the Matlab code instead of adding points, 1s are used instead to point out the addition of a point.

Recommend

Why are these buttons gray?