Grasshopper

algorithmic modeling for Rhino

This week I'm going into VB NET scriptting with GH an I have taked some examples to analyze and modify it.

I have tried to translate some old rhinoscripts using some examples like templates. I have detected that I get the same error always.

If you download this example and redimension the slider to 20, if you set it to 10, 12 or 19, you lose first row of points in surface.


Best.

p.s. I hope to debug this ussing VB.NET soon :)

Views: 199

Replies to This Discussion

Hi Ángel,

the reason you're getting the same problem with VB.NET as you were getting with RhinoScript is because both languages treat floating point numbers in the same way. You'd get the exact same problem with C++ and C# and (probably) Python.

Here's the problem (scroll down for the solution):

You're creating a loop that runs from zero to one, with a specific step size. However, the step size is computed as the inverse of the number of rows/columns. Whenever you compute 1.0 / Rows, you don't get the exact answer. You get a floating point number that is very close to the real answer. Add this number to itself 19 times and you don't end up exactly at 1.0, but at 1.000000000001 (or something). Therefore the last iteration is skipped.

You could solve this by adjusting your loop to go from zero to one+half-the-stepsize:
For i As Double = 0.0 To (1.0 + 0.5*rowStep) Step rowStep


But I think the following is much neater:
Private Sub RunScript(ByVal Brp As OnBrep, ByVal Col As Integer, ByVal Row As Object, ByRef A As Object)
  Dim srf As IOnSurface = Brp.Face(0)

  Dim U As OnInterval = srf.Domain(0)
  Dim V As OnInterval = srf.Domain(1)

  Dim Rows As New List(Of On3dPoint)
  For i As Int32 = 0 To Row
    For j As Int32 = 0 To Col
      Dim s As Double = U.ParameterAt(i / Row)
      Dim t As Double = V.ParameterAt(j / Col)

      Dim pt As On3dpoint = srf.PointAt(s, t)
      Rows.Add(pt)
    Next
  Next

  A = Rows
End Sub


I practically never use doubles in For...Next loops.

--
David Rutten
david@mcneel.com
Turku, Finland
Really nice solutions :) Master class here.

I was thinking about that kind of tolerance error but i could'nt get the thing out.

Really interesting. I don't understand how people doesn't care about that problem in examples.

Thanks a lot :)

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service