Jump to content

Point inside or outside of another entity


robierzo

Recommended Posts

(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.

  • Like 1
Link to comment
Share on other sites

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 by marko_ribar
  • Like 1
Link to comment
Share on other sites

  • 10 years later...
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?

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...