Find triangles from line
I suggest that you start by considering what it means for two points to be the same vertex.

In the toxiclibs library, a Vec2D consists of an x- and y-coordinate, each stored as a float.  In shareVertex(), you've defined two Vec2Ds to be the "same" point if they are less than one unit apart.  (Using == to compare floats is generally a bad idea, so setting some threshold for equality is good, though 1.0 might be a bit sloppy relative to the precision that a float is capable of.)

However, in getTraingle() [sic], you use a different criterion for equality of Vec2Ds.  You're relying on a TreeSet&lt;Vec2D&gt; to do the de-duplication for you.  In the absence of any comparator given to the TreeSet constructor, it will use Vec2D.compareTo().  Vec2D.compareTo() is a bit weird: it compares vectors by their distance from the origin (the weirdness being that if two points are the same distance from the origin, the ordering will be somewhat arbitrary, thus breaking the Comparable consistency requirement — but that's of no concern to you).  What does matter to you, though, are:


All you care about is equality, but you'll end up doing a lot of wasted magnitude calculations instead.
Your criterion for equality in shareVertex() (less than one unit separation) is inconsistent with the criterion for equality in Vec2D.compareTo() (strict float equality).




Once you've figured out which endpoints of the line segments coincide, the actual coordinates no longer matter.  At that point, you would be better off treating this as a problem in graph theory rather than one in computational-geometry.  Your algorithm is currently O(n3) due to the three nested loops.  You could probably do better with a smarter algorithm.