robierzo Posted September 19, 2012 Share Posted September 19, 2012 Hello. How i can know if a point is inside or outside of another entity: circle, rectangle, polyline, spline.... Regards. Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted September 19, 2012 Share Posted September 19, 2012 (defun GroupByNum ( lst n / r) (if lst (cons (reverse (repeat n (setq r (cons (car lst) r) lst (cdr lst)) r)) (GroupByNum lst n) ) ) ) (defun ptonline ( pt pt1 pt2 / vec12 vec1p d result ) (setq vec12 (mapcar '- pt2 pt1)) (setq vec12 (reverse (cdr (reverse vec12)))) (setq vec1p (mapcar '- pt pt1)) (setq vec1p (reverse (cdr (reverse vec1p)))) (setq vec2p (mapcar '- pt2 pt)) (setq vec2p (reverse (cdr (reverse vec2p)))) (setq d (distance '(0.0 0.0) vec12) d1 (distance '(0.0 0.0) vec1p) d2 (distance '(0.0 0.0) vec2p)) (if (equal d (+ d1 d2) 1e- (setq result T) (setq result nil)) result ) (defun ptinsideent ( pt ent / msp ptt xlin int k kk tst result ) (vl-load-com) (setq msp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))) (setq ptt (vlax-curve-getclosestpointto ent pt)) (setq xlin (vla-addxline msp (vlax-3d-point pt) (vlax-3d-point ptt))) (setq int (GroupByNum (vlax-invoke (if (eq (type ent) 'ENAME) (vlax-ename->vla-object ent)) 'intersectwith xlin acExtendBoth) 3)) (setq int (vl-sort int '(lambda (a b) (< (vlax-curve-getparamatpoint xlin a) (vlax-curve-getparamatpoint xlin b))))) (setq k 0) (while (< (setq k (1+ k)) (length int)) (if (and (eq (rem k 2) 1) (ptonline pt (nth (- k 1) int) (nth k int))) (setq tst (cons T tst)) (setq tst (cons nil tst))) ) (setq tst (reverse tst)) (setq k 0) (mapcar '(lambda (x) (setq k (1+ k)) (if (eq x T) (setq kk k))) tst) (vla-delete xlin) (if kk (if (eq (rem kk 2) 1) (setq result T) (setq result nil)) (setq result nil) ) result ) (ptinsideent pt ent) => T or nil M.R. 1 Quote Link to comment Share on other sites More sharing options...
robierzo Posted September 19, 2012 Author Share Posted September 19, 2012 Hello, marko_ribar. Works pefectly. It's great. Thank you very much. Quote Link to comment Share on other sites More sharing options...
robierzo Posted September 19, 2012 Author Share Posted September 19, 2012 Marko, there is a small problem. When de point belongs to the polyline, does not work. Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted September 20, 2012 Share Posted September 20, 2012 (edited) Command: (vl-catch-all-apply 'ptinsideent (list pt ent)) # - pt lies on ent -if you want to return T (pt lies on ent and may not be inside or outside ent) use : (vl-catch-all-error-p (vl-catch-all-apply 'ptinsideent (list pt ent))) Command: (vl-catch-all-apply 'ptinsideent (list pt ent)) T - pt is inside ent Command: (vl-catch-all-apply 'ptinsideent (list pt ent)) nil - pt is outside ent (if (vl-catch-all-error-p (vl-catch-all-apply 'ptinsideent (list pt ent))) (prompt "\nPoint is on entity") (if (ptisideent pt ent) (prompt "\nPoint is inside entity") (prompt "\nPoint is outside entity") ) ) Edited September 20, 2012 by marko_ribar 1 Quote Link to comment Share on other sites More sharing options...
robierzo Posted September 20, 2012 Author Share Posted September 20, 2012 Thank you very much, marko. Now it works perfectly. Quote Link to comment Share on other sites More sharing options...
JBell Posted August 20 Share Posted August 20 On 9/19/2012 at 3:42 PM, marko_ribar said: (defun ptonline ( pt pt1 pt2 / vec12 vec1p d result ) ... (if (equal d (+ d1 d2) 1e- (setq result T) (setq result nil)) result ) I'm noticing the 1e- Is that an incomplete argument? What should come after the minus? Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted August 20 Share Posted August 20 1e-6), or 1e-8) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 21 Share Posted August 21 0.000001 or 0.00000001 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.