http://www.bugman123.com/Programs/Functions.html

- ;Function to determine whether a point is inside a region.
- (defun inside (p plist / n vp1 p1 p2 thetasum theta)
- (if (vl-some 'numberp plist)
- (progn
- (setq n 0
- p1 (car plist)
- ) ; intersection test vector, this code was adapted from: [url]http://www.autocode.com/lisp/inout.zip[/url]
- (setq vp1 (pt (+ (car p) (* 3 (- (xmax plist) (xmin plist))))
- (cadr p)
- )
- ) ; virtual point (assumes this point is outside)
- (foreach p2 (cdr plist)
- (if (numberp p2)
- (setq theta p2)
- (progn
- (if theta
- (setq n (+ n (length (inters-arc p vp1 p1 p2 theta T))))
- (if (inters p vp1 p1 p2)
- (setq n (1+ n))
- )
- )
- (setq p1 p2
- theta nil
- )
- )
- )
- ) ;f
- (/= (rem n 2) 0) ; oneofeach
- );p
- (progn (setq thetasum 0
- theta2 (if plist
- (angle p (last plist))
- )
- ) ; no buldges (faster)
- (foreach p2 plist
- (setq theta1 (angle p p2)
- theta (- theta2 theta1)
- )
- (if (> (abs theta) pi)
- (setq theta (+ theta
- (* (if (minusp theta)
- -1
- 1
- )
- 2pi
- )
- )
- )
- )
- (setq thetasum (+ thetasum theta)
- theta2 theta1
- )
- ) ;f
- (/=~ thetasum 0)
- ) ;p
- )
- ) ;d
or
http://discussion.autodesk.com/thread.jspa?messageID=4116930
http://discussion.autodesk.com/thread.jspa?messageID=1217519 |