ITPub博客

首页 > Linux操作系统 > Linux操作系统 > acdbSpline变acdbPolyline的函数

acdbSpline变acdbPolyline的函数

原创 Linux操作系统 作者:xuhuai1 时间:2009-06-23 10:15:24 0 删除 编辑

bool CCovertSpline::getSplineSamplePoints(AcDbSpline *&spline, AcGePoint3dArray &pnts)
{
 assert(spline != NULL);

 double dbStartParam,dbEndParam;
 if (Acad::eOk != spline->getStartParam(dbStartParam) || Acad::eOk != spline->getEndParam(dbEndParam))
 {
  return false;
 }
 double dStep=m_nImitateMinLenth;
 double dLen1 = 0.0;
 double dLen2 = 0.0;
 double dlength = 0.0;
 spline->getDistAtParam(dbStartParam,dLen1);
 spline->getDistAtParam(dbEndParam,dLen2);
 dlength = dLen2 - dLen1;

 double dPreDis = 0.0;
 
 double dMidDis = 0.0;
 AcGePoint3d pnt;
 AcGePoint3d predpnt,nextpnt,midPnt;
 spline->getStartPoint(pnt);
 pnts.append(pnt);
 predpnt = pnt;
 if (dlength <0.26)
 {
  dStep /= 2;
  while (dStep > dlength && dStep > 0.001)
  {
   dStep /= 2;
  }
 }
 double dNextDis = dStep;
 do
 {
  /*
  *calculate a next point on segment 
  */
  bool bFind = false;
  while (dPreDis < dNextDis && (dNextDis < dlength))
  {
   dMidDis = (dPreDis + dNextDis) / 2;
   // get the next step point
   Acad::ErrorStatus es;
   es = spline->getPointAtDist(dMidDis,midPnt);
   es = spline->getPointAtDist(dNextDis,nextpnt);
   
   assert(midPnt != nextpnt);
   assert(nextpnt != predpnt);
   assert(predpnt != midPnt);
   AcGeVector2d v1 = AcGePoint2d(midPnt.x,midPnt.y)-AcGePoint2d(predpnt.x,predpnt.y);
   AcGeVector2d v2 = AcGePoint2d(nextpnt.x,nextpnt.y)-AcGePoint2d(predpnt.x,predpnt.y);
   // the bulge less than 0.002
   double dBules = tan(v1.angleTo(v2));
   if(dBules > 0.004 )
   {
    if (dNextDis - dPreDis <0.01)
    {
     break;
    }
    dNextDis -= (dNextDis-dMidDis)/2;
   
   }
   else if(dBules < 0.002)
   {
    if (dlength - dNextDis  <0.001)
    {
     break;
    }
    dNextDis += (dNextDis-dMidDis)/2;
    
   }
   else
   {
    break;
   }
   assert(dNextDis > dPreDis);
  }
  dPreDis = dNextDis;
  predpnt = nextpnt;
  pnts.append(midPnt);
  pnts.append(predpnt);
  if(dNextDis + dStep > dlength && dStep > 0.007)
  {
   dStep /=2;
  }
  dNextDis += dStep; 
 } while(dNextDis spline->getDistAtPoint(pnts.last(),dMidDis);
 spline->getPointAtDist((dMidDis+dlength)/2,midPnt);
 pnts.append(midPnt);
 //AcDbCircle *pc = new AcDbCircle;
 //pc->setCenter(midPnt);
 //pc->setColorIndex(1);
 //pc->setRadius(0.5);
 //AddToModelSpace(pc);
 //pc->close();
 spline->getEndPoint(pnt);
 pnts.append(pnt);
 
 return (pnts.length() > 2);
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12560256/viewspace-607223/,如需转载,请注明出处,否则将追究法律责任。

下一篇: odbc写excel
请登录后发表评论 登录
全部评论

注册时间:2008-09-03

  • 博文量
    13
  • 访问量
    26890