forked from mcneel/rhino-developer-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircleTrimmer.rvb
54 lines (43 loc) · 1.52 KB
/
CircleTrimmer.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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' CircleTrimmer.rvb -- February 2010
' 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 CircleTrimmer
' Local variable declarations
Dim curve, circle, ccx, ccx_t(1), interval
' Select closed curve to split
curve = Rhino.GetObject("Select closed curve to split", 4)
If IsNull(curve) Then Exit Sub
If Not Rhino.IsCurveClosed(curve) Then Exit Sub
' Select circle to split with
circle = Rhino.GetObject("Select circle to split with", 4)
If IsNull(circle) Then Exit Sub
If Not Rhino.IsCircle(circle) Then Exit Sub
' Intersect the two curves
ccx = Rhino.CurveCurveIntersection(curve, circle)
If IsNull(ccx) Then
Rhino.Print "Curve and circle do not intersect"
Exit Sub
End If
' Make sure there are only two intersection events
If UBound(ccx) <> 1 Then
Rhino.Print "Unable to split curve"
Exit Sub
End If
' Get two intersection parameters on the curve
ccx_t(0) = ccx(0,5)
ccx_t(1) = ccx(1,5)
' If the input curve is closed and the interval is decreasing,
' then the portion of the curve across the start and end of the
' curve is returned.
If ccx_t(0) < ccx_t(1) Then
interval = Array(ccx_t(1), ccx_t(0))
Else
interval = Array(ccx_t(0), ccx_t(1))
End If
' Trim the curve
Rhino.TrimCurve curve, interval
End Sub