构造自己的射线算法,测试点是否在曲线内的ARX完整代码...

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2007-09-19 17:33:20

  // includes from ObjectARX Wizard

#include "acdb.h" // acdb definitions

#include "adslib.h" // ads defs

#include "aced.h" // aced stuff

#include "dbsymtb.h" // symboltables

#include "rxregsvc.h" // unlock application

#include "dbcurve.h"

#include "gevec3d.h"

#include "dbray.h"

#include "dbautil.h"

#include "geassign.h"

#include "dbents.h"

 

// entry point for this application

extern "C" AcRx::AppRetCode acrxEntryPoint( AcRx::AppMsgCode msg, void* );

// message handlers

 

// helper functions

static void initApp (void);

static void unloadApp(void);

 

void utilsisinside (void );

 

 

// end of declaration

 

/////////////////////////////////////////////////////////////////////

// acrxEntryPoint(internal)

// This function is the entry point for your application.

/////////////////////////////////////////////////////////////////////

AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* ptr)

{

switch (msg) {

case AcRx::kInitAppMsg:

acrxUnlockApplication(ptr);

initApp();

break;

case AcRx::kUnloadAppMsg:

unloadApp();

break;

default:

break;

}

return AcRx::kRetOK;

}

 

static void initApp(void)

{

// register your autocad commands

acedRegCmds->addCommand("UTILS", "ISINSIDE", "ISINSIDE", ACRX_CMD_MODAL,

utilsisinside);

 

} // END initApp()

 

static void unloadApp(void)

{

// unregister your autocad commands

acedRegCmds->removeGroup("UTILS");

// END unloadApp()

}

 

 

enum IncidenceType {

kIncidenceToLeft = 0,

kIncidenceToRight = 1,

kIncidenceToFront =2,

kIncidenceUnknown };

 

IncidenceType CurveIncidence(AcDbCurve*pCurve, double param, AcGeVector3d

dir, AcGeVector3d normal )

{

AcGeVector3d deriv1;

 

pCurve->getFirstDeriv( param, deriv1 );

if( deriv1.isParallelTo( dir )) {

// need second degree analysis

AcGeVector3d deriv2;

pCurve->getSecondDeriv( param, deriv2 );

if( deriv2.isZeroLength() || deriv2.isParallelTo( dir ) ) {

return kIncidenceToFront;

} else if(deriv2.crossProduct( dir ).dotProduct( normal ) < 0 ) {

return kIncidenceToRight;

} else {

return kIncidenceToLeft;

 

}

}

 

if( deriv1.crossProduct( dir ).dotProduct( normal ) < 0 ) {

return kIncidenceToLeft;

} else {

return kIncidenceToRight;

}

}

 

Adesk::Boolean IsInsideCurve(AcDbCurve*pCurve, AcGePoint3d testPt )

{

if(!pCurve->isClosed() || !pCurve) {

// cannot be inside

return Adesk::kFalse;

}

 

Acad::ErrorStatus es;

 

AcDb2dPolyline*p2dPoly = AcDb2dPolyline::cast(pCurve);

if( p2dPoly != NULL && p2dPoly->polyType() != AcDb::k2dSimplePoly ) {

// Not supported

return Adesk::kFalse;

}

 

AcGePoint3d ptOnCurve;

es = pCurve->getClosestPointTo(testPt, ptOnCurve );

if( testPt == ptOnCurve ) {

return Adesk::kTrue;

}

 

// check its planar

AcGePlane plane;

AcDb::Planarity planarity;

es = pCurve->getPlane(plane, planarity );

if( es != Acad::eOk || planarity != AcDb::kPlanar ) {

return Adesk::kFalse;

}

 

// make the test ray from the plane

AcGeVector3d normal = plane.normal();

AcGeVector3d testVector = normal.perpVector();

AcDbRay ray;

ray.setBasePoint(testPt);

ray.setUnitDir(testVector);

 

AcGePoint3dArray IntersectionPoints;

 

// fire the ray at the curve

es = pCurve->intersectWith(&ray, AcDb::kOnBothOperands,

IntersectionPoints);

if(es != Acad::eOk) {

return Adesk::kFalse;

}

int numberOfInters = IntersectionPoints.length();

 

if(numberOfInters == 0) {

// must be outside

return Adesk::kFalse;

}

int nGlancingHits = 0;

double epsilon = 2e-6; // ( trust me on this )

for( int i=0;i < numberOfInters; i++ ) {

 

// get the first point, and get its parameter

AcGePoint3d hitPt = IntersectionPoints;

double hitParam;

es = pCurve->getParamAtPoint(hitPt, hitParam );

if(es != Acad::eOk) {

return Adesk::kFalse;

}

double inParam = hitParam - epsilon;

double outParam = hitParam + epsilon;

 

IncidenceType inIncidence = CurveIncidence(pCurve, inParam,

testVector, normal );

IncidenceType outIncidence = CurveIncidence(pCurve, outParam,

testVector, normal );

 

[1] [2]  下一页

Tags:

作者:佚名

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
按字母检索: A - B - C - D - E - F - G - H - I - J - K - L - M - N - O - P - Q - R - S - T - U - V - W - X - Y - Z -
按声母检索: A - B - C - D - E - F - G - H - J - K - L - M - N - O - P - Q - R - S - T - W - X - Y - Z - 数字 - 符号 -
  • 金字塔软件网 - 最专业的行业软件网 JztSoft.COM