Forums > MaxMSP

check proximity of blobs stored in coll?

November 15, 2011 | 11:51 pm

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.


November 16, 2011 | 3:59 am

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. –

November 17, 2011 | 12:41 am

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


November 17, 2011 | 2:45 am

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.


November 17, 2011 | 3:09 am

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. –

Viewing 5 posts - 1 through 5 (of 5 total)