forked from mcneel/MOVED-rhinoscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawParametricCurve.rvb
67 lines (56 loc) · 2.05 KB
/
DrawParametricCurve.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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' DrawParametricCurve.rvb -- February 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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Subroutine: DrawParametricCurve
' Purpose: Create a interpolated curve based on a parametric equation.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub DrawParametricCurve()
Dim t0, t1, t, intCount, x, arrPoint, arrPoints()
Dim a, b
a = 6
b = 3
' Get the minimum parameter
t0 = Rhino.GetReal("Minimum t value", 0.0)
If IsNull(t0) Then Exit Sub
' Get the maximum parameter
t1 = Rhino.GetReal("Maximum t value", 1.0)
If IsNull(t1) Then Exit Sub
' Get the number of sampling points to interpolate through
intCount = Rhino.GetInteger("Number of points", 50, 2)
If IsNull(intCount) Then Exit Sub
' Get the first point
ReDim arrPoints(intCount - 1)
arrPoint = CalculatePoint(t0, a, b)
arrPoints(0) = arrPoint
' Get the rest of the points
For x = 1 To intCount - 2
t = (1.0 - (x / intCount) ) * t0 + (x / intCount) * t1
arrPoint = CalculatePoint(t, a, b)
arrPoints(x) = arrPoint
Next
' Get the last point
arrPoint = CalculatePoint(t1, a, b)
arrPoints(intCount - 1) = arrPoint
' Add the curve
Rhino.AddInterpCurve arrPoints
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Function: CalculatePoint
' Purpose: Customizable function that solves a parametric equation.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function CalculatePoint(t)
Dim arrPoint(2)
If IsNumeric(t) Then
arrPoint(0) = (4 * (1 - t) + 1 * t) * Sin(3 * 6.2832 * t)
arrPoint(1) = (4 * (1 - t) + 1 * t) * Cos(3 * 6.2832 * t)
arrPoint(2) = 5 * t
CalculatePoint = arrPoint
Else
CalculatePoint = Null
End If
End Function