Author Topic: Point is Inside polyline (Now with Bulges)  (Read 22339 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Point is Inside polyline (Now with Bulges)
« Reply #60 on: May 10, 2015, 07:30:30 AM »
...able to define the tolerance in terms of the maximum sagitta allowed between the segment and the curve.

Code - Auto/Visual Lisp: [Select]
  1. < ... >
  2.             (setq j (ceil (sqrt (/ (* 0.5 (distance (car pl) (vlax-curve-getpointatparam en i)) b) tol)))
  3.                   d (/ 1.0 j)
  4.                   i (1+ i)
  5.             )
  6.             (repeat j
  7.                 (setq pl (cons (vlax-curve-getpointatparam en (setq i (- i d))) pl))
  8.             )
  9. < ... >

Nice idea ymg  :-)

This was my approach from some time ago, but your method of dealing with bulges is much more elegant.

ymg

  • Guest
Re: Point is Inside polyline (Now with Bulges)
« Reply #61 on: May 10, 2015, 07:52:18 AM »
Lee,

Thanks!,

However function tracepline2 supports only polylines, yours is more like the "Express Tools" one.

Another disadvantage to it is that we always interpolate.  Thus our resulting point list is always smaller than the original polyline.

ymg
« Last Edit: May 10, 2015, 07:59:14 AM by ymg »

chlh_jd

  • Guest
Re: Point is Inside polyline (Now with Bulges)
« Reply #62 on: May 17, 2015, 07:25:51 AM »
...
Another disadvantage to it is that we always interpolate.  Thus our resulting point list is always smaller than the original polyline.

Hi , Ymg
If to determine a given point in Polyline with bulge , yours has sufficient accuracy , I suggest add the closest point into pointlist , it can reduce a lot of points builded .


ymg

  • Guest
Re: Point is Inside polyline (Now with Bulges)
« Reply #63 on: May 18, 2015, 08:56:10 AM »
chlh_jd,

Quote
I suggest add the closest point into pointlist , it can reduce a lot of points builded .

Not sure I understand your suggestion.  Adding the points you are showing would double the number of points to process, and would be equivalent to to reducing the tolerance.

What I meant, is there are some methods where you generate the point just outside the curve. 
This way the tangent cuts the curve at the midpoint of the chord.

Now if you calculate the area of the polyline you will be much closer than with the interpolation method
which is always smaller than true value.

But may be I am missing something in your suggestion.

ymg

ymg

  • Guest
Re: Point is Inside polyline (Now with Bulges)
« Reply #64 on: May 18, 2015, 08:59:39 AM »
chlh_jd,

I thing, I caught what you meant.

I believe it makes sense, I will make some test and post when I got results.

ymg

chlh_jd

  • Guest
Re: Point is Inside polyline (Now with Bulges)
« Reply #65 on: May 19, 2015, 10:49:08 AM »
Hi , Ymg
Test this function's result to determine the given point inside a polyline , will reduce a lot of calculation .
Code - Auto/Visual Lisp: [Select]
  1. (defun tracepline3 (en gp / pl obj i p cp cpa mp)
  2.    ; en -- Polyline
  3.    ; gp -- given point
  4.    ;(if (= (type en) 'vla-object) ;
  5.    ;   (setq obj en   en (vlax-vla-object->ename  obj))
  6.        (setq obj (vlax-ename->vla-object en))
  7.    ;)  
  8.          cp (vlax-curve-getclosestpointto en gp)
  9.          cpa (vlax-curve-getparamatpoint en cp))
  10.    (repeat (fix i)    
  11.       (if (not (zerop (car (list (abs (vla-getbulge obj (setq i (1- i))))
  12.                                  (setq p (vlax-curve-getpointatparam en i))))))
  13.         (progn
  14.           (setq mp (vlax-curve-getpointatparam en (+ i 0.5)))
  15.          (if (<= i cpa (1+ i))
  16.            (if (<= i cpa (+ i 0.5))
  17.              (setq pl (vl-list*  p cp  mp  pl))
  18.              (setq pl (vl-list*  p mp cp pl)))
  19.            (setq pl (vl-list* p mp pl))))
  20.          (setq pl (cons p pl)))
  21.      )
  22.    pl
  23. )
  24.  
