Jump to content

Identify a polyline by a point inside this polyline


Recommended Posts

Posted

Like this:

 

(defun vk_IsPointInside (Point PointsList / PY P1Y P2Y)
 (if (cdr PointsList)
   (/=    (and (or (and (<= (setq    PY  (cadr Point)
               P2Y (cadadr PointsList)
               P1Y (cadar PointsList)
             )
             PY
             )
             (< PY P2Y)
        )
        (and (> P1Y PY) (>= PY P2Y))
        )
        (>    (car Point)
       (+ (* (/ (- PY P1Y) (- P2Y P1Y))
             (- (caadr PointsList) (caar PointsList))
          )
          (caar PointsList)
       )
        )
   )
   (vk_IsPointInside Point (cdr PointsList))
   )
 )
)

(defun c:test (/ ent pt)
 (vl-load-com)
 (if (and (setq ent (car (entsel "\nLWPolyline: ")))
          (setq pt (getpoint "\nPt: ")))
   (alert
     (vl-princ-to-string
       (vk_IsPointInside pt
         (mapcar 'cdr
           (vl-remove-if-not
             (function
               (lambda (x)
                 (eq 10 (car x)))) (entget ent)))))))
 (princ))

Posted

Lee Mac, I forgot to mention the arguments requirement

(defun c:test (/ ent pt)
 (vl-load-com)
 (if (and (setq ent (car (entsel "\nLWPolyline: "))) (setq pt (getpoint "\nPt: ")))
   (progn (setq lst
	  (mapcar 'cdr
		  (vl-remove-if-not (function (lambda (x) (eq 10 (car x)))) (entget ent))
	  )
   )
   (if (not (equal (car lst) (last lst)))
     (setq lst (cons (last lst) lst))
   )
   (alert (vl-princ-to-string (vk_IsPointInside pt lst)))
   )
 )
 (princ)
)

p.s. added comment to my previous post

Posted

Very good VovKa - works a treat! And also would be probably much faster than my routine. I wonder if the recursive process has restrictions though...

Posted

*just trying to step through the routine and work out how it works*

 

Struggling to figure out this bit:

 

          (> (car Point)
             (+ (* (/ (- PY P1Y) (- P2Y P1Y))
                   (- (caadr PointsList)     ;; x of second pt in list
                      (caar PointsList)))    ;; x of first pt in list
                (caar PointsList))))         ;; x of first pt in list

Posted

Lee,

I will think about your recommendations.

(Nice idea to close all open polylines, but this means you will change the drawing more then intended)

 

VovKa,

thank you for this routine.

I changed it, in the way it hatches the polyline, if the point lies in between.

 

(defun c:test (/ ent pt)
 (vl-load-com)
 (if (and (setq ent (car (entsel "\nLWPolyline: ")))
      (setq pt (getpoint "\nPt: "))
     )
   (progn (setq lst
         (mapcar 'cdr
             (vl-remove-if-not
               (function (lambda (x) (eq 10 (car x))))
               (entget ent)
             )
         )
      )
      (if (not (equal (car lst) (last lst)))
        (setq lst (cons (last lst) lst))
      )
     [color=Blue];(alert (vl-princ-to-string (vk_IsPointInside pt lst)))[/color]
   )
 )
 [color=Blue](if (= T (vk_IsPointInside pt lst))
   (command "._bhatch" "_S" ent "" ""))[/color]
 (princ)
)
(defun vk_IsPointInside (Point PointsList / PY P1Y P2Y)
; works with polygons only, i.e. if (equal (car PointsList) (last PointsList))
 (if (cdr PointsList)
   (/=    (and (or (and (<= (setq    PY  (cadr Point)
               P2Y (cadadr PointsList)
               P1Y (cadar PointsList)
             )
             PY
             )
             (< PY P2Y)
        )
        (and (> P1Y PY) (>= PY P2Y))
        )
        (>    (car Point)
       (+ (* (/ (- PY P1Y) (- P2Y P1Y))
             (- (caadr PointsList) (caar PointsList))
          )
          (caar PointsList)
       )
        )
   )
   (vk_IsPointInside Point (cdr PointsList))
   )
 )
)

This works fine.

But it means, that I have to loop twice:

- onetime my pointlist

- nexttime the list of polylines in the drawing.

 

Am I wrong?

 

 

regards

Wolfgang

Posted

You will need to loop through your list of point-lists for each pt you want to test using VovKa's routine.

 

Regarding my test function - you can remove the part that closes the polylines - but I meant about using the function as a sub-function that you would supply with arguments, instead of using global variables.

  • 14 years later...
Posted
On 8/18/2009 at 7:19 PM, Lee Mac said:

Very good VovKa - works a treat! And also would be probably much faster than my routine. I wonder if the recursive process has restrictions though...

Hi Lee,

 

Can you explain little bit more about recursive process over here? I still can't capture the idea of recursion and how does it matter too? Thank you in advance.

Posted
1 hour ago, Wan said:

Can you explain little bit more about recursive process over here? I still can't capture the idea of recursion and how does it matter too? Thank you in advance.

 

Wow, this is an old thread. The recursion used here will only cause problems for very large point lists, for which the stack limit may be reached (i.e. the size of the stack imposes a limit on the maximum number of recursive calls).

  • Like 1

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