明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2238|回复: 2

请问intersectWith函数怎么用?能给个例子吗?谢谢

[复制链接]
发表于 2004-6-3 19:51 | 显示全部楼层 |阅读模式
发表于 2004-6-3 21:58 | 显示全部楼层
参考:
  1. void chkints()
  2. {
  3.   ads_point pickPt;
  4.   ads_name ent;  AcDbObjectId entId1, entId2;
  5.   AcDbEntity *pEnt1, *pEnt2;
  6.   AcGePoint3dArray intPoints;  // This array holds the intersecting points
  7.   AcGePoint3d intPt;
  8.   AcGePoint3d r1, r2, r3, r4;
  9.   AcGeVector3d transVec(-0.1, 0.1, 0.0);  // Point translation vector
  10.   AcGeMatrix3d transMat;          // Translation matrix
  11.   char kw[10];
  12.   int extVal = 0; // Extend value, 0 = no, 1 = fist entitity,
  13.           // 2 = second entity, 3 = both entities
  14.           // see intersectWith() function below  int rc;  rc = acedEntSel("\nSelect first entity to test for intersection: ",
  15.           ent, pickPt);
  16.   switch(rc)
  17.   {
  18.     case RTCAN:
  19.       acutPrintf("\nUser canceled.");
  20.       return;
  21.     break;    case RTERROR:
  22.       acutPrintf("\nNothing selected.");
  23.       return;
  24.     break;
  25.   }// switch  acdbGetObjectId(entId1, ent);  // Is the entity a line, arc or circle?
  26.   // Here we limit ourselves to lines, arcs
  27.   // and circles, because that is what we created
  28.   // in the last application.
  29.   acdbOpenAcDbEntity(pEnt1, entId1, AcDb::kForRead);
  30.   if(!(pEnt1->isKindOf(AcDbLine::desc())     ||
  31.      pEnt1->isKindOf(AcDbCircle::desc()) ||
  32.      pEnt1->isKindOf(AcDbArc::desc())
  33.     )
  34.      )
  35.   {
  36.     acutPrintf("\nNot a line, arc or circle entity.");
  37.     pEnt1->close();
  38.     return;
  39.   }  // Now get the second entity
  40.   rc = acedEntSel("\nSelect second entity to test for intersection: ",
  41.           ent, pickPt);
  42.   switch(rc)
  43.   {
  44.     case RTCAN:
  45.       acutPrintf("\nUser canceled.");
  46.       return;
  47.     break;    case RTERROR:
  48.       acutPrintf("\nNothing selected.");
  49.       return;
  50.     break;
  51.   }// switch  acdbGetObjectId(entId2, ent);
  52.   acdbOpenAcDbEntity(pEnt2, entId2, AcDb::kForRead);  // Is the second entity the same as the first?
  53.   if(entId1 == entId2)
  54.   {
  55.     acutPrintf("\nSame entity selected!");
  56.     pEnt1->close();
  57.     pEnt2->close();
  58.     return;
  59.   }  // Is the second entity a line, arc or circle?
  60.   if(!(pEnt2->isKindOf(AcDbLine::desc())     ||
  61.      pEnt2->isKindOf(AcDbCircle::desc()) ||
  62.      pEnt2->isKindOf(AcDbArc::desc())
  63.     )
  64.      )
  65.   {
  66.     acutPrintf("\nNot a line, arc or circle entity.");
  67.     pEnt1->close();
  68.     pEnt2->close();
  69.     return;
  70.   }  // If the first entity is not a circle
  71.   // ask if the user wants to extend the entity
  72.   // for apparent intersection
  73.   if(!pEnt1->isKindOf(AcDbCircle::desc()))
  74.   {
  75.     pEnt1->highlight();    acedInitGet(NULL, "Yes No");
  76.     rc = acedGetKword("\nExtend the highlighted entity - [Yes/No]<No>: ", kw);    pEnt1->unhighlight();    switch(rc)
  77.     {
  78.       case RTCAN:
  79.       case RTERROR:
  80.         acutPrintf("\nError with acedGetKword(). ");
  81.         pEnt1->close();
  82.         pEnt2->close();
  83.         return;
  84.       break;      case RTNONE:
  85.       break;      case RTNORM:
  86.         if(strcmp(kw, "Yes") == 0)
  87.         {
  88.           extVal = 1;
  89.         }
  90.       break;
  91.     }
  92.   }  // If the second entity is not a circle
  93.   // ask if the user wants to extend the entity
  94.   // for apparent intersection
  95.   if(!pEnt2->isKindOf(AcDbCircle::desc()))
  96.   {
  97.     pEnt2->highlight();    acedInitGet(NULL, "Yes No");
  98.     rc = acedGetKword("\nExtend the highlighted entity - [Yes/No]<No>: ", kw);    pEnt2->unhighlight();    switch(rc)
  99.     {
  100.       case RTCAN:
  101.       case RTERROR:
  102.         acutPrintf("\nError with acedGetKword(). ");
  103.         pEnt1->close();
  104.         pEnt2->close();
  105.         return;
  106.       break;      case RTNONE:
  107.       break;      case RTNORM:
  108.         if(strcmp(kw, "Yes") == 0)
  109.         {
  110.           if(extVal == 1)
  111.           {
  112.             extVal = 3;  // Both
  113.           }
  114.           else
  115.           {
  116.             extVal = 2;  // Second only
  117.           }
  118.         }
  119.       break;
  120.     }
  121.   }
  122.   // Does the first selected entity
  123.   // intersect with the second enity?
  124.   switch(extVal)
  125.   {
  126.     case 0 :
  127.       pEnt1->intersectWith(pEnt2, AcDb::kOnBothOperands, intPoints);
  128.       // No extension on either entity
  129.     break;    case 1 :
  130.       pEnt1->intersectWith(pEnt2, AcDb::kExtendThis, intPoints);
  131.       // Extend the first entity
  132.     break;    case 2 :
  133.       pEnt1->intersectWith(pEnt2, AcDb::kExtendArg, intPoints);
  134.       // Extend the second entity
  135.     break;    case 3 :
  136.       pEnt1->intersectWith(pEnt2, AcDb::kExtendBoth, intPoints);
  137.       // Extend both entities
  138.     break;  }  pEnt1->close();
  139.   pEnt2->close();  // Here is an example of the AcGePoint3dArray class
  140.   // as well as a demonstration of how to use translation
  141.   // matricies AcGeMatrix3d
  142.   if(! intPoints.isEmpty())
  143.   {
  144.     for(int i = 0; i < intPoints.length(); i++)
  145.     {
  146.       intPt = intPoints.at(i);      transMat = AcGeMatrix3d(transVec);
  147.       r1 = intPt;
  148.       r1.transformBy(transMat);
  149.       transVec.set(0.0, -0.2, 0.0);
  150.       transMat = AcGeMatrix3d(transVec);
  151.       r2 = r1;
  152.       r2.transformBy(transMat);      acedGrDraw((double*)(&r1), (double*)(&r2), 3, 0);      transVec.set(0.2, 0.0, 0.0);
  153.       transMat = AcGeMatrix3d(transVec);
  154.       r3 = r2;
  155.       r3.transformBy(transVec);      acedGrDraw((double*)(&r2), (double*)(&r3), 3, 0);      transVec.set(0.0, 0.2, 0.0);
  156.       transMat = AcGeMatrix3d(transVec);
  157.       r4 = r3;
  158.       r4.transformBy(transVec);      acedGrDraw((double*)(&r3), (double*)(&r4), 3, 0);
  159.       acedGrDraw((double*)(&r4), (double*)(&r1), 3, 0);      transVec.set(-0.1, 0.1, 0.0);      acutPrintf("\nIntersection point = (%.2lf %.2lf %.2lf)",
  160.             intPt.x, intPt.y, intPt.z);
  161.     }
  162.   }
  163. }
复制代码
发表于 2018-5-17 11:11 | 显示全部楼层

C++?怎么运行呢?只知道有VBA,里斯普可以直接用,麻烦回一声哈。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-26 01:17 , Processed in 0.332160 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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