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.