TheSwamp

Code Red => ARX Programming => Topic started by: alinsoar on May 07, 2010, 05:39:09 AM

Title: BUG in AcGeLineSeg3d::intersectWith
Post by: alinsoar 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 pt1Bdl(100.0000000 ,0.00000000,0.00000000);
AcGePoint3d pt2Bdl(100.00000000 ,0.00000000 ,0.00000000);

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
Title: Re: BUG in AcGeLineSeg3d::intersectWith
Post by: pkohut 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.
Title: Re: BUG in AcGeLineSeg3d::intersectWith
Post by: alinsoar 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.

Title: Re: BUG in AcGeLineSeg3d::intersectWith
Post by: alinsoar 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;

double deltad = 1e-5, gap = 0.0;

unsigned long long x=0, NN=100000;

x=NN;

while(x--!=1)
{
AcGePoint3d pt1Bdl(100.0,0.0,0.0);
AcGePoint3d pt2Bdl(100.0,0.0,0.0);
retdx = lSeg1dl.intersectWith(lSeg2dl,ptInsd1,told);
retd1 = myfunc(lSeg1dl, lSeg2dl, told);
if((retd1!=retdx))
break;
}

CPPUNIT_ASSERT ( !x);

x=NN;
while(x--!=1)
{
AcGePoint3d pt1Bdl(100.0000000 ,0.00000000,0.00000000);
AcGePoint3d pt2Bdl(100.00000000 ,0.00000000 ,0.00000000);

retd1 = lSeg1dl.intersectWith(lSeg2dl,ptInsd1,told);
retdx = myfunc(lSeg1dl, lSeg2dl, told);
if(retdx!=retd1)
break;
}
CPPUNIT_ASSERT ( !x);
return;
Title: Re: BUG in AcGeLineSeg3d::intersectWith
Post by: LE3 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.
Title: Re: BUG in AcGeLineSeg3d::intersectWith
Post by: frtfff on May 08, 2010, 10:53:17 AM
No bug,I have posted a pic for this. :pissed:
Title: Re: BUG in AcGeLineSeg3d::intersectWith
Post by: alinsoar 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.