-
Notifications
You must be signed in to change notification settings - Fork 338
/
Copy pathSectionArea.rvb
97 lines (73 loc) · 2.62 KB
/
SectionArea.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
84
85
86
87
88
89
90
91
92
93
94
95
96
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' SectionArea.rvb -- July 2007
' 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
Sub SectionArea
' Prompt the user for the number of samples
samples = 8
samples = Rhino.GetInteger("Number of samples", samples, 2)
If IsNull(samples) Then Exit Sub
' Prompt the user for the 'from' point
pt0 = Rhino.GetPoint("Point to move from")
If IsNull(pt0) Then Exit Sub
' Prompt the user for the 'to' point
pt1 = Rhino.GetPoint("Point to move to", pt0)
If IsNull(pt1) Then Exit Sub
' Prompt the user for the object to cut
obj = Rhino.GetObject("Select closed volume to cut", 8)
If IsNull(obj) Then Exit Sub
' Redim arrays
Dim graph_points()
ReDim graph_points( samples )
' Try to speed things up a bit
Rhino.EnableRedraw False
' Add layers
Rhino.AddLayer "sections", RGB(240, 20, 20)
Rhino.AddLayer "cumulative area", RGB(20, 200, 20)
' Set the sections layer current
Rhino.CurrentLayer("sections")
' Create a vector from the two input points
v = Rhino.VectorCreate(pt1, pt0)
' Get the length of the vector
length = Rhino.VectorLength(v)
' Unitize the vector
v = Rhino.VectorUnitize(v)
' Calculate the size of each interval
interval = length / samples
' Repeat sample + 1 times
For i = 0 To samples
' Plane origin
origin = pt0
' Create plane from origin and vector
plane = Rhino.PlaneFromNormal(origin, v)
' If i > 0, then move the plane along the defined axis
If( i > 0 ) Then
scale_v = Rhino.VectorScale(v, i*interval)
origin = Rhino.PointAdd(pt0, scale_v)
plane = Rhino.MovePlane(plane, origin)
End If
' Add a point at the plane's origin
Rhino.AddPoint origin
' Create section curves through the object
sections = Rhino.AddSrfSectionCrvs(obj, plane)
' If there was more then one section curve
' try to union the curves together
If (UBound(sections) > 0) Then
sections = Rhino.CurveBooleanUnion(sections)
End If
' Calculate the area of the section curves
area = Rhino.CurveArea(sections)
' Build a graphing point based on the plane's
' origin, and the cumulative curve area
graph_points(i) = Array(origin(0), area(0), 0)
Next
' Draw our graph
Rhino.CurrentLayer("cumulative area")
Rhino.AddInterpCurve graph_points
Rhino.AddPoints graph_points
' Turn screen redrawing back on
Rhino.EnableRedraw True
End Sub