明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4433|回复: 7

AcDbFace面域问题??????

[复制链接]
发表于 2004-10-1 20:49:00 | 显示全部楼层 |阅读模式
我问过这个问题了,但是还不明白。请版主帮忙解释一下: 一下是我的做法,不知道为什么求不出面积。 AcGePoint3d pA(0,0,0),pB(100,0,0),pC(100,100,0),pD(0,100,0);
AcDbFace *pFace=new AcDbFace(pA,pB,pC,pD);
postToDatabase(pFace,faceId); ads_point pt1,pt2,pt;
AcGePoint2dArray point_Array; int stat=1;
stat=acedGetPoint(NULL,"选择点(ESC结束)\n",pt1);
if(stat==RTCAN)
return;
point_Array.append(asPnt2d(pt1));
while(1)
{
acdbPointSet(pt1, pt2);
file://stat = acedGetPoint(pick, "选择下一点(ESC-quit): ", pick);
stat=acedGetPoint(pt1,"选择点,(ESC结束)\n",pt1);
acedGrDraw(pt2, pt1, 1, 0);
if(stat==RTCAN)
break;
point_Array.append(asPnt2d(pt1));
}
AcDbPolyline *ClosePolyline=new AcDbPolyline();
for(int i=0;i<point_Array.length();i++)
{
AcGePoint2d pTmp=point_Array.at(i);
ClosePolyline->addVertexAt(i,pTmp,0,-1,-1);
} ClosePolyline->setColorIndex(1);
ClosePolyline->setClosed(Adesk::kTrue);
postToDatabase(ClosePolyline,IdObj);
acdbOpenAcDbEntity(pEnt,IdObj,AcDb::kForRead);
AcDbPolyline *pPoly=AcDbPolyline::cast(pEnt);
AcDbVoidPtrArray entities,regions;
entities.append(pFace);
entities.append(pPoly);
AcDbRegion::createFromCurves(entities, regions);
if (regions.length() < 1)
{
acutPrintf("构造闭合区域错误\n");
}
assert(pRegion != NULL);
AcDbRegion *pRegion = new AcDbRegion;

for ( i = 0; i < regions.length(); i++)
{
if(Acad::eOk!=pReg->booleanOper(AcDb::kBoolIntersect,(AcDbRegion*) regions))
acutPrintf("有问题\n");
delete (AcRxObject*)regions;

}
double regArea;
pReg->getArea(regArea);
pReg->close();
acutPrintf("area=%0.3f\n",regArea); 请高手指出错误。
发表于 2004-10-1 22:08:00 | 显示全部楼层

回复

能贴出你完整的代码吗?


没做过,只能帮你调试一下了.
 楼主| 发表于 2004-10-1 22:27:00 | 显示全部楼层
上面基本的程序放到一个函数里面即可。 版主可以看看两个多边形相交,如何求两个图形的交集的面积?? 帖子, 告诉我做法了,但是我没有求出结果。 基本思想。就是两个实体(闭合的)然后求出图形交集部分的面积
发表于 2004-10-1 22:54:00 | 显示全部楼层

回复

这里 file://stat = acedGetPoint(pick, "选择下一点(ESC-quit): ", pick);
stat=acedGetPoint(pt1,"选择点,(ESC结束)\n",pt1); 是什么? file:这一行需要吗? postToDatabase也是未声明的? 很多未声明的标识符!
 楼主| 发表于 2004-10-1 23:02:00 | 显示全部楼层
那是注释掉得语句。粘贴到帖子上就加了file。不要。


postToDatabase()是把该实体添加到图形数据库中
发表于 2004-10-1 23:10:00 | 显示全部楼层

回复

没法调试, 这段代码中很多变量都是没有声明的. postToDatabase IdObj pEnt pRegion pReg ... 因为我没做过,所以看不出应该怎么改. postToDatabase是个自定义的函数 Acad::ErrorStatus postToDatabase(AcDbEntity* ent, AcDbObjectId& objId)
{
// Given an entity, this function will post it to the database
// in MODEL_SPACE and then return the objectId; returns eOk if
// all went well.

Acad::ErrorStatus es;
AcDbBlockTable* pBlockTable;
AcDbBlockTableRecord* pSpaceRecord;

es = acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead); assert(es == Acad::eOk);

es = pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord, AcDb::kForWrite);
assert(es == Acad::eOk);

es = pBlockTable->close();
assert(es == Acad::eOk);

es = pSpaceRecord->appendAcDbEntity(objId, ent);
assert(es == Acad::eOk);

es = ent->close();
assert(es == Acad::eOk);

es = pSpaceRecord->close();
assert(es == Acad::eOk);

return es;
}
 楼主| 发表于 2004-10-1 23:30:00 | 显示全部楼层
不好意思。我再发一次 void AppmytoolCloReg()
{
ads_point pt1,pt2,pt;
AcGePoint2dArray point_Array;
AcDbObjectId IdObj,faceId;
AcDbEntity *pEnt=NULL;
AcGePoint3d pA(0,0,0),pB(100,0,0),pC(100,100,0),pD(0,100,0);
AcDbFace *pFace=new AcDbFace(pA,pB,pC,pD);
postToDatabase(pFace,faceId); int stat=1;
stat=acedGetPoint(NULL,"选择点(ESC结束)\n",pt1);
if(stat==RTCAN)
return;
point_Array.append(asPnt2d(pt1));
while(1)
{
acdbPointSet(pt1, pt2);
stat=acedGetPoint(pt1,"选择点,(ESC结束)\n",pt1);
acedGrDraw(pt2, pt1, 1, 0);
if(stat==RTCAN)
break;
point_Array.append(asPnt2d(pt1));
}
AcDbPolyline *ClosePolyline=new AcDbPolyline();
for(int i=0;i<point_Array.length();i++)
{
AcGePoint2d pTmp=point_Array.at(i);
ClosePolyline->addVertexAt(i,pTmp,0,-1,-1);
} ClosePolyline->setColorIndex(1);
ClosePolyline->setClosed(Adesk::kTrue);
postToDatabase(ClosePolyline,IdObj);//添加实体数据库中 acdbOpenAcDbEntity(pEnt,IdObj,AcDb::kForRead);
AcDbPolyline *pPoly=AcDbPolyline::cast(pEnt); AcDbVoidPtrArray entities,regions;
entities.append(pFace);
entities.append(pPoly);
AcDbRegion::createFromCurves(entities, regions);
if (regions.length() < 1)
{
acutPrintf("构造闭合区域错误\n");
}
assert(pRegion != NULL);
AcDbRegion *pRegion = new AcDbRegion;

for ( i = 0; i < regions.length(); i++)
{

if(Acad::eOk!=pRegion->booleanOper(AcDb::kBoolIntersect,(AcDbRegion*)regions))
acutPrintf("有问题\n");
delete (AcRxObject*)regions;

}
double regArea;
pRegion->getArea(regArea);
pRegion->close();
pEnt->close(); acutPrintf("area=%0.3f\n",regArea);
} Acad::ErrorStatus
postToDatabase(/*[in]*/AcDbEntity* pEnt,/*[out]*/AcDbObjectId& idObj) {
Acad::ErrorStatus es;
AcDbBlockTable* pBlockTable;
AcDbBlockTableRecord* pSpaceRecord;

if (acdbHostApplicationServices()->workingDatabase()==NULL)
return Acad::eNoDatabase;


if ((es = acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForRead))==Acad::eOk){


if ((es = pBlockTable->getAt(ACDB_MODEL_SPACE, pSpaceRecord, AcDb::kForWrite))==Acad::eOk){


if ((es = pSpaceRecord->appendAcDbEntity(idObj, pEnt))==Acad::eOk)
pEnt->close();
pSpaceRecord->close();
}
pBlockTable->close(); }
return es;
}
发表于 2008-9-22 17:39:00 | 显示全部楼层
先求交点,再创建一个新的面或多线段,面积就出来了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 15:59 , Processed in 0.171862 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表