Lee Mac Posted August 18, 2009 Share Posted August 18, 2009 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)) Quote Link to comment Share on other sites More sharing options...
VovKa Posted August 18, 2009 Share Posted August 18, 2009 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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 18, 2009 Share Posted August 18, 2009 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... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 18, 2009 Share Posted August 18, 2009 *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 Quote Link to comment Share on other sites More sharing options...
wkplan Posted August 18, 2009 Author Share Posted August 18, 2009 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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 18, 2009 Share Posted August 18, 2009 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. Quote Link to comment Share on other sites More sharing options...
Wan Posted January 23 Share Posted January 23 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. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 23 Share Posted January 23 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). 1 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.