I have a 2d vector
vector<vector<double>> vec = { { 1, 0.5 },{ 2, 0.5 },{ 2.25, 0.5 },{ 2.6, 0.3 },
{3.3, 0.5 },{ 3, 0.5 },{ 3.1, 0.5 },{ 4, 0.6 } };
The first element is the start about a line. The second element is the length about the line. I can show it as follow graph
Now I want to get the group of the line index as they intersect or not. I mean I hope the result is
{{1},{2,3,4},{5,6,7},{8}}
If I'm in Wolfram Mathematic, I can use follow code
list = {{1, 0.5}, {2, 0.5}, {2.25, 0.5}, {2.6, 0.3}, {3.3, 0.5}, {3,
0.5}, {3.1, 0.5}, {4, 0.6}};
g = RelationGraph[#[[2]] < #2[[2]] < #[[2]] + #[[3]] || #[[2]] <
#2[[2]] + #2[[3]] < #[[2]] + #[[3]] &,
MapIndexed[Prepend[#, First[#2]] &, list]]
Map[First] /@ ConnectedComponents[g]
But how to implement this in C++
?