# Revision history [back]

I do not understand how you could build a matrix over the booleans or the strings in Sage ('True', 'False'). So, i will assume that you are able to build a matrix M where there is a 1 at position (i,j) if the segment i intersects the segment j, and 0 otherwise.

The answer of @kcrisman is correct: your matrix is the adjacency matrix of the intersection graph of your set of segments, and the clusters you are looking for are the connected components of your graph.

To transform your matrix into a graph:

sage: G = Graph(M) ; G


To see how your graph looks like:

sage: G.plot()


To find the connected components of your graph:

sage: CC = G.connected_components() ; CC


CC is a list of connected components, each connected component is a list of vertices. If you want to see how many components you have, just type:

sage: len(CC)


If you want to see how many vertices there is in each connected component, just type:

sage: [len(c) for c in CC]