Recursion

Bookmark and Share

I was Working couple weeks ago in a simple script to produce a recursion, I try drawing 3 points and then subdivided every segment for the mid point to find the another triangle inside of the original, the script appear in several minutes, Ididn`t think too much, I just typed very fast.

I learned recursion using C++, but I never used In Rvb, so this is my first experiments in recursion in Rvb. and this time I add The source of the original code, add comments, modify it, share, make differents Calls and send me Images.

Best.

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
Option Explicit
'Script written by Carlos de la Barrera'

Call Main()
Sub Main()
Dim pt1, pt2, pt3, trip
 
pt1 = Rhino.GetPoint("sel fisrt point")
If IsNull (pt1) Then Exit Sub
 
pt2 = Rhino.GetPoint("sel second point")
If IsNull (pt2) Then Exit Sub
 
pt3 = Rhino.GetPoint("sel third point")
If IsNull (pt3) Then Exit Sub
 
trip = Rhino.AddPolyline(Array(pt1, pt2, pt3, pt1))
 
Call myFractal(trip, pt1, pt2, pt3)
End Sub
 
Function myFractal(trip, Opt1, Opt2, Opt3)
Dim pt1, pt2, pt3
 
pt1 = myMidFunction(Opt1, Opt2)
pt2 = myMidFunction(Opt2, Opt3)
pt3 = myMidFunction(Opt3, Opt1)
 
trip = Rhino.AddPolyline(Array(pt1, pt2, pt3, pt1))
 
If Rhino.Distance(pt1, pt2) > 0.01 Then
Call myFractal(trip, pt1, pt2, pt3)
 
Else
Exit Function
 
End If
End Function
 
Function myMidFunction(P1, P2)
 
Dim MidP
MidP = Array((P1(0) + P2(0)) / 2, (P1(1) + P2(1)) / 2, (P1(2) + P2(2)) / 2)
 
myMidFunction = MidP
 
End Function

1 Comment

  • G.D.E.S. May 1, 2008, 18:37

    images represent the process of my recursion work that started few weeks ago, with the post recursion, I will continue working in this kind of programming, and exploring differents types of recursion.

    Recursion-3

Leave a Reply