请问intersectWith函数怎么用?能给个例子吗?谢谢
参考:void chkints(){
ads_point pickPt;
ads_name ent;AcDbObjectId entId1, entId2;
AcDbEntity *pEnt1, *pEnt2;
AcGePoint3dArray intPoints;// This array holds the intersecting points
AcGePoint3d intPt;
AcGePoint3d r1, r2, r3, r4;
AcGeVector3d transVec(-0.1, 0.1, 0.0);// Point translation vector
AcGeMatrix3d transMat; // Translation matrix
char kw;
int extVal = 0; // Extend value, 0 = no, 1 = fist entitity,
// 2 = second entity, 3 = both entities
// see intersectWith() function belowint rc;rc = acedEntSel("\nSelect first entity to test for intersection: ",
ent, pickPt);
switch(rc)
{
case RTCAN:
acutPrintf("\nUser canceled.");
return;
break; case RTERROR:
acutPrintf("\nNothing selected.");
return;
break;
}// switchacdbGetObjectId(entId1, ent);// Is the entity a line, arc or circle?
// Here we limit ourselves to lines, arcs
// and circles, because that is what we created
// in the last application.
acdbOpenAcDbEntity(pEnt1, entId1, AcDb::kForRead);
if(!(pEnt1->isKindOf(AcDbLine::desc()) ||
pEnt1->isKindOf(AcDbCircle::desc()) ||
pEnt1->isKindOf(AcDbArc::desc())
)
)
{
acutPrintf("\nNot a line, arc or circle entity.");
pEnt1->close();
return;
}// Now get the second entity
rc = acedEntSel("\nSelect second entity to test for intersection: ",
ent, pickPt);
switch(rc)
{
case RTCAN:
acutPrintf("\nUser canceled.");
return;
break; case RTERROR:
acutPrintf("\nNothing selected.");
return;
break;
}// switchacdbGetObjectId(entId2, ent);
acdbOpenAcDbEntity(pEnt2, entId2, AcDb::kForRead);// Is the second entity the same as the first?
if(entId1 == entId2)
{
acutPrintf("\nSame entity selected!");
pEnt1->close();
pEnt2->close();
return;
}// Is the second entity a line, arc or circle?
if(!(pEnt2->isKindOf(AcDbLine::desc()) ||
pEnt2->isKindOf(AcDbCircle::desc()) ||
pEnt2->isKindOf(AcDbArc::desc())
)
)
{
acutPrintf("\nNot a line, arc or circle entity.");
pEnt1->close();
pEnt2->close();
return;
}// If the first entity is not a circle
// ask if the user wants to extend the entity
// for apparent intersection
if(!pEnt1->isKindOf(AcDbCircle::desc()))
{
pEnt1->highlight(); acedInitGet(NULL, "Yes No");
rc = acedGetKword("\nExtend the highlighted entity - <No>: ", kw); pEnt1->unhighlight(); switch(rc)
{
case RTCAN:
case RTERROR:
acutPrintf("\nError with acedGetKword(). ");
pEnt1->close();
pEnt2->close();
return;
break; case RTNONE:
break; case RTNORM:
if(strcmp(kw, "Yes") == 0)
{
extVal = 1;
}
break;
}
}// If the second entity is not a circle
// ask if the user wants to extend the entity
// for apparent intersection
if(!pEnt2->isKindOf(AcDbCircle::desc()))
{
pEnt2->highlight(); acedInitGet(NULL, "Yes No");
rc = acedGetKword("\nExtend the highlighted entity - <No>: ", kw); pEnt2->unhighlight(); switch(rc)
{
case RTCAN:
case RTERROR:
acutPrintf("\nError with acedGetKword(). ");
pEnt1->close();
pEnt2->close();
return;
break; case RTNONE:
break; case RTNORM:
if(strcmp(kw, "Yes") == 0)
{
if(extVal == 1)
{
extVal = 3;// Both
}
else
{
extVal = 2;// Second only
}
}
break;
}
}
// Does the first selected entity
// intersect with the second enity?
switch(extVal)
{
case 0 :
pEnt1->intersectWith(pEnt2, AcDb::kOnBothOperands, intPoints);
// No extension on either entity
break; case 1 :
pEnt1->intersectWith(pEnt2, AcDb::kExtendThis, intPoints);
// Extend the first entity
break; case 2 :
pEnt1->intersectWith(pEnt2, AcDb::kExtendArg, intPoints);
// Extend the second entity
break; case 3 :
pEnt1->intersectWith(pEnt2, AcDb::kExtendBoth, intPoints);
// Extend both entities
break;}pEnt1->close();
pEnt2->close();// Here is an example of the AcGePoint3dArray class
// as well as a demonstration of how to use translation
// matricies AcGeMatrix3d
if(! intPoints.isEmpty())
{
for(int i = 0; i < intPoints.length(); i++)
{
intPt = intPoints.at(i); transMat = AcGeMatrix3d(transVec);
r1 = intPt;
r1.transformBy(transMat);
transVec.set(0.0, -0.2, 0.0);
transMat = AcGeMatrix3d(transVec);
r2 = r1;
r2.transformBy(transMat); acedGrDraw((double*)(&r1), (double*)(&r2), 3, 0); transVec.set(0.2, 0.0, 0.0);
transMat = AcGeMatrix3d(transVec);
r3 = r2;
r3.transformBy(transVec); acedGrDraw((double*)(&r2), (double*)(&r3), 3, 0); transVec.set(0.0, 0.2, 0.0);
transMat = AcGeMatrix3d(transVec);
r4 = r3;
r4.transformBy(transVec); acedGrDraw((double*)(&r3), (double*)(&r4), 3, 0);
acedGrDraw((double*)(&r4), (double*)(&r1), 3, 0); transVec.set(-0.1, 0.1, 0.0); acutPrintf("\nIntersection point = (%.2lf %.2lf %.2lf)",
intPt.x, intPt.y, intPt.z);
}
}
}
yfy2003 发表于 2004-6-3 21:58
参考:
C++?怎么运行呢?只知道有VBA,里斯普可以直接用,麻烦回一声哈。
页:
[1]