Perlin noise 3d

Hi @deja.vrbn,

You could achieve this by checking if a new point has a certain minimum distance to all the previously created points and save it, only if the minimum distance criteria is met.

import rhinoscriptsyntax as rs
import perlin

sn = perlin.SimplexNoise()

pList = [ ]

for i in range(x):
    for j in range(y):
        for k in range(z):
            perVal = sn.noise3(i * scaleX, j * scaleY, k * scaleZ)
            if (perVal > lowerLim and perVal < upperLim):
                
                if len(pList) == 0: # empty point list
                    pt = rs.AddPoint(i, j, k) # create first point
                    pList.append(pt) # save first point to list
                else: # not empty point list
                    pt = rs.AddPoint(i, j, k) # create point
                    shortest_dist = sorted([rs.Distance(pt, prev_pt) for prev_pt in pList])[0] # find the distance to the closest neighbour
                    if shortest_dist >= minDist: # if the closest neighbour is far enough away...
                        pList.append(pt) # save point to list

a = pList

You need to add minDist as a slider input!

Since, you are new to Python, you might not understand the following line:
shortest_dist = sorted([rs.Distance(pt, prev_pt) for prev_pt in pList])[0]

It’s basically short hand for this:

distances = []
for prev_pt in pList:
    dist = rs.Distance(pt, prev_pt)
    distances.append(dist)
sorted_distances = sorted(distances)
shortest_dist = sorted_distances[0]

If you’re interested in this topic, simply google “python list comprehensions”.

I hope this helps.

1 Like