` static void ArxPntInTri_getit(void)`

{

ads_point ads_testpnt;

AcGePoint3d a,b,c,p;

if(acedGetPoint(NULL,_T("\nPick Point to test: "),ads_testpnt) != RTNORM)

{

PRNTERR

return;

}

p = asPnt3d(ads_testpnt);

AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase();

AcDbBlockTableRecordPointer pBlockTableRecord(pDb->currentSpaceId(),kForRead);

TRYRETVOID (pBlockTableRecord.openStatus());

AcDbBlockTableRecordIterator* pIter;

TRYRETVOID (pBlockTableRecord->newIterator( pIter ))

for (pIter->start();!pIter->done();pIter->step())

{

AcDbObjectId entId;

TRYMSG(pIter->getEntityId(entId));

AcDbEntityPointer pEnt(entId,AcDb::kForRead);

AcDbFace* pFace = AcDbFace::cast(pEnt);

if(pFace)

{

TRYMSG(pFace->getVertexAt(0,a));

TRYMSG(pFace->getVertexAt(1,b));

TRYMSG(pFace->getVertexAt(2,c));

if(isInTriangle(AcGePoint2d(a.x,a.y),AcGePoint2d(b.x,b.y),

AcGePoint2d(c.x,c.y),AcGePoint2d(p.x,p.y)))

{

TRYMSG(pFace->upgradeOpen());

TRYMSG(pFace->setColorIndex(1));

}

}

}

delete pIter;

}

//http://www.blackpawn.com/texts/pointinpoly/default.html

static bool isInTriangle(const AcGePoint2d &a,

const AcGePoint2d &b,

const AcGePoint2d &c,

const AcGePoint2d &p)

{

AcGeVector2d v0 = c-a;

AcGeVector2d v1 = b-a;

AcGeVector2d v2 = p-a;

double dot00 = v0.dotProduct(v0);

double dot01 = v0.dotProduct(v1);

double dot02 = v0.dotProduct(v2);

double dot11 = v1.dotProduct(v1);

double dot12 = v1.dotProduct(v2);

double invDenom = 1 / (dot00 * dot11 - dot01 * dot01);

double u = (dot11 * dot02 - dot01 * dot12) * invDenom;

double v = (dot00 * dot12 - dot01 * dot02) * invDenom;

return (u > 0) && (v > 0) && (u + v < 1);

}

fixed leak