J'ai écrit un script pour créer une grille sphérique selon le nombre spécifié et y disposer les objets 3D. J'écrirai la méthode.
[contribution] name: obj, Data Access: Item Access, Indice de type: GeometryBase, desc: Objets à organiser name: num, Data Access: Item Access, Indice de type: int, desc: Nombre de grilles name: rad, Data Access: Item Access, Indice de type: float, desc: Sphere radius [Production] name: objs, desc: Objets disposés sur une sphère nom: pts, déc: points disposés de manière sphérique
import ghpythonlib.components as ghcomp
import Rhino
import math
objList = []
ptList = []
for i in range(num):
    #Disposer en forme sphérique
    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;
    
    #Échelle selon le rayon
    x = x * rad;
    y = y * rad;
    z = z * rad;
    position = Rhino.Geometry.Point3d(x, y, z);
    ptList.append(position)
    
    #Placer des objets
    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 = []
...
Importez la bibliothèque utilisée cette fois et créez deux listes vides.
...
for i in range(num):
    #Disposer en forme sphérique
    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;
...
Le principal est cette partie, où est faite la base de la grille sphérique.
...
    #Échelle selon le rayon
    x = x * rad;
    y = y * rad;
    z = z * rad;
    position = Rhino.Geometry.Point3d(x, y, z);
    ptList.append(position)
La base est mise à l'échelle en fonction de la taille du rayon. Après cela, j'ai mis les points que j'ai faits dans ptList.
...
    #Placer des objets
    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)
...
J'ai dupliqué l'objet de base et utilisé la direction d'orientation du composant GH pour l'orienter aux points de la grille que je viens de créer. Enfin, ajoutez l'objet dupliqué à la liste.
...
objs = objList
pts = ptList
Enfin, la liste est sortie.
Recommended Posts