« Last Edit: May 19, 2015, 10:59:02 AM by chlh_jd »

chlh_jd

  • Guest
Re: Point is Inside polyline (Now with Bulges)
« Reply #66 on: May 19, 2015, 11:13:58 AM »
To judge a point location with a polygon I used following functions :

Function1
Code - Auto/Visual Lisp: [Select]
  1.  
  2. ;;;Function : judge a point location with polygon
  3. ;;;Arg : pt -- a point
  4. ;;;      pts -- points of polygon
  5. ;;;      eps -- allowance
  6. ;;;return :
  7. ;;;     -1 -- out of polygon , 0 -- at , 1 -- in
  8. (defun pipl?  (pt pts eps / is at a)
  9.   ;; by Superb-Machete (this name translated by GSLS(SS), I just knew his chinese name &#29378;&#20992;)
  10.   ;; Edit by GSLS(SS) 2011.03.28
  11.   ;; Solved the problem : if a point at the given polygon , it perhap return T or NIL .  
  12.   (cond
  13.     ((vl-some (function (lambda (x) (equal x pt eps))) pts) 0)
  14.                            (setq a (rem (- (angle pt x) (angle pt y)) PI))
  15.                            (if (equal (+ (distance pt x) (distance pt y))(distance x y)Eps)
  16.                              (setq at T))a))(cons (last pts) pts) pts))) pi eps)(not at))1)
  17.     (at 0)(-1)))
  18.  

function2
Code - Auto/Visual Lisp: [Select]
  1. (defun EE:pitp (p l)
  2.   ;; check is a point inside the triangle.
  3.   ;; by ElpanovEvgeniy
  4.   (if (vl-some (function (lambda (x) (equal p x 1e-6)))
  5.                l)    T
  6.     (if (< (sin (- (angle (last l) p) (angle (last l) (car l))))
  7.            -1e-6)
  8.       (vl-every
  9.         (function
  10.           (lambda (a b) (< (sin (- (angle a p) (angle a b))) -1e-6)))
  11.         l
  12.         (cdr l)      )
  13.       (vl-every
  14.         (function
  15.           (lambda (a b) (> (sin (- (angle a p) (angle a b))) 1e-6))     )
  16.         l
  17.         (cdr l)
  18.       )
  19.     )
  20.   )
  21. )
  22.  

