I want to make a Gradient Descent algorithm which iteratively performs small steps in the direction of the negative gradient towards a (local) minimum (like a drop of water on a surface, flowing downwards from a given point in the steepest descent direction). Does anyone know how to do this?
I trimmed down the scritp to only include the random distribution. Each point is positioned randomly within it's separate square.
Dim strObject, arrBox, dblX, dblY, strDensity, n, x, y, dblRan1, dblRan2, arrResults
strObject = Rhino.GetObject("Select a surface",8,,True)
If Issurface(strObject) Then
strDensity=1
arrBox=Rhino.boundingbox(strObject)
'-------------------------------- Adding and projecting data
dblX=Round(Rhino.Distance (arrBox(0), arrBox(1)),0)/strDensity
dblY=Round(Rhino.Distance (arrBox(0), arrBox(3)),0)/strDensity
Dim ArrPoints()
n=0
For x=0 To dblX
For y=0 To dblY
Randomize
dblRan1=rnd
Randomize
dblRan2=rnd
ReDim Preserve arrPoints(n)
arrPoints(n) = array((arrbox(0)(0)+x*strDensity)+(dblRan1*strDensity),(arrbox(0)(1)+y*strDensity)+(dblRan2*strDensity),(arrbox(7)(2)+10))
n=n+1
Next
Next
arrResults = Rhino.ProjectPointToSurface(arrPoints, strObject, Array(0,0,-1))
Rhino.addpoints arrResults
End If
Jørgen Holo
I trimmed down the scritp to only include the random distribution. Each point is positioned randomly within it's separate square.
Dim strObject, arrBox, dblX, dblY, strDensity, n, x, y, dblRan1, dblRan2, arrResults
strObject = Rhino.GetObject("Select a surface",8,,True)
If Issurface(strObject) Then
strDensity=1
arrBox=Rhino.boundingbox(strObject)
'-------------------------------- Adding and projecting data
dblX=Round(Rhino.Distance (arrBox(0), arrBox(1)),0)/strDensity
dblY=Round(Rhino.Distance (arrBox(0), arrBox(3)),0)/strDensity
Dim ArrPoints()
n=0
For x=0 To dblX
For y=0 To dblY
Randomize
dblRan1=rnd
Randomize
dblRan2=rnd
ReDim Preserve arrPoints(n)
arrPoints(n) = array((arrbox(0)(0)+x*strDensity)+(dblRan1*strDensity),(arrbox(0)(1)+y*strDensity)+(dblRan2*strDensity),(arrbox(7)(2)+10))
n=n+1
Next
Next
arrResults = Rhino.ProjectPointToSurface(arrPoints, strObject, Array(0,0,-1))
Rhino.addpoints arrResults
End If
Dec 3, 2009
Richard Schaffranek
Here the corrected Script
Dec 4, 2009
Pablo Resende
Thank you!
Sep 14, 2010