|
[code]
static const double PI = 3.141592653589793;
static double dVal = 0.2;
static double delta(double a1, double a2)
{
double ang;
if (a1 > a2 + PI)
ang = (a2 + PI + PI) - a1;
else if (a2 > a1 + PI)
ang = a2 - a1 - PI - PI;
else
ang = a2 - a1;
return ang;
}
static void isPointInside(AcGePoint3d inPt, ads_name ename)
{
AcDbObjectId objId;
acdbGetObjectId(objId, ename);
AcDbObjectPointer<AcDbCurve> pPoly(objId, AcDb::kForRead);
if (pPoly.openStatus() == Acad::eOk)
{
if (!pPoly->isClosed())
{
acutPrintf(_T("\n*** Curve is not closed. ")); return;
}
AcGePoint3d P; acdbUcs2Wcs(asDblArray(inPt), asDblArray(P), false);
AcGePoint3d ClosestPoint; pPoly->getClosestPointTo(P, ClosestPoint);
if (P.isEqualTo(ClosestPoint))
{
acutPrintf(_T("\n*** Point is on curve. ")); return;
}
double ClosestParam, EndParam;
pPoly->getParamAtPoint(ClosestPoint, ClosestParam);
acdbWcs2Ucs(asDblArray(ClosestPoint), asDblArray(ClosestPoint), false);
pPoly->getEndParam(EndParam);
double Param1 = 0.0, Param2 = dVal, Deflection = 0.0;
AcGePoint3d StartPT; pPoly->getStartPoint(StartPT);
acdbWcs2Ucs(asDblArray(StartPT), asDblArray(StartPT), false);
double a1 = acutAngle(asDblArray(inPt), asDblArray(StartPT));
while (Param2 <= EndParam)
{
Param2 = min(Param2, EndParam);
if (Param1 < ClosestParam && ClosestParam < Param2)
{
double a2 = acutAngle(asDblArray(inPt), asDblArray(ClosestPoint));
Deflection = Deflection + delta(a1, a2);
a1 = a2;
}
AcGePoint3d P;
while (pPoly->getPointAtParam(Param2, P) != Acad::eOk)
Param2 = Param2 + dVal;
acdbWcs2Ucs(asDblArray(P), asDblArray(P), false);
double a2 = acutAngle(asDblArray(inPt), asDblArray(P));
Deflection = Deflection + delta(a1, a2);
a1 = a2;
Param1 = Param2;
Param2 = Param2 + dVal;
}
if (abs(Deflection) > 4)
acutPrintf(_T("\n*** Point is inside. "));
else
acutPrintf(_T("\n*** Point is outside. "));
}
}
static void LESQptInside17_TESTER(void)
{
ads_name ename; ads_point ptres; AcGePoint3d pt;
if (acedEntSel(_T("\nSelect curve:"), ename, ptres) != RTNORM) return;
if (acedGetPoint(NULL, _T("\nTest point: "), asDblArray(pt)) != RTNORM) return;
isPointInside(pt, ename);
}[/code] |
|