Grasshopper

algorithmic modeling for Rhino

I have several angle values and I want to identify and replace values of 2pi (6.283185) with 0.

I used a member index component and tried plugging in both Pi x 2 and 6.28315 but neither are recognized (see picture).

the replace set component did the same thing.

Anyone know why this is?

Views: 3280

Replies to This Discussion

Hi Brian,

you could be suffering from rounding errors. Floating point numbers in Grasshopper have ~16 decimal places, but I only typically show 6 in the UI.

If you want to replace 2*pi with zero, using an expression would be better. Create an expression component with a single variable (x) and an expression:

If(Abs(x - 2*pi) < 0.01, 0.0, x)

This works as follows. The If() function requires 3 arguments, i.e. it looks like If(X, A, B). The X part must resolve to a Boolean value (True/False). If X = True, then the function returns A, otherwise the function returns B.

So in this case, we measure the absolute difference between x and 2*pi, then compare that difference to a small (but non-zero) threshold value. You should never compare floating point numbers with zero tolerance because there is almost always some noise in the least significant digits after a few mathematical operations.

If you want to tighten up the comparison, use a number smaller than 0.01. If you want a really tight (but still non-zero) comparison, you can use the roughly-equals operator:

If(x ≈ 2*pi, 0.0, x)

which compares only the ten most significant digits.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Actually something quite different, still about member index though.

Why is it not possible to have automatic path to string on member index?

And why is my Data still a Path here, even thoug I did a conversion  via param before?

Thanks,

Phillip

Attachments:

Hi Phillip,

I agree Paths are distinctive enough to separate them from numbers and points, but as it is you can force the issue with a String Param instead of the Panel (which is slower)

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service