Skip to content

Instantly share code, notes, and snippets.

@jhorikawa
Created August 31, 2015 20:23
Show Gist options
  • Save jhorikawa/f6fb13961a9adfa00652 to your computer and use it in GitHub Desktop.
Save jhorikawa/f6fb13961a9adfa00652 to your computer and use it in GitHub Desktop.
Rhinoceros / Grasshopper / GHPythonで球状グリッドを作ってみる ref: http://qiita.com/jhorikawa/items/ad86e1d3f6fe45a53518
import ghpythonlib.components as ghcomp
import Rhino
import math
objList = []
ptList = []
for i in range(num):
#球状に配列する
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;
#半径に応じてスケール
x = x * rad;
y = y * rad;
z = z * rad;
position = Rhino.Geometry.Point3d(x, y, z);
ptList.append(position)
#オブジェクトを配置
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 = []
...
...
for i in range(num):
#球状に配列する
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;
...
...
#半径に応じてスケール
x = x * rad;
y = y * rad;
z = z * rad;
position = Rhino.Geometry.Point3d(x, y, z);
ptList.append(position)
...
#オブジェクトを配置
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment