Forgot password?

Create an account!

Forum

« back

RhinoScript – random points

Messages

Please log in to write a message.

  • 2. Hanno (Sep 14, 2009 15.30):

    Hi,

    your loop runs 500 times, but points are only created if the random coordinates are valid. So depending on the random results your script creates up to 500 points. You can replace your if line with a loop statement, leaving the rest unchanged like this:

            For i=Lbound(arrpoints) To Ubound(arrpoints)
                   
                Do

                    Dim x: x = rnd()*xparameter
                    Dim y: y = rnd()*yparameter
                    Dim z: z = rnd()*zparameter
                    '              
                    Arrpoints(i)=array(x,y,z)

                Loop Until ValidPoint(x, y, z, 12000, 11000,1000,0)

                Rhino.addpoint(arrpoints(i))
                   
            Next

    This means that your loop runs 500 times, and each iteration is repeated until a valid point is found. Theoretically this can run infinitely, so keep your solution space large enough.

    As for your second question: The easiest way is to create separate loops (one for each side) and run them one by one. If you want the same amount on each side, the distribution stays only random per side, so you don't need to combine all in one run.

    Hope that helps!

    Hanno

  • 1. moodo (Sep 14, 2009 13.11):

    hey all,

    I want to generate 500 points between two boxes (polysurfaces). I made a script
    where I generate some points between the inner and outer 'box'. The outerbox is a box 12000x12000x12000, the innerbox is 10000,10000,11000 the groundsuface of the inner and outerbox have the same z coordinates.
    The script generates points, but not 500, how can I solve this.
    And how do I get a 'equal' amount of points on all sides?

    thank you.

    gr.
    m00do

            'creates points between outer box 12000*12000*12000 and inner
            'box 10000*10000*11000
           
            Dim intnumpoints, Xparameter, Yparameter, zparameter
            intnumpoints = rhino.getinteger("how many points? ",500,1)
            Xparameter=12000
            Yparameter =12000
            Zparameter=12000
            ReDim arrpoints(intNumPoints -1)

           
            Dim i
            For i=Lbound(arrpoints) To Ubound(arrpoints)
                   
                    Dim x: x = rnd()*xparameter
                    Dim y: y = rnd()*yparameter
                    Dim z: z = rnd()*zparameter
                    '              
                    Arrpoints(i)=array(x,y,z)
                   
                    If ValidPoint(x, y, z, 12000, 11000,1000,0) Then
                            Rhino.addpoint(arrpoints(i))
                   
                    End If
            Next



           
    End Sub

    Function ValidPoint(x, y, z, outer, inner,outer2,inner2)
            ValidPoint = x > inner2 And x < outer2 Or x > inner And x <outer And _
                    y > inner2 And y < outer2 Or y>inner And y<outer And _
                    z > inner2 And z < outer
            '2 Or z>inner And z<outer
    End Function
Recommend

Why are these buttons gray?