### Poll

#### BUG

BUG
1 (50%)
BUG
1 (50%)

Total Members Voted: 1

### Author Topic: BUG in AcGeLineSeg3d::intersectWith  (Read 3773 times)

0 Members and 1 Guest are viewing this topic.

#### alinsoar

• Guest
##### BUG in AcGeLineSeg3d::intersectWith
« on: May 07, 2010, 05:39:09 AM »
Hi,

I have been using Autocad for a few days, but I have just discovered a bug into.

It is about the function intersectWith.

If I get 2 segments, which have a point in common, this function returns sometimes true, sometimes false.

Here is an example. I get the first segment to be [ 300.0 0.0 0.0] [100.0 0.0 0.0], and the other segment to be [0.0 gap 0.0 ] [100.0 0.0 0.0]. When I make a while with the gap varying in the interval [0 1], with the ratio 1/10^10, res is sometimes true (intersection), sometimes false (not intersected).

AcGePoint3d pt1Adl(0.00000000 ,0.00000000+gap,0.00000000);
AcGePoint3d pt1Bdl(100.0000000 ,0.00000000,0.00000000);
AcGePoint3d pt2Adl(300.00000000 ,0.00000000 ,0.00000000);
AcGePoint3d pt2Bdl(100.00000000 ,0.00000000 ,0.00000000);
AcGeLineSeg3d lSeg1dl(pt1Adl,pt1Bdl);
AcGeLineSeg3d lSeg2dl(pt2Adl,pt2Bdl);

res = lSeg1dl.intersectWith(lSeg2dl,ptInsd1,tol);

This is strange. I used a tolerance of tol=0.1, sometimes .01.

Can somebody (a mathematician) help me understand what it is happenning ?

Thanks in advance for any help

#### pkohut

• Guest
##### Re: BUG in AcGeLineSeg3d::intersectWith
« Reply #1 on: May 07, 2010, 06:19:55 AM »
Not a bug.

Quote
An intersection is a single point where two lines meet or cross each other.

Your lines are parallel, so the only possible intersection are where the end points meet.

#### alinsoar

• Guest
##### Re: BUG in AcGeLineSeg3d::intersectWith
« Reply #2 on: May 07, 2010, 07:12:14 AM »
probably I did not write correctly. I say again.

For gap = 0, I get an intersection point.

If gap > 0, gap very little, I won't get any more an intersection point, even if they meet in (100 0).

Afterwards, starting from another gap , the lines are reported to intersect again.

My misunderstanding is why intersectWith reports no intersection in the little interval.

#### alinsoar

• Guest
##### Re: BUG in AcGeLineSeg3d::intersectWith
« Reply #3 on: May 07, 2010, 07:23:59 AM »
About the test using parallelism idea, here is a test functions that I wrote.

Strange, for me it returns different results! There are some situations where the lines are reported parallel, and in the same time they have a point in common!

Will anybody test it either , please?

bool
myfunc(AcGeLineSeg3d x, AcGeLineSeg3d y, AcGeTol tol)
{
AcGeVector3d v1 = x.endPoint().asVector() - x.startPoint().asVector() ;
AcGeVector3d v2 = y.endPoint().asVector() - y.startPoint().asVector() ;

AcGeVector3d nulvec = AcGeVector3d::kIdentity;

v1.normalize();
v2.normalize();

AcGeVector3d sum = v1+v2;
AcGeVector3d dif = v1-v2;
AcGeTol zeroTol;
zeroTol.setEqualPoint(0.0);
zeroTol.setEqualVector(0.0);

if ((sum == nulvec) || (dif == nulvec))
return false;

//if(sum.isEqualTo(nulvec,zeroTol) || dif.isEqualTo(nulvec,zeroTol))
//    return true;

return ! (v1.isParallelTo(v2, tol));
}

void AcGeLineSeg3dTest::intersection()
{
AcGeTol told;
double dtold=0.1;
told.setEqualPoint(dtold);
//told.setEqualPoint(1.0);
told.setEqualVector(dtold);
//told.setEqualVector(0.01);
AcGePoint3d ptInsd1;

Adesk::Boolean retdx = Adesk::kTrue, retd1= Adesk::kTrue;
double deltad = 1e-5, gap = 0.0;

unsigned long long x=0, NN=100000;

x=NN;

while(x--!=1)
{
AcGePoint3d pt1Adl(0.0,0.0+gap,0.0);
AcGePoint3d pt1Bdl(100.0,0.0,0.0);
AcGePoint3d pt2Adl(0.0,0.0,0.0);
AcGePoint3d pt2Bdl(100.0,0.0,0.0);
AcGeLineSeg3d lSeg1dl(pt1Adl,pt1Bdl);
AcGeLineSeg3d lSeg2dl(pt2Adl,pt2Bdl);
retdx = lSeg1dl.intersectWith(lSeg2dl,ptInsd1,told);
retd1 = myfunc(lSeg1dl, lSeg2dl, told);
if((retd1!=retdx))
break;
gap+=deltad;
//pt1Ad.set(pt1Ad.x+gap,pt1Ad.y,pt1Ad.z);
//lSeg1d.set(pt1Ad,pt1Bd);
}

CPPUNIT_ASSERT ( !x);

x=NN;
while(x--!=1)
{
AcGePoint3d pt1Adl(0.00000000 ,0.00000000+gap,0.00000000);
AcGePoint3d pt1Bdl(100.0000000 ,0.00000000,0.00000000);
AcGePoint3d pt2Adl(300.00000000 ,0.00000000 ,0.00000000);
AcGePoint3d pt2Bdl(100.00000000 ,0.00000000 ,0.00000000);
AcGeLineSeg3d lSeg1dl(pt1Adl,pt1Bdl);
AcGeLineSeg3d lSeg2dl(pt2Adl,pt2Bdl);

retd1 = lSeg1dl.intersectWith(lSeg2dl,ptInsd1,told);
retdx = myfunc(lSeg1dl, lSeg2dl, told);
if(retdx!=retd1)
break;
gap+=deltad;
//pt1Ad.set(pt1Ad.x+gap,pt1Ad.y,pt1Ad.z);
//lSeg1d.set(pt1Ad,pt1Bd);
}
CPPUNIT_ASSERT ( !x);
return;

#### LE3

• Guest
##### Re: BUG in AcGeLineSeg3d::intersectWith
« Reply #4 on: May 07, 2010, 12:49:03 PM »
don't have much time to play... did a quick test (A2010) and your code as is it does not return any intersection - will try later if I can.

#### frtfff

• Bull Frog
• Posts: 229
##### Re: BUG in AcGeLineSeg3d::intersectWith
« Reply #5 on: May 08, 2010, 10:53:17 AM »
No bug,I have posted a pic for this. :pissed:

#### alinsoar

• Guest
##### Re: BUG in AcGeLineSeg3d::intersectWith
« Reply #6 on: May 11, 2010, 04:36:32 AM »
No bug,I have posted a pic for this. :pissed:

Thanks. Into one of my tests, it returns different results.