Perlin noise 3d

Hey!

I’m quite new to grasshopper and python scripting so I’m hoping you could help me whit my problem. I found this: https://www.youtube.com/watch?v=syOnj_QFaEc&t=95s (3d Perlin noise for grasshopper in python script) and I’m wondering if it is possible to generate the minimum distance between outputs(points). If yes is its still going to be Perlin noise? I’m sorry if this question is stupid but like I said I’m veryyyy. However, I need this for my school project.

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

Hey p1r4t3b0y,

thank you for your response. It works! I’m so happy! Thank you very much!!!

You’re welcome! Have a nice week-end.