当前位置: 首页>>代码示例>>C++>>正文


C++ arr::clear方法代码示例

本文整理汇总了C++中arr::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ arr::clear方法的具体用法?C++ arr::clear怎么用?C++ arr::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在arr的用法示例。


在下文中一共展示了arr::clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getConstraints

void SocSystem_Analytical::getConstraints(arr& cdir,arr& coff,uint t,const arr& qt){
  cdir.clear();
  coff.clear();
#ifndef USE_TRUNCATION
   return;
#endif
  uint i,M=obstacles.d0;
  arr d;
  
#if 0 //direct and clean way to do it -- but depends simple scenario
  cdir.resize(M,x.N);
  coff.resize(M);
  for(i=0;i<M;i++){
    cdir[i] = qt-obstacles[i];
    coff(i) = scalarProduct(cdir[i],obstacles[i]);
  }
#elif 1 //assume that the task vector is a list of scalars, each constrained >0
  arr J,y;
  for(i=0;i<M;i++){
    real haty = norm(x-obstacles[i]);
    if(haty>.5) continue; //that's good enough -> don't add the constraint
    J = (x-obstacles[i])/norm(x-obstacles[i]);
    coff.append(-haty + scalarProduct(J,x));
    cdir.append(J);
  }
  cdir.reshape(coff.N,x.N);
  coff.reshape(coff.N);
#else //messy: try to combine all constraints into a single scalar, doesn't really work...
  //first compute squared collision meassure...
  arr J(1,qt.N),phiHatQ(1);
  J.setZero();
  phiHatQ.setZero();
  for(i=0;i<obstacles.d0;i++){
    real margin = .25;
    real d = 1.-norm(x-obstacles[i])/margin;
    //if(d<0) continue;
    //phiHatQ(0) += d*d;
    //J += (2.*d/margin)*(obstacles[i]-x)/norm(x-obstacles[i]);
    phiHatQ(0) += d;
    J += (1./margin)*(obstacles[i]-x)/norm(x-obstacles[i]);
  }
  //...then add a single constraint
  if(phiHatQ(0)>0.){ //potential violation, else discard
    cdir.append(-J);
    coff.append(phiHatQ-scalarProduct(J,x)-1.);
    cdir.reshape(1,x.N);
    coff.reshape(1);
  }
#endif
}
开发者ID:wensun,项目名称:probCollision,代码行数:50,代码来源:soc_system_analytical.cpp


注:本文中的arr::clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。