Grasshopper

algorithmic modeling for Rhino

i wanna creat a bunch of random points based on a boundingbox of a curve.

i wrote the code in a for loop
but it turns out the random value is always the same. so i get all the points in one position.


Sub RunScript(ByVal x As OnCurve, ByVal y As Integer)
'your code here…

Dim BB As OnBoundingBox
BB = x.BoundingBox

Dim minPt As On3dPoint
minPt = BB.Corner(0, 0, 0)
Dim minx As Double = minPt.x
Dim miny As Double = minPt.y
Dim minz As Double = minPt.z


Dim maxPt As On3dPoint
maxPt = BB.Corner(1, 1, 1)
Dim maxx As Double = maxPt.x

Dim maxy As Double = maxPt.y
Dim maxz As Double = maxPt.z

Dim sx As Double = maxx - minx
Dim sy As Double = maxy - miny
Dim sz As Double = maxz - minz


Dim i As Integer
Dim RdPts As New List(Of On3dPoint)



Dim aa As Double
Dim dd As Double
Dim cc As Double

Randomize()


For i = 0 To y
Dim num As New Random
Dim Rnd As Integer = num.Next(1, 10)

aa = minx + sx * Rnd / 10
dd = miny + sy * Rnd / 10
cc = minz + sz * Rnd / 10

Dim pt As New On3dPoint (aa, dd, cc)


RdPts.Add(pt)

Next
A = RdPts

Views: 283

Replies to This Discussion

Not looking extensively at the code, try:

aa = minx + sx * num.Next(1, 10) / 10
dd = miny + sy * num.Next(1, 10) / 10
cc = minz + sz * num.Next(1, 10) / 10


also, there is specific vb/c# forum...

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service