To check if two line segments are overlapping, we shall use the AcGeLinearEnt3d::overlap() method. It returns the line that coincides with their region of overlap. The declaration of the method goes as mentioned:
GE_DLLEXPIMPORT Adesk::Boolean overlap( const AcGeLinearEnt3d& line, AcGeLinearEnt3d*& overlap, const AcGeTol& tol = AcGeContext::gTol ) const;
Here, the overlap parameter is null if this function returns a value of Adesk::kFalse, else the overlap line may be an object of any derived class of AcGeLinearEnt3d, depending on the types of the two lines. The overlap() method can also be used for an input line which is 2D linear entity.
Below is the code snippet for its usage:
static void ADSKMyGroupCheckOverlap() { AcGeLineSeg3d line1(AcGePoint3d(0, 0, 0), AcGePoint3d(5, 0, 0)); AcGeLineSeg3d line2(AcGePoint3d(2, 2, 0), AcGePoint3d(2, -5, 0)); //intersecting with line1 AcGeLineSeg3d line3(AcGePoint3d(0, 0, 0), AcGePoint3d(10, 0, 0)); // overlapping with line1 bool isOverlapped = Adesk::kFalse; AcGeLinearEnt3d* overlappingEnt; isOverlapped = line1.overlap(line3, overlappingEnt); if (isOverlapped) { AcGePoint3d startPt, endPoint; if (!overlappingEnt->hasEndPoint(endPoint)) return; if (!overlappingEnt->hasStartPoint(startPt)) return; acutPrintf(_T("\nBoth lines are overlapping. Start and end points of the overlapping segment are:\n")); acutPrintf(_T("\nStart point: %f, %f, %f"), startPt.x, startPt.y, startPt.z); acutPrintf(_T("\nEnd point: %f, %f, %f"), endPoint.x, endPoint.y, endPoint.z); } else { acutPrintf(_T("\nLines are not overlapping.")); } }
Recent Comments