zoukankan      html  css  js  c++  java
  • 【转载】曲线打断、求交点

    在08科创项目,绘图助手工具箱中的第二、三个命令RTLine、STLine就是使用了曲线打断的函数,为实现这个命令我查阅了多个网页,找出了几个重要的函数,分别是打断曲线的getSplitCurves、求两曲线交点的intersectwith。感谢ObjectARX编程站,让我找到很多ObjectARX方面我需要的东西,以下就是我转载的文章:

    创建自己的曲线打断命令

     原文地址:http://www.objectarx.net/bbs/viewthread.php?tid=1655&extra=page%3D1%26amp%3Bfilter%3Ddigest

     void drawEntity(AcDbEntity* pEntity);
     
    bool breakCurve(AcDbCurve* curve, AcGePoint3d pt);
     
    bool breakCurve(AcDbCurve* curve, AcGePoint3d p1, AcGePoint3d p2);


     
    static void Mybreak2008_Mybreak(void)
     
    {
         
    // Add your code for command Mybreak2008._Mybreak here
         ads_point pt1,pt2;
         ads_name entName;
         Acad::ErrorStatus es;
         
    int ret;
         ACHAR kWord[
    100];


         
    if (acedEntSel(_T("\n选择所要打断的曲线:"), entName, pt1) !=RTNORM)
         
    {
             
    return;
         }

         AcDbObjectId entId;
         AcDbCurve 
    *pCurve=NULL;
         AcDbEntity 
    *pEnt = NULL;
         es 
    = acdbGetObjectId(entId, entName);
         
    if (es != Acad::eOk)
         
    {
            
    return;
         }

         acdbOpenObject(pEnt, entId, AcDb::kForWrite);
         
    if (pEnt->isKindOf(AcDbCurve::desc()))
         
    {
            pCurve 
    = AcDbCurve::cast(pEnt);
            
    if (pCurve != NULL)
            
    {
               acedInitGet (NULL, _T(
    "F"));
               ret
    =acedGetPoint(NULL,_T("\n指定第二个打断点或[第一点(F)]:"),pt2);
               
    switch (ret)
               
    {
                   
    case RTKWORD:
                       ret
    =acedGetInput(kWord);
                       
    if ( ret!= RTNORM )
                           
    break ;
                       acedInitGet(RSG_NONULL, _T(
    ""));
                       ret
    =acedGetPoint(NULL,_T("\n指定第一个打断点:"),pt1);
                       
    if (ret!=RTNORM)
                           
    break;
                       acedInitGet(RSG_NONULL, _T(
    ""));
                       ret
    =acedGetPoint(NULL,_T("\n指定第二个打断点:"),pt2);
                       
    if (ret!=RTNORM)
                          
    break;
                       breakCurve(pCurve,asPnt3d(pt1), asPnt3d(pt2));
                       
    break;
                   
    case RTNONE:
                       breakCurve(pCurve,asPnt3d(pt1));
                       
    break;
                    
    case RTNORM:
                       breakCurve(pCurve,asPnt3d(pt1), asPnt3d(pt2));
                        
    break;
                  
    default:
                       
    break;
               }

            }

         }

         pEnt
    ->close();
     }



     
    //以下为函数
     
    //打断于点
     bool breakCurve(AcDbCurve* curve,AcGePoint3d pt)
     
    {
         AcGePoint3d p1;
         curve
    ->getClosestPointTo(pt,p1);
         
    double param;
         curve
    ->getParamAtPoint(p1,param);
         AcGeDoubleArray 
    params;
         
    params.append(param);
         AcDbVoidPtrArray curveSegments;
         curve
    ->getSplitCurves(params, curveSegments);
         AcDbEntity
    * ent =NULL;
         
    if (curveSegments.length()==2)
         
    {
             ent
    =(AcDbEntity*)curveSegments[0];
             drawEntity(ent);
             ent
    ->close();
             ent
    =(AcDbEntity*)curveSegments[1];
             drawEntity(ent);
             ent
    ->close();
             curve
    ->erase();
         }

         
    else
         
    {
             curve
    ->close();
         }
       
         
    return true ;
     }

     
    //两点打断
     bool breakCurve(AcDbCurve* curve, AcGePoint3d p1, AcGePoint3d p2)
     
    {
         AcGePoint3d p11;
         curve
    ->getClosestPointTo(p1,p11);
         
    double param1;
         curve
    ->getParamAtPoint(p11,param1);
         AcGePoint3d p21;
         curve
    ->getClosestPointTo(p2,p21);
         
    double param2;
         curve
    ->getParamAtPoint(p21,param2);
         AcGeDoubleArray 
    params;
         
    if (param1<param2)
         
    {
             
    params.append(param1);
             
    params.append(param2);
         }

         
    else
         
    {
             
    params.append(param2);
             
    params.append(param1);
         }

         AcDbVoidPtrArray curveSegments;
         curve
    ->getSplitCurves(params, curveSegments);
         AcDbEntity
    * ent =NULL;
         
    if (curveSegments.length()==2)
         
    {
             ent
    =(AcDbEntity*)curveSegments[1];
             drawEntity(ent);
             ent
    ->close();
         }

         
    else if (curveSegments.length()==3)
         
    {
             ent
    =(AcDbEntity*)curveSegments[0];
             drawEntity(ent);
             ent
    ->close();
             ent
    =(AcDbEntity*)curveSegments[2];
             drawEntity(ent);
             ent
    ->close();
         }

         curve
    ->erase();
         
    return true ;
     }

     
    //绘制打断的曲线
     void drawEntity(AcDbEntity* pEntity)
     
    {
         AcDbBlockTable 
    *pBlockTable;
         acdbHostApplicationServices()
    ->workingDatabase()
             
    ->getSymbolTable(pBlockTable, AcDb::kForRead);
         AcDbBlockTableRecord 
    *brec;
         resbuf tilemode;
         acedGetVar(_T(
    "TILEMODE"),&tilemode);
         
    int tile=tilemode.resval.rint;
         
    if (tile)
             pBlockTable
    ->getAt(ACDB_MODEL_SPACE, brec,AcDb::kForWrite);
         
    else
             pBlockTable
    ->getAt(ACDB_PAPER_SPACE, brec,AcDb::kForWrite);
         pBlockTable
    ->close();
         AcDbObjectId entid;
         brec
    ->appendAcDbEntity(entid, pEntity);
          brec
    ->close();     
      }
  • 相关阅读:
    [CF1483C] Skyline Photo
    [CF1483B] Playlist
    [CF1483A] Basic Diplomacy
    [CF1329C] Drazil Likes Heap
    [CF1329B] Dreamoon Likes Sequences
    [CF1329A] Dreamoon Likes Coloring
    [CF96E] Horse Races
    [ICPC2020济南J] Tree Constructer
    [ICPC2020济南L] Bit Sequence
    [ICPC2020济南G] Xor Transformation
  • 原文地址:https://www.cnblogs.com/alonecat06/p/1458200.html
Copyright © 2011-2022 走看看