# Variable sized spheres over points depending on how close it is to other points

I have 400 or so points in my 3d coordinate plane and I am trying to analyze their density. I was wondering if there is a way to look at each point and its relationship to others, then, depending on their relationship, create a sphere with a certain radius with the respective point at its center. The parameters for how large the sphere should be could be as follows: If another point is 0-3 units away in any direction the resulting sphere should have a radius of 3, if another point is 3-6 units away it should have a radius of 2, if another point is 6-9 units away it should have a radius of 1, etc.

I know I should be using if statements but I’m new to rhino and python so the syntax is really getting me.

Hello - see how this works:

``````import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

def test():

rs.EnableRedraw(False)

points = rs.ObjectsByType(1)

pts = [rs.coerce3dpoint(id) for id in points]
spheres = []
count = 0

while count < len(points):

pt = pts.pop()

testPt = pts[rs.PointArrayClosestPoint(pts, pt)]
d = pt.DistanceTo(testPt)

if d <= 3:
spheres.append(Rhino.Geometry.Sphere(pt, 3.0))
elif 3< d <=6:
spheres.append(Rhino.Geometry.Sphere(pt, 2.0))
elif 6<d<=9:
spheres.append(Rhino.Geometry.Sphere(pt, 1.0))

pts.insert(0, pt)
count+=1

if len(spheres) > 0:
for sphere in spheres: