I'm using processing and so far I have a sketch that draws random balls, and draws a line when the connect within a certain radius.
for(int i=0;i<=people.size()-1;i++){
Person p = people.get(i);
for(Person pp: people){
if(pp!=p){
if(p.isIntersecting(pp)){
// Draw the line connecting the two here
line(p.loc.x,p.loc.y,pp.loc.x,pp.loc.y);
// Store the other person in this persons "connections" list
if(!p.connections.contains(pp)){ p.connections.add(pp);}
} else {
p.connections.remove(pp);
}
}
}
}
This works perfectly fine to visually show which groups are clustering together. But now how could I store that group of connected objects into an ArrayList, while they're connected? So I can recall them for other functions.
Like what I mean is, I can easily visually see when 4 people are linked on screen. But how can I tell the computer that they're all linked?
The links are stored in each objects connections list. But how does each separate object know of the other objects connections to group them.
So I can draw a "group blob" around them, while they're linked.
I've tried a bunch of things, but I always seem to be running into recursion/stackoverflow errors. Because obviously I'm just recursively looking through all the connections to link them, and it's too much.
Any idea how I can store the connected lines as Groups in an ArrayList?