Grasshopper

algorithmic modeling for Rhino

Hi all,

 

I'm pretty new to VB scripting(excuse me if I don't use correct terminology) and I'm having troubles dividing a list of circles I managed to create with a recursive function.

 

I found out curves have .DivideByCount method but when I declare circles I can't reach this method. Shall I declare the circles as curves and use DivideByCount? Can someone show a basic example how to use DivideByCount method for curves. All I could manage to get is the list of parameters on the curve. Shall I combine it with Curve.PointAt method to get division points as output?

 

Here is my script:

 

Private Sub RunScript(ByVal r As Double, ByVal n As Double, ByVal m As Object, ByRef A As Object, ByRef B As Object)

    'declaring list of radius values and circles
    Dim arrRadius As New List(Of Double)
    Dim arrCircles As New List (Of Circle)

    Call CircleGrowth(r, n, m, arrRadius, arrCircles)

    A = arrRadius
    B = arrCircles

  End Sub

 
  Sub CircleGrowth(ByVal r As Double, ByVal n As Double, ByVal m As Integer, ByRef arrRadius As List (Of Double), ByRef arrCircles As List (Of circle))

    'stopping condition
    If arrRadius.Count >= m  Then Exit Sub

    'declaring equations for recursive function (radius)
    Dim inradius,z,t As Double
    Dim c As New Point3d(0, 0, 0)


    inradius = r * math.Cos(math.PI / n)
    z = math.Sqrt(r ^ 2 - inradius ^ 2)
    t = r - inradius

    r = r + z - t

    arrRadius.Add(r)

    'add circle
    Dim crc As New Circle(c, r)
    arrCircles.Add(crc)

    Call CircleGrowth(r, n, m, arrRadius, arrCircles)

  End Sub

 

Thanks in advance.

Views: 2404

Attachments:

Replies to This Discussion

Hi Caglar, try this:

Private Sub RunScript(ByVal x As List(Of Object), ByVal y As Object, ByRef A As Object)


Dim p As New Point3d(0, 0, 0)
Dim c As New Circle(p, 13)

'Create a new NurbsCurve representation from the circle object
Dim n As New NurbsCurve(c.ToNurbsCurve())

'Divides the Curve domain in 3 segments (returns domain as double array)
Dim d() As Double = n.DivideByCount(3, True)

'to output the segment use trim function and the corresponding domain values...loop?
A = n.Trim(d(0), d(1))

End Sub

Thanks Florian,

You made me switch to Bronze Age. I just need the division points so I used this:

 

Dim p As New Point3d(0, 0, 0)
    Dim c As New Circle(p, x)

    'Create a new NurbsCurve representation from the circle object
    Dim n As New NurbsCurve(c.ToNurbsCurve())

    'Divides the Curve domain in y segments (returns domain as double array)
    Dim d() As Double = n.DivideByCount(y, True)

    Dim pointList As New List (Of Point3d)
    Dim divisionPoint As Point3d
    Dim i As Integer
    For i = 0 To y - 1

      divisionPoint = n.PointAt(d(i))
      pointList.Add(divisionPoint)

    Next
    A = pointList

 

If there is a shorter method, I'd be happy to know.

Circles are not Curves. I know that is a bit counter-intuitive, but I mean that the type Rhino.Geometry.Circle has not been derived from the type Rhino.Geometry.Curve. We've done this because Circles are Value Types in RhinoCommon (whereas Curve is a Reference Type) and also because Curves come with quite a lot of baggage and we wanted to keep Circle lean and mean.

 

You have two options to go from Circle to Curve:

 

1) Use the ToNurbsCurve() method to create a nurbs-curve with similar shape (but not similar derivatives!).

2) Create an ArcCurve from your circle.

 

The whole point of ArcCurve is to provide the methods only found on Rhino.Geometry.Curve for Arcs and Circles (for the same reason we also have LineCurve and PolylineCurve)

 

Dim crc As New Circle(Point3d.Origin, 10.0)

Dim crv As New ArcCurve(crc)

Dim pts As Point3d()

crv.DivideByCount(12, True, pts)

A = pts

 

This will divide the circle into 12 segments, and include both the start and the end point (which are identical since a circle is a closed curve).

 

Another way would be to evaluate the circle directly using a loop. Circles have a 'constant speed', in that the parameterization is the same everywhere. I.e. no matter where you are on the circle, if you take a step with constant parameter difference you'll always end up the same distance from where you started. Because of this property you can get away with iterating over the parameter domain of the curve knowing that your division points will be properly spaced. This would not be true if you had used the ToNurbsCurve() method, since a circular nurbs curve does not have constant parameterization.

 

Dim crc As New Circle(Point3d.Origin, 10.0)

Dim pts As New List(Of Point3d)

For i As Int32 = 0 To 12

   pts.Add(crc.PointAt(2.0 * Math.PI * (i/12)))

Next

A = pts

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service