# How to optimize lengths of parametric objects?

I have a parametric design of wooden sticks. Its length depends on the distance to a nearby curve. But each one has a different length. How can I optimize the lengths in a range of only 4 or 5 lengths so that my carpenter does not go crazy?
That is, you would need to round off the lengths so that you only have 4 or 5 different distances. I also need them to color according to their distance to generate a location graphic according to their dimensions. These dimensions must be painted in different colors to make it easier to locate in your site.

Use the Nearest Number component of Peacock.

2 Likes

Thanks … but I can not find that command in peacock …
Thank you very much!

1 Like

double click on canvas and type nearestNumber,
or from Peacock tab > Data panel > 2nd group.

What does the Peacock component do that the Find Similar Member component doesn’t? You can also use Find Domain as @Joseph_Oster did to get the nearest number, even if the domains are all zero-length, it will still find the nearest one.

I completely forgot about that component.
The difference is that it allows you to choose the closest upper or the closest lower with a boolean (only works with numbers). For example, to make a stone configuration from a circle packing with arbitrary radius, given a list of valid stone sizes, each circle must be associated with the nearest stone size without exceeding it, since if it is larger than the radius it would break the circle packing.

Yeah that’s quite a useful feature to have. You could do that with Find Domain if you make your domains all adjacent. Find whichever domain contains the value, then either use the minimum or the maximum limit of that domain to round. But it may add an uncomfortable amount of additional components just to create the domains themselves.

Pufferfish also has a Round To Nearest component with the option to remap the inputs to the bounds of the desired outputs. Useful for attractor values coming from distances which may be way out of bounds of the desired output lengths (to avoid clipping of the inputs and let you just take advantage of the attractor gradient)

Pf_RoundToNearest.gh (14.8 KB)

1 Like

Here is another example (the forum is full of them!) where two lists of values are used, one of circle diameters and the other of colors. It is a variation of the idea of computing the difference between a random value and each of the values in a limited list, sorting them and choosing the smallest: