ARX can determine the positional relationship between the point and AcBrFace through the AcBr API.
AcBrFace::getPointRelationToFace Function
AcBr::ErrorStatus
getPointRelationToFace(
const AcGePoint3d& point,
AcBr::Relation& relation) const;
point | AcGe point object |
relation | AcBr relation enum |
AcBr::Relation Enum
These are the ErrorStatus enumerated values used by getPointRelationToXXX() and getCurveRelationToXXX() functions. These enumerated types and the functions that use them are deprecated in favor of the newer getPointContainment() and getLineContainment() functions, along with the new AcGe::PointContainment enumerated type.
Relation.
The following is the ARX implementation code:static void BrepPointCheckPoint(void)
{
Acad::ErrorStatus es;
AcBr::ErrorStatus ebr;
ads_name en;
ads_point pt;
if (acedEntSel(_T("\nSelect contour: "), en, pt) != RTNORM)
return;
AcDbObjectId eId; acdbGetObjectId(eId,en);
AcDbObjectPointer<AcDbCurve> pline(eId,AcDb::kForRead) ;
if ((es = pline.openStatus()) != Acad::eOk) {
acutPrintf(_T("\npline.openStatus()=%s"),acadErrorStatusText(es));
return;
}
if (acedGetPoint(pt,_T("\nPick point: "), pt) != RTNORM)
return;
AcDbVoidPtrArray ar, regions;
ar.append(pline.object());
if ((es = AcDbRegion::createFromCurves(ar,regions)) != Acad::eOk) {
acutPrintf(_T("\nAcDbRegion::createFromCurves(ar,regions)=%s"),acadErrorStatusText(es));
return;
}
AcDbRegion reg; reg.copyFrom((AcDbRegion *)regions[0]);
for (int i=0; i<regions.length();i++) delete regions[i];
AcBrBrep brEnt; ebr = brEnt.set(reg);
if (ebr != AcBr::eOk) {
acutPrintf(_T("\nbrEnt.set(sol)=%s"),acadErrorStatusText((Acad::ErrorStatus)(Adesk::UInt32)ebr));
return;
}
AcGe::PointContainment pDesc;
AcBrEntity *pCont = NULL;
AcBrBrepFaceTraverser brepFaceTrav; brepFaceTrav.setBrep(brEnt);
AcBr::ErrorStatus err = AcBr::eInvalidInput;
while (!brepFaceTrav.done()) {
AcBrFace brFace; brepFaceTrav.getFace(brFace);
err = brFace.getPointContainment(asPnt3d(pt),pDesc,pCont);
if (err == Acad::eOk && pDesc == AcGe::kInside) {
acedAlert(_T("In")); return;
} else if (err == Acad::eOk && pDesc == AcGe::kOnBoundary) {
acedAlert(_T("On")); return;
}
brepFaceTrav.next();
}
if (err == Acad::eOk) {
acedAlert(_T("Out"));
} else {
acedAlert(_T("Unknown error"));
}
return;
}
Below we use the AcBr library function encapsulated by the XDRX API to translate the above ARX code to LISP:
Define a function _isPtInPoly
Parameters: pl ---- closed curve
pnt ---- test point
Return value: 1: outside, 2: inside, 3, on the boundary
(defun _isPtInPoly
(pl pnt
/ ss brep tr face region relation
) (if (setq ss
(xdrx_region_make pl t
)) ;PL generates REGION ;;Construct AcBrBrep object
(setq tr
(xdbr::constructor
"brepfacetraverser" brep
)) ;;Build Brep to Face traverser
;;FACE traversal
;;The traverser has not reached the end, looping
(setq face
(xdbr::getpropertyvalue tr
"face")) ;;Get the AcBrFace object at the current traversal position
(setq relation
(xdbr::getpropertyvalue
face
"PointRelationToFace"
pnt
)
)
;;Use the PointRelationToFace method to determine the positional relationship between points and faces
(xdrx_object_release face)
;;Release the face object
(xdbr::traverser:next tr)
;;The traverser points to the next face
)
(xdrx_entity_delete region)
;;Delete temporary REGION
(xdrx_object_release tr brep)
;;Release AcBrBrep object and traverser object
)
)
relation
)
The following is a point monitor used to test the positional relationship between the mouse point and the closed curve, and print it to the screen.
(defun _callback
(dynpt
/ str
) ; point monitor callback function )
(setq relation
(_isPtInPoly crv testpnt
)) ; The callback function internally calls the point position judgment function _isPtInPoly
(cond ((= relation XD:kInside
) (setq str
"The current mouse is inside the polyline!") )
((= relation XD:kBoundary)
(setq str
"The current mouse is on the polyline!") )
(t
(setq str
"The current mouse is outside the polyline!")) )
str
)
"\nPick closed polyline<Exit>:"
'((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))
)
)
)
(xdrx_begin)
(xdrx_sysvar_push '("osmode" 0))
(xdrx_pointmonitor "_callback") ;Enable point monitor
"\nMove the mouse and determine the relationship between the current mouse point and the polyline<Exit>:"
)
(xdrx_pointmonitor) ;Close point monitor
(xdrx_end)
)
)
)

=============
The above LISP code uses the XDRX-API, which can be downloaded from
https://github.com/xdcad/XDrx-APIThe XDRX API encapsulates AcDb, AcEd, AcGe, AcBr... C++ library, using C++ methods to develop LISP programs.Thousands of Lisp functions are available.