Grasshopper

algorithmic modeling for Rhino

Hi guys, I don't know why I can't approximate all numbers of this definition. Results could be 4.5, 2.0, 4.9, 1.4, 0.2, 5.8, 9.6, 9.2. Hope that someone could help me!! ;-)

Views: 1048

Replies to This Discussion

Why don't you use the [Round] component?

Wow ... I didn't know this battery yet ... but how can I define decimals numbers?

Sorry, I got confused. It's not in the component, it's in the expression editor:

Round(x, 1)

Keep in mind that rounding the number is not the same as changing its format:

when you format the number, the whole number is still kept in the memory. 

when you round it, it's the new rounded up number that get stored in the memory. 

I'm actually not sure about this... but if I'm wrong someone will correct me and I'll learn something new :)

Did not know that.
Thanks Jesus.

I don't think that is true.

Format and round should both output the same rounded value. The main difference is that format will output a string (that when connected to a number input will be reconverted into the rounded number), round will directly output the rounded down number.

Format is usually used to 'format' a number into readable text (by rounding, adding prefix and suffix letters like 'm²' and so on).

Hi Vicente,

Thank you for the clarification.
What does the "rounded down number" mean? The original value (before rounding, formatting)?

It should say "rounded number" (there is no rounding down), sorry. It means the number after rounding.

If I input the number '1.2345' into an expression component and format it with {0:0.0} it will return the string '1.2'. When I connect this string to an input asking for a number it will be automatically converted into the number '1.2'.

Understood.
And this automatic conversion is due to conversion ability implemented in some of Grasshopper components?
If it was in the custom VB,C#,Python component the number from the "format" output would need to be converted into float(x), before further inputting?

Yes, it's implemented in GH, not per component but per data type.

In a scripting component format is also a string and has to be converted to a double when needed, although there are also some sort of autoconversions. For example, this should work:  

Dim d As Double = String.Format("{0:0.0}", 1.23456)

Thanks Vicente. I new there'd be a cop somewhere. 

Great!! Thank U Jesus, it works. But I don't know why even if Rhino curves are defined by 1 number after comma (with lengths like 1.0, 2.5 ...) when I do this definition lenghts doesn't match. Seems that GSH fails to measure lengths.

The error is probably due to the subcurve component not creating a curve the exact length you are feeding in. It might or might not have to do with this, but keep in mind that it's asking for subdomain of the curve parameter and you are feeding a curve length value.

Nevertheless, for any practical purpose it should be good enough given that the error you are getting is around 0.002%.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service