Distance Mesuring between blobs (every blob to every blob)
Hey everyone, I'm working on a tool that can mesure the distance between blobs and makes an alarm when a distance is too big or too small (works both ways). My problem now is, that I need a command or an if/while statement or something else (i really don't know, I'm a total beginner) that can calculate distances from every blob to every blob. So attached below you will find a subpatch of the programm, thats where the magic happens, and within the subpatch you will see that I have messageboxes for x and y positions of all blobs (50 blobs!) and than it goes in the distance calculation - thats were I'm stuck (as you will see from the patch below). Please help me, if you know a way how to achieve this. Like I need a calculation that calculates every frame the distance between all blobs (every blob with every blob). Help would be very much apreciated! Thanks in advance, David.
Let's think about that. You have one position (x y) for each blob.
You want to compute "the distance between all blobs (every blob with every blob)".
Let's start with the simpler question: how many values does that make?
With 3 points. How many distance values? (drawing...) I find 3.
4 points... 6 distance values.
5 points... (a pattern starts to appear if you draw...) 10 values...
So, it's as simple as "how many ways of taking 2 points in a set of n". That's the number nC2 = n!/(2*(n-2)!)
With 50 points, that's going to be 1225 distance values.
I just threw together a quick thing to get the correct points for all combinations, in a version with 4 points instead of 50.
I leave it to you to find the distances (i see a version with two [jit.op] objects) and to find the minimum (an option could be to use a zl object).
Of course, you could do the same with lists, no need for matrices for that.
I updated the patch, and included the shortest distance calculation:
You could optimize the code, but still, do you really want to do that for 50 points every frame?
Hey Jean, THANK YOU VERY MUCH! It helped us more than a lot!
But one quick question: Currently we have 2 cellblocks where all the x and y values are stored and permanently written (yes we do want to that for 50 points every single frame ;) ).
But we are stuck at transfering the contents of our two cellblocks to the first trigger (under "1. CLICK THIS").
You don't use cables or sends, how does it receive the x and y values from the two cellblocks on the left side?
Greetings from Austria,
David
The x and y values are in the matrix called "points" on the left.
Under Click This, it's only the building of the combinations (basically the list of possible pairs).
No send, no receive, but the matrix "points" is present at different places in the patch.
To use your own data, look only at the left part of the patch: data is in the matrix 'points'.
If you look at the first version of the patch, the data x y is in a one-plane 2-dimensional matrix.
In the second version, I used a 2-plane one-dimensional matrix.
Hi David and Jean-Francois.
Here's an approach using Jitter matrices exclusively I needed to build the other day.
Nice take on the problem, indeed!
You save quite some code by keeping the duplicates and the distance to self.
I don't know what a GPU approach (and readback) could add here.. just thinking.