How to determine if two line segments are overlapping in AutoCAD

<?xml encoding=”UTF-8″>By Sreeparna Mandal

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:


<em>GE_DLLEXPIMPORT Adesk::Boolean overlap(
const AcGeLinearEnt3d& line,
AcGeLinearEnt3d*& overlap,
const AcGeTol& tol = AcGeContext::gTol
) const;</em>

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."));
}
}

Comments

6 responses to “How to determine if two line segments are overlapping in AutoCAD”

  1. Octordle compared to Wordle and Quordle is somewhat different. With 13 guesses with eight different vertical lines, the player needs to solve all eight horizontal words at the same time.

  2. Your writings stick out to me since the content is interesting and simple to understand. Even though I’ve read a lot of websites, I still like yours more. Your essay was interesting to read. I can understand the essay better now that I’ve read it carefully. In the future, I’d like to read more of your writing.

  3. The writing is amazing. Looking forward to reading it more.

  4. Sreeparna Avatar
    Sreeparna

    Thanks!!

  5. I am very happy to visit your blog, It tells me a lot of useful information. I will regularly visit the blog to support you.

  6. The article in this forum is very good, this article is very helpful for me. Nice to read your post. If you can, take a moment to play game a and b one of the most exciting games

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading