Created
August 31, 2015 20:23
-
-
Save jhorikawa/f6fb13961a9adfa00652 to your computer and use it in GitHub Desktop.
Rhinoceros / Grasshopper / GHPythonで球状グリッドを作ってみる ref: http://qiita.com/jhorikawa/items/ad86e1d3f6fe45a53518
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ghpythonlib.components as ghcomp | |
import Rhino | |
import math | |
objList = [] | |
ptList = [] | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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; | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
#半径に応じてスケール | |
x = x * rad; | |
y = y * rad; | |
z = z * rad; | |
position = Rhino.Geometry.Point3d(x, y, z); | |
ptList.append(position) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
#オブジェクトを配置 | |
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) | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
objs = objList | |
pts = ptList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment