Comparing lists of coordinates

Hi there. Using Grasshopper (without any scripting), I have created a series of boxes with random colors. They are laid out in a rectangular matrix so boxes will have up to 8 other boxes next to them, depending on where the boxes are (e.g. boxes at the edge of the matrix will have fewer neighbours). What is the algorithm I need to highlight each box and find out what are the colors of its neighbours?

I’ve tried comparing (Equality) the list of neighbours from a point in the matrix (Closest Points) with the lists generated from each of the color algorithms (the algorithms that assign a color to each box). Theoretically, this should generate a list of coordinates that are common to both and thus identify the color of each neighbour. Assuming that the Equality component compares the coordinates from each list. If not, which command will do that? Or, what is the algorithm I need to do this?

Many thanks in advance.

Images? Files?

As in, ‘manually’? I don’t understand what you mean by highlight. Or ‘each’ for that matter. Each in turn? Each all at once?

9x9 cube.3dm (27.3 KB)
Sample (18.3 KB)

Here are the files. The idea is to create a structure of cubes with different colors (randomly assigned) and then inspect each cube to find out what colors are its neighbouring cubes. The current sample is the simplest structure we can think of but the longer aim is to be able to create structures of cubes of any size (e.g. 20x50x9) and then be able to inspect each cube to determine its context.

Either. That is, the user can choose to inspect any cube, and we also want to programmatically inspect all the cubes in turn and be able to do something with them depending on their context (e.g. join the cube to other neighbouring cubes of the same color and create a new object).

This can be pretty complicated, however you may be able to rephrase your problem using only point coordinates. For example the attached file shows how to find all clusters of neighbouring points with the same colour using the Point Groups component, which does all the heavy lifting. I do have to pre-process the data so that only neighbours with identical colours are considered: cluster (28.0 KB)

And to prove that it’s correct, here’s a metaball drawn around each cluster:

Cool. Many thanks, :).

Ummm, how might one do it on a three dimensional cluster of cubes?

That won’t translate too well, since I need an additional dimension to move points with different colours away from each other. In three-dimensions, you’d need a fourth, which isn’t supported in GH. You’ll have to instead split your volume into different branches of a datatree and avoid cross-pollination that way.

Can you share a file (ideally as simple as possible) that has the data you want to match up?

It might be easier to just tell you what we are trying to do. We’re a group of architectural students thinking around a parametrically driven building design. Thus:

  1. Take a 4.5x4.5x4.5 module (actually the size doesn’t matter but it’s easier if we have a rectangular module).
  2. These modules are assigned different functions (colors): residential, commercial, office, recreation/leisure, garden, etc. For the purpose of this exercise, we are restricting the functions to just three (residential, commercial, leisure).
  3. Buildings are simply collections of these modules built around a circulation system. For example, in a typical building tower, we’ll have a central core, and the modules will all be located around this core.
  4. There are obvious problems if the modules are more than 1 deep as the internal modules will have no access to the outside and the external modules will be blocked from access by the internal modules. At this point, let’s not worry about that.
  5. The idea is that you can “buy or rent” any number of modules and combine them for your purpose. For example, if you buy 3-4 adjacent modules, you could have an apartment of maybe 2-3 bedrooms. Again, let’s not worry about how the apartment could be planned but assume that this can be done.
  6. The number of modules you can buy will of course depend on what is available but the idea is that this will allow the users to buy and use the modules in whatever way they like.
  7. We have a number of typical layouts that can be applied to the modules depending on what they are (residential/commercial/leisure), how many (from 2 upwards, the user can buy entire floors, and several floors, for example), and where they are located (faces that face outward can have windows and balconies, adjacent floors/walls/ceilings can be removed to create larger spaces), and so on.

We’re trying to create a central engine for this that we can build on but we don’t know how to inspect the structure and go beyond that. We can create structures of cubes and assign colors but we’re stuck beyond that. The earlier files I sent were an attempt at creating the simplest structure (9x9x9 cube).

We’re really new to this, so it might be that you will be able to better create the file than the one we created above.

This is an ambitious school project. When is it due?

No fixed date. It’s not a class assignment. Just something we wanted to do. We’re using this idea as a vehicle to learn Grasshopper. There are so many commands out there and so many things we can do, so we thought why not develop one idea and take it one step at a time. Right now, we’re looking to just being able to identify the location of the modules and identifying its properties (e.g. it is part of a larger group of 10 modules, it is a residential unit, it has 2 faces facing out, etc).

Hi, everyone, thank you for all your help. This is the simplest engine we have developed so far. The steps in the Grasshopper definition are: Create a box (module), arrange the boxes around a specified X,Y,Z axes so that we have a user-defined tower made of these boxes.

Because I’m using a centre-defined box, I’ve tried to change the source points so that tower starts on the origin rather than a little off the origin (since the origin of the box is in the centre of the box rather than in the bottom corner). There’s also a little definition within where I define distances between the boxes to be twice the dimension of the box as I figured out that the size of the box is actually twice the size of the dimension assigned to the box.

It’s as simple as I can conceive it. A few problems/questions:

  1. I’ve used a slider to set values to the multiplication component. Is there a simpler way to multiply a datum by a fixed constant, like 2?
  2. There is a line of boxes at the bottom of the tower which is out of place. Can anyone tell me why this is happening? The rest of the tower seems to be working as expected.

Now to assign colors to the cubes…

Upload file :wink:

Sure.OBL_box (10.5 KB)

I’ve changed it slightly to use a Panel component to input a constant.

you can right click on the N input of the series nodes and set expression to x * 2. you’d have to do this on all three inputs though, so not very efficient. instead of the multiplication i would use an expression component with x * 2 in it. just a little cleaner/better to read but essentially the same thing you did.

This is exactly what I need. Many thanks. I was wondering how to input constants into the program. What about irrational numbers like pi?