I made a spherical grid according to the specified number and wrote a script to arrange 3D objects there. I will write down the method.
[input] name: obj, Data Access: Item Access, Type hint: GeometryBase, desc: Objects to array name: num, Data Access: Item Access, Type hint: int, desc: Number of grids name: rad, Data Access: Item Access, Type hint: float, desc: Sphere Radius [Output] name: objs, desc: Objects arranged on a sphere name: pts, dec: spherically arranged points
import ghpythonlib.components as ghcomp
import Rhino
import math
objList = []
ptList = []
for i in range(num):
#Arrange in a spherical shape
y = i * 2 / num - 1 + (1 / num)
r = math.sqrt(1 - y * y)
phi = i * math.pi * (3 - math.sqrt(5));
x = math.cos(phi) * r;
z = math.sin(phi) * r;
#Scale according to radius
x = x * rad;
y = y * rad;
z = z * rad;
position = Rhino.Geometry.Point3d(x, y, z);
ptList.append(position)
#Place object
clone = obj.Duplicate()
center = clone.GetBoundingBox(True).Center
dir = Rhino.Geometry.Vector3d(position) - Rhino.Geometry.Vector3d(center)
dir.Unitize()
clone = ghcomp.OrientDirection(clone,center,Rhino.Geometry.Vector3d(0,0,1),position,dir)[0]
objList.append(clone)
objs = objList
pts = ptList
import ghpythonlib.components as ghcomp
import Rhino
import math
objList = []
ptList = []
...
Import the library used this time and make two empty lists.
...
for i in range(num):
#Arrange in a spherical shape
y = i * 2 / num - 1 + (1 / num)
r = math.sqrt(1 - y * y)
phi = i * math.pi * (3 - math.sqrt(5));
x = math.cos(phi) * r;
z = math.sin(phi) * r;
...
The main is this part, where the base of the spherical grid is made.
...
#Scale according to radius
x = x * rad;
y = y * rad;
z = z * rad;
position = Rhino.Geometry.Point3d(x, y, z);
ptList.append(position)
The base is scaled according to the size of the radius. After that, I put the points I made in ptList.
...
#Place object
clone = obj.Duplicate()
center = clone.GetBoundingBox(True).Center
dir = Rhino.Geometry.Vector3d(position) - Rhino.Geometry.Vector3d(center)
dir.Unitize()
clone = ghcomp.OrientDirection(clone,center,Rhino.Geometry.Vector3d(0,0,1),position,dir)[0]
objList.append(clone)
...
I duplicate the base object and use the GH component Orient Direction to orient it to the points in the grid I just created. Finally, add the duplicated object to the list.
...
objs = objList
pts = ptList
Finally, the list is output.
Recommended Posts