algorithmic modeling for Rhino
I want to retrieve a specific value from a list which is the closest to some value.
For example I have a range of numbers from 0 to 10, divided by 10 steps.
I want to retrieve the value from the list which is closest to 7.49 (which will be 7).
How can I do that?
Thank you.
Tags:
This is probably due to a type mismatch. When you connect differnet types to a component, GH tries to figure out what you want to do and converts types accordingly.
Data from a panel is a string and gets converted if neccessary. FSim probably rates strings more useful for set comparisons. So it seems to convert your data to string and match the best string, whih isn't the same as comparing numbers.
You can force the panels data to be treated as a number by feeding it through a Number parameter before connecting to FSim.
I am trying to get the same component , like the one Hannes Löschke did in here, just with additional variable.
The only problem is that I am getting an error message:
Operator '*' cannot be applied to operands of type 'double' and 'object'
Can somebody please tell me what is wrong?
I attached the file.
Thank you.
The sort component has a synchronous sort input (A) which will sort your index list in the same order as the K input. Therefore the first item in list A comes from the same location as the one in List K
Thank you for the help Danny.
I solved it with a bit strange way, by using part of your solution, so it works now.
I used your solution to get the nearest value from the list for 1.25e-9. Then inputted that nearest value into the FSim component, and inputted the above mentioned list also. That gave me the index of the nearest value. Maybe it sounds a bit complicated, as you said that index can be obtained directly from Sort component. But I do not understand you, as I do not understand how Sort component works.
But still I am willing to learn how Sort component works. I read the Help file for it, and again I do not understand it.
Do I need to open a new discussion for this or not?
The Sort Component has at least 2 inputs. K and A. It can have as many inputs as you like K, A, B, C, D, E....n. The important thing here is only K has any influence on the order of any of the lists. but the order in which K gets changed is the same order that all of the other lists get changed.
For example (I'm not at a PC with Rhino/GH so I can't post an example directly) You want to order a cloud of points from the bottom up, i.e. by Z lowest to highest. Using the PComp component to decompose a point into its separate x, Y and Z components you can plug the Z output into K of the Sort Component. Sort will then re-order the Z values from lowest to highest, but the points you wish to order haven't be changed only a list of numbers. So you can plug the points into A and they will be reordered into the same lowest to highest order that the Z component was changed to.
Similarly if each of these points had a label that you wished to be attached to it at a latter point in the definition the list would no longer be in the same sequence. For instance if the original list was ordered in the X axis from 1 to 20 with one being the closest point to X = 0 and 20 being the furthest. Since you have rearranged the points, their labels are now 1 is the lowest and 20 is the highest, but we want them to remain the same as before with 1 being the closest to X=0. This is where the extra inputs on the Sort Component come in. Plug the list into B.
K is ordered smallest number to largest number
A is ordered lowest point to highest point
B is ordered so that 1 remains closest point to X=0 and 20 is furthest from X=0
This seems like a fairly common question, I added a FAQ entry for it:
http://www.grasshopper3d.com/forum/topics/sorting-using-keys-values...
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by
I found where was an error I was talking about in my last post
I forgot to add "_" in front of some variables. So it works now, sorry for false alarm.
In any case, I am just curious: what did that error message mean:
?