Let's make a spherical grid with Rhinoceros / Grasshopper / GHPython

Introduction

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.

data

[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

Screen Shot 2015-09-01 at 04.55.21.png Screen Shot 2015-09-01 at 04.55.47.png

Commentary

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.

download

SphericalGrid.gh

Recommended Posts

Let's make a spherical grid with Rhinoceros / Grasshopper / GHPython
Let's make a GUI with python.
Let's make a breakout with wxPython
Let's make a graph with python! !!
Let's make a supercomputer with xCAT
Let's make a shiritori game with Python
Let's make a voice slowly with Python
Let's make a simple language with PLY 1
Let's make a web framework with Python! (1)
Let's make a tic-tac-toe AI with Pylearn 2
Let's make a Twitter Bot with Python!
Let's make a web framework with Python! (2)
Let's replace UWSC with Python (5) Let's make a Robot
[Let's play with Python] Make a household account book
Let's make a simple game with Python 3 and iPhone
Let's make dependency management with pip a little easier
Let's make a Mac app with Tkinter and py2app
[Super easy] Let's make a LINE BOT with Python.
Let's make Othello with wxPython
Let's make dice with tkinter
Make a fortune with Python
Let's make a rock-paper-scissors game
Make a fire with kdeplot
Let's make a websocket client with Python. (Access token authentication)
Let's make a diagram that can be clicked with IPython
Let's make a remote rumba [Hardware]
Make a sound with Jupyter notebook
Let's make a cycle computer with Raspberry Pi Zero (W, WH)
Let's make a spot sale service 2
Let's make a WEB application for phone book with flask Part 2
Let's make a spot sale service 1
Let's make Othello AI with Chainer-Part 1-
Make a recommender system with python
Let's make a WEB application for phone book with flask Part 3
Make a filter with a django template
Let's make a WEB application for phone book with flask Part 4
Let's make Othello AI with Chainer-Part 2-
Make a model iterator with PySide
Make a nice graph with plotly
Let's make a web chat using WebSocket with AWS serverless (Python)!
Let's make a spot sale service 3
[Ev3dev] Let's make a remote control program by Python with RPyC protocol
Make a video player with PySimpleGUI + OpenCV
Let's create a free group with Python
Make a rare gacha simulator with Flask
Make a Notebook Pipeline with Kedro + Papermill
Let's scrape a dynamic site with Docker
Make a drawing quiz with kivy + PyTorch
Make a cascade classifier with google colaboratory
[Python] Let's make matplotlib compatible with Japanese
Make a Yes No Popup with Kivy
Let's make a multilingual site using flask-babel
Make a wash-drying timer with a Raspberry Pi
Make a GIF animation with folder monitoring
Let's make a combination calculation in Python
Make a desktop app with Python with Electron
Let's make a Backend plugin for Errbot
Let's make an A to B conversion web application with Flask! From scratch ...
Let's make a nervous breakdown app with Vue.js and Django-Rest-Framework [Part 2] ~ Vue setup ~
Let's make a nervous breakdown app with Vue.js and Django-Rest-Framework [Part 1] ~ Django setup ~
Let's make a nervous breakdown application with Vue.js and Django-Rest-Framework [Part 6] ~ User Authentication 2 ~