-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIcosahedron.rvb
83 lines (71 loc) · 3.02 KB
/
Icosahedron.rvb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Icosahedron.rvb -- September 2009
' If this code works, it was written by Dale Fugier.
' If not, I don't know who wrote it.
' Works with Rhino 4.0.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Creates a regular icosahedral
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Icosahedron()
' Declare local variables
Dim radius, center
Dim sqr5, phi, ratio, a, b
Dim v(11), s(19)
' Prompt for center point
center = Rhino.GetPoint("Center of icosahedral")
If IsNull(center) Then Exit Sub
' Prompt for radius
radius = Rhino.GetDistance(center, 1.0,"Radius")
If IsNull(radius) Then Exit Sub
' This will make the script run faster
Call Rhino.EnableRedraw(False)
' A few calculations...
sqr5 = Sqr(5.0)
phi = (1.0 + Sqr5) * 0.5 ' golden ratio
ratio = Sqr(10.0 + (2.0 * sqr5)) / (4.0 * phi)
a = (radius / ratio) * 0.5
b = (radius / ratio) / (2.0 * phi)
' Define the icosahedron's 12 vertices
v(0) = Rhino.PointAdd(center, Array( 0, b, -a))
v(1) = Rhino.PointAdd(center, Array( b, a, 0))
v(2) = Rhino.PointAdd(center, Array(-b, a, 0))
v(3) = Rhino.PointAdd(center, Array( 0, b, a))
v(4) = Rhino.PointAdd(center, Array( 0, -b, a))
v(5) = Rhino.PointAdd(center, Array(-a, 0, b))
v(6) = Rhino.PointAdd(center, Array( 0, -b, -a))
v(7) = Rhino.PointAdd(center, Array( a, 0, -b))
v(8) = Rhino.PointAdd(center, Array( a, 0, b))
v(9) = Rhino.PointAdd(center, Array(-a, 0, -b))
v(10) = Rhino.PointAdd(center, Array( b, -a, 0))
v(11) = Rhino.PointAdd(center, Array(-b, -a, 0))
' Create the icosahedron's 20 triangular faces
s(0) = Rhino.AddSrfPt(Array(v(0), v(1), v(2)))
s(1) = Rhino.AddSrfPt(Array(v(3), v(2), v(1)))
s(2) = Rhino.AddSrfPt(Array(v(3), v(4), v(5)))
s(3) = Rhino.AddSrfPt(Array(v(3), v(8), v(4)))
s(4) = Rhino.AddSrfPt(Array(v(0), v(6), v(7)))
s(5) = Rhino.AddSrfPt(Array(v(0), v(9), v(6)))
s(6) = Rhino.AddSrfPt(Array(v(4), v(10), v(11)))
s(7) = Rhino.AddSrfPt(Array(v(6), v(11), v(10)))
s(8) = Rhino.AddSrfPt(Array(v(2), v(5), v(9)))
s(9) = Rhino.AddSrfPt(Array(v(11), v(9), v(5)))
s(10) = Rhino.AddSrfPt(Array(v(1), v(7), v(8)))
s(11) = Rhino.AddSrfPt(Array(v(10), v(8), v(7)))
s(12) = Rhino.AddSrfPt(Array(v(3), v(5), v(2)))
s(13) = Rhino.AddSrfPt(Array(v(3), v(1), v(8)))
s(14) = Rhino.AddSrfPt(Array(v(0), v(2), v(9)))
s(15) = Rhino.AddSrfPt(Array(v(0), v(7), v(1)))
s(16) = Rhino.AddSrfPt(Array(v(6), v(9), v(11)))
s(17) = Rhino.AddSrfPt(Array(v(6), v(10), v(7)))
s(18) = Rhino.AddSrfPt(Array(v(4), v(11), v(5)))
s(19) = Rhino.AddSrfPt(Array(v(4), v(8), v(10)))
' Join all of the faces
Rhino.UnselectAllObjects()
Call Rhino.SelectObjects(s)
Call Rhino.Command("_Join", False)
Rhino.UnselectAllObjects()
' Don't forget to do this
Call Rhino.EnableRedraw(True)
End Sub