function3  widding number method
Code - Auto/Visual Lisp: [Select]
  1. ;; This method suggest by Lee Mac from http://en.wikipedia.org/wiki/Winding_number
  2. ;; function : get widding number
  3. ;; l  ---- point set of a Closed Curve
  4. ;; pt ---- a given point to determin position with the Closed Curve
  5. ;;  return a list (point_postion_num Clokwise_boolean)
  6. ;;          point_postion_num  ----  -1  pt out of curve
  7. ;;                             ----   0  pt at curve
  8. ;;                             ----   1  pt in curve
  9. ;;          Clokwise_boolean   ----  NIL Counter-Clockwise
  10. ;;                             ----  T  Clokwise
  11. ;; by GSLS(SS) 2012-08-02
  12. (defun get-widding-number (l pt / n r)
  13.   (if (equal (car l) (last l) 1e-6)
  14.     nil
  15.     (setq l (append l (list (car l)))))  
  16.   ;_(setq n (/ ang 2. pi))
  17.   (setq n (widding l pt))
  18.   (if (< n 0)
  19.     (setq r (list T))
  20.     (setq r (list NIL)))  
  21.   ;;deal widding number
  22.   (if (and (> n 0) (equal (1+ (fix n)) n 1e-2))
  23.     (setq n (1+ (fix n)))
  24.     (if (and (< n 0) (equal (1- (fix n)) n 1e-2))
  25.       (setq n (1- (fix n)))
  26.       (setq n (fix n))))
  27.   (if (= (rem n 2) 0)
  28.     (cons -1 r)
  29.  
  30. ;; use function
  31. (defun widding  (l pt)
  32.   (/ (apply
  33.        (function +)
  34.        (mapcar (function (lambda (p1 p2)
  35.                            (ang<api (- (angle pt p2) (angle pt p1)))
  36.                            ))
  37.                l
  38.                (cdr l)))
  39.      2.
  40.      pi))
  41.  
  42. (defun ang<Api (ang)
  43.   (setq ang (rem ang (+ pi pi)))
  44.   (cond ((< ang (- pi))
  45.          (+ ang (+ pi pi)))
  46.         ((> ang pi)
  47.          (- ang (+ pi pi)))
  48.         (ang)))
  49.  
« Last Edit: May 19, 2015, 11:19:14 AM by chlh_jd »

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Point is Inside polyline (Now with Bulges)
« Reply #67 on: January 14, 2017, 12:48:42 PM »
Here is my version, slow and for polygons without bulges...

At least it's working fine for me...

Code - Auto/Visual Lisp: [Select]
  1. (defun mr_IsPointInside ( pt ptlst / trianglst ptinsidetriangle-p trl )
  2.  
  3.   (defun trianglst ( ptlst / unique LM:ListClockwise-p clockwise-p l p1 p2 p3 trl )
  4.  
  5.     (defun unique ( l )
  6.       (if l (cons (car l) (unique (vl-remove-if (function (lambda ( x ) (equal x (car l) 1e-6))) l))))
  7.     )
  8.  
  9.     ;; List Clockwise-p - Lee Mac
  10.     ;; Returns T if the point list is clockwise oriented
  11.  
  12.     (defun LM:ListClockwise-p ( lst )
  13.       (minusp
  14.         (apply '+
  15.           (mapcar
  16.             (function
  17.               (lambda ( a b )
  18.                 (- (* (car b) (cadr a)) (* (car a) (cadr b)))
  19.               )
  20.             )
  21.             lst (cons (last lst) lst)
  22.           )
  23.         )
  24.       )
  25.     )
  26.  
  27.     (defun clockwise-p ( p1 p2 p3 )
  28.       (< (* (- (car  p2) (car  p1)) (- (cadr p3) (cadr p1)))
  29.          (* (- (cadr p2) (cadr p1)) (- (car  p3) (car  p1)))
  30.       )
  31.     )
  32.  
  33.     (setq l ptlst)
  34.     (while (> (length ptlst) 3)
  35.       (setq p1 (car ptlst) p2 (cadr ptlst) p3 (caddr ptlst))
  36.       (cond
  37.         ( (LM:ListClockwise-p ptlst)
  38.           (if
  39.             (and
  40.               (clockwise-p p1 p2 p3)
  41.               (= (length (unique (vl-remove nil (mapcar (function (lambda ( a b ) (inters p1 p2 a b))) l (cdr (reverse (cons (car l) (reverse l)))))))) 2)
  42.               (= (length (unique (vl-remove nil (mapcar (function (lambda ( a b ) (inters p2 p3 a b))) l (cdr (reverse (cons (car l) (reverse l)))))))) 2)
  43.               (= (length (unique (vl-remove nil (mapcar (function (lambda ( a b ) (inters p3 p1 a b))) l (cdr (reverse (cons (car l) (reverse l)))))))) 2)
  44.             )
  45.             (progn
  46.               (setq trl (cons (list p1 p2 p3) trl))
  47.               (setq ptlst (vl-remove p2 ptlst))
  48.               (setq ptlst (cdr (reverse (cons (car ptlst) (reverse ptlst)))))
  49.             )
  50.             (setq ptlst (cdr (reverse (cons (car ptlst) (reverse ptlst)))))
  51.           )
  52.         )
  53.         ( (not (LM:ListClockwise-p ptlst))
  54.           (if
  55.             (and
  56.               (not (clockwise-p p1 p2 p3))
  57.               (= (length (unique (vl-remove nil (mapcar (function (lambda ( a b ) (inters p1 p2 a b))) l (cdr (reverse (cons (car l) (reverse l)))))))) 2)
  58.               (= (length (unique (vl-remove nil (mapcar (function (lambda ( a b ) (inters p2 p3 a b))) l (cdr (reverse (cons (car l) (reverse l)))))))) 2)
  59.               (= (length (unique (vl-remove nil (mapcar (function (lambda ( a b ) (inters p3 p1 a b))) l (cdr (reverse (cons (car l) (reverse l)))))))) 2)
  60.             )
  61.             (progn
  62.               (setq trl (cons (list p1 p2 p3) trl))
  63.               (setq ptlst (vl-remove p2 ptlst))
  64.               (setq ptlst (cdr (reverse (cons (car ptlst) (reverse ptlst)))))
  65.             )
  66.             (setq ptlst (cdr (reverse (cons (car ptlst) (reverse ptlst)))))
  67.           )
  68.         )
  69.       )
  70.     )
  71.     (setq trl (cons (list (car ptlst) (cadr ptlst) (caddr ptlst)) trl))
  72.     trl
  73.   )
  74.  
  75.   (defun ptinsidetriangle-p ( pt p1 p2 p3 )
  76.     (or
  77.       (and
  78.         (not
  79.           (or
  80.             (inters pt p1 p2 p3)
  81.             (inters pt p2 p1 p3)
  82.             (inters pt p3 p1 p2)
  83.           )
  84.         )
  85.         (not
  86.           (or
  87.             (> (+ (distance pt p1) (distance pt p2)) (+ (distance p3 p1) (distance p3 p2)))
  88.             (> (+ (distance pt p2) (distance pt p3)) (+ (distance p1 p2) (distance p1 p3)))
  89.             (> (+ (distance pt p3) (distance pt p1)) (+ (distance p2 p3) (distance p2 p1)))
  90.           )
  91.         )
  92.       )
  93.       (equal (distance p1 p2) (+ (distance p1 pt) (distance pt p2)) 1e-8)
  94.       (equal (distance p2 p3) (+ (distance p2 pt) (distance pt p3)) 1e-8)
  95.       (equal (distance p3 p1) (+ (distance p3 pt) (distance pt p1)) 1e-8)
  96.     )
  97.   )
  98.  
  99.   (setq trl (trianglst ptlst))
  100.   (and
  101.     (vl-some (function (lambda ( x ) (ptinsidetriangle-p pt (car x) (cadr x) (caddr x)))) trl)
  102.     (not (vl-some (function (lambda ( a b ) (equal (distance a b) (+ (distance a pt) (distance pt b)) 1e-8))) ptlst (cdr (reverse (cons (car ptlst) (reverse ptlst))))))
  103.   )
  104. )
  105.  

I used it here :
https://www.theswamp.org/index.php?topic=52465.msg574455#new

It proofed to be good...
M.R.
(This topic is old, but I decided to revive it as it's very useful..)
« Last Edit: August 18, 2017, 09:00:08 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

mailmaverick

  • Bull Frog
  • Posts: 494
Re: Point is Inside polyline (Now with Bulges)
« Reply #68 on: January 15, 2017, 12:09:22 AM »
In order to check whether the point is within a list of points, why can't we use SSGET _WP (list 'Points') (list (cons 0 "POINT")) and check whether the required point is within the selection set or not.


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Point is Inside polyline (Now with Bulges)
« Reply #69 on: January 15, 2017, 12:36:46 AM »
Because ObjectDBX.

Because the point may not be an object but merely a test coordinate.

An aside, ssget is not reliable if the area of interest is not visible.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

mailmaverick

  • Bull Frog
  • Posts: 494
Re: Point is Inside polyline (Now with Bulges)
« Reply #70 on: February 14, 2017, 05:59:54 PM »
To judge a point location with a polygon I used following functions :

Function1
.......
.......

function2
.......
.......

function3  widding number method
.......
.......

Dear, you have given three functions. Can these three functions be interchangeably used, or are there certain cases (scenarios) where a particular function should be used ?