Determine if 2 edges are superimposed?

Given 2 TopoDS_Edges (or their curves) A & B, how to determine if A and B are superimposed over any part of their length, within some tolerance?

My best idea so far is to find a common starting point, find the parameter p on each curve at that point, find n points on each curve at (p + (someInterval * i)) and then test the distance between each pair of points. Maybe a sum of the squares instead of
doing individual comparisons?

I suspect that this approach does not take the full advantage of OCC's capabilities. :(

Any suggestions appreciated.

Thanks.

Mikhail Sazonov's picture

May be the common Boolean operation will help in your case.

Just set the fuzzy value to the given tolerance and compute common (BRepAlgoAPI_Common) between the two edges.

  BRepAlgoAPI_Common anOp;
  anOp.SetFuzzyValue (aTol);
  TopTools_ListOfShape anArg1, anArg2;
  anArg1.Append (anEdge1);
  anArg2.Append (anEdge2);
  anOp.SetArguments (anArg1);
  anOp.SetTools (anArg2);
  anOp.Build();
  TopoDS_Shape aRes = anOp.Shape();

aRes will contain the edge that is a common part of two edges. It will be an empty compound in case of no common.

WandererFan's picture

This is great. Never occurred to me to use booleans on edges. Thank you. In case somebody else comes looking, here is the code to interpret the result of the common.

    if (aRes.IsNull()) {
        return NOTASUBSET;      //no common segment
    }
    std::vector<TopoDS_Edge> commonEdgeList;
    TopExp_Explorer edges(aRes, TopAbs_EDGE);
    for (int i = 1; edges.More(); edges.Next(), i++) {
        commonEdgeList.push_back(TopoDS::Edge(edges.Current()));
    }
    if (commonEdgeList.empty()) {
        return NOTASUBSET;
    }
    //we're only going to deal with the situation where the common of the edges
    //is a single edge.  A really odd pair of edges could have >1 edge in their
    //common.
    TopoDS_Edge commonEdge = commonEdgeList.at(0);
    if (sameEndPoints(e1, commonEdge)) {
        return e1ISSUBSET;  //e1 is a subset of e0
    }
    if (sameEndPoints(e0, commonEdge)) {
        return e0ISSUBSET;  //e0 is a subset of e1
    }
    // e0 is not a subset of e1, nor is e1 a subset of e0, but they have a common segment
    return EDGEOVERLAP;