check proximity of blobs stored in coll?

Nov 15, 2011 at 11:51pm

check proximity of blobs stored in coll?

Hey,
I’m storing blob coordinates in a coll object, they look like:
0, 100 200 50
1, 200 150 50
2, 120 40 50

Where the first number is X, then Y, then the size (irrelevant here).
I know this can be done the hard way… but if there’s an object that will help me out I would reaaallly appreciate it.

So if two coordinates are within let’s say 20 of each other, I want some output.

#60037
Nov 16, 2011 at 3:59am

c’mon, do it the hard way! distance formula via Pythagoras…for all the blobs…see below for an (admittedly convoluted) example. Probably a great place for Javascript to handle the numerous steps of calculations: building your lists, finding the differences between elements, squaring, etc…

– Pasted Max Patch, click to expand. –
#216138
Nov 17, 2011 at 12:41am

Thanks for the reply! But is there perhaps an easier way? And won’t Javascript slow down my patch quite a bit?

#216139
Nov 17, 2011 at 2:45am

Not sure about the slowing down, but this computation isn’t much. I bet JS would be totally fine, and if it’s an issue, an mxj would likely be faster. It’s really not that much number crunching compared to even a few jit.pwindows etc., I would imagine.

I also bet there’s a clever way to do it by storing your X and Y in a 2-plane matrix (just one row, with as many columns as blobs) and running through some jit.ops (or a custom jit.expr). You could use “getcell” and “setcell” if you had to work with individual cells at any point, but if there’s a way to keep it all in matrix-land, even by using intermediate matrices, it’ll be super fast…

Ideally you’d end up with a 2-dimensional, 1-plane matrix that has the distances from each blob to all the others, in each row. Similar to the example above but with way more blobs possible.

#216140
Nov 17, 2011 at 3:09am

This method accepts a list formed of as many x,y pairs as you need and uses the “combo” subpatch to find all the combinations of blobs you will want to compare. This should be more efficient than comparing each blob to all the others which results in each pair being tested twice and all blobs being compared to themselves (we don’t need every permutation, the order doesn’t matter).

– Pasted Max Patch, click to expand. –
#216141

You must be logged in to reply to this topic.