- UID
- 25782
- 积分
- 1453
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-1-15
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
学习ARX一周,今天终于写出了第一段代码,请大家批评指正.
射线法测试点和闭合曲线的位置关系。
考虑了 射线与曲线相切的特殊情况。
- Adesk::Boolean PointRelationToCurve(ads_point pt,AcDbCurve *pPline)
- {
- //acutPrintf("x %d",pt[X]);
- ads_point tmpP;
- AcDbRay *pRay =new AcDbRay();
- pRay->setBasePoint(asPnt3d(pt));
- pRay->setUnitDir(AcGeVector3d(1.0,0.0,0.0));
- AcGePoint3d pointOnCurve;
- pPline->getClosestPointTo(asPnt3d(pt),pointOnCurve);
- ads_point pt1 = {pointOnCurve.x,pointOnCurve.y,pointOnCurve.z};
- if(acutDistance(pt,pt1)==0)
- {
- acutPrintf("\nON");
- return Adesk::kTrue;
- }
- AcGePoint3dArray points,points1;
- pPline->intersectWith(pRay,AcDb::kOnBothOperands,points);
- acutPrintf("\n交点数目:%d", points.length());
- AcGeVector3d fd,fd1,fd2;
- pRay->getFirstDeriv(asPnt3d(pt),fd);
- pRay->close();
- AcDbRay *pRay1;
- AcGePoint3d tmpPoint;
- ads_name tmpE;
- double min=0.00002;
- double paramBegin,paramEnd,param,param1,param2,angle1,angle2;
- for(int i=0;i<points.length();i++)
- {
- //acutPrintf("\n交点%d:%d,%d,%d",i,points[i].x,points[i].y,points[i].z);
- //pPline->getFirstDeriv(points[i],fd1);
- pPline->getStartParam(paramBegin);
- pPline->getEndParam(paramEnd);
- pPline->getParamAtPoint(points[i],param);
- /*addline(points[i]);*/
- if (param== paramBegin)
- {
- param1=paramEnd-min;
- param2=paramBegin+min;
- }
- else if (param== paramEnd )
- {
- param1=paramEnd-min;
- param2=paramBegin+min;
- }
- else
- {
- param1=param-min;
- param2=param+min;
- }
- pPline->getFirstDeriv(param1,fd1);
- pPline->getFirstDeriv(param2,fd2);
- /*acutPrintf("\n1 %f:%f",param1,fd1.angleTo(fd));
- acutPrintf(" %f %f %f",fd1.x,fd1.y,fd1.z);
- acutPrintf("\n2 %f:%f",param2,fd2.angleTo(fd));
- acutPrintf(" %f %f %f",fd2.x,fd2.y,fd2.z);
- acutPrintf("\n");*/
- int valid=1;
- if ((fd1.y>0)&&(fd2.y<0)||(fd1.y<0)&&(fd2.y>0))
- {
- valid=0;
- acutPrintf("\n!!!");
- }
- /*acdbEntLast( tmpE);
- acedGetPoint(NULL,"",tmpP);
- acdbEntDel(tmpE);*/
- if (valid==1)
- {
- points1.append(points[i]);
- }
- }
- //acutPrintf("\n交点数目:%d", points1.length());
- if((points1.length()%2)==1)
- {
- acutPrintf("\nIN");
- return Adesk::kTrue;
- }
- else
- {
- acutPrintf("\nOUT");
- return Adesk::kFalse;
- }
-
- }
复制代码 |
|