TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: well20152016 on July 28, 2019, 02:27:24 AM

Title: (Algorithms) How to determine the position of two LWPOLYLINE?
Post by: well20152016 on July 28, 2019, 02:27:24 AM
How to determine the position of two LWPOLYLINE?
Title: Re: (Algorithms) How to determine the position of two LWPOLYLINE?
Post by: Dlanor on July 28, 2019, 05:21:21 AM
If both are closed draw a line from the centoid of each, and check the parameters or distances of the intersection points of the line with the two polylines
Title: Re: (Algorithms) How to determine the position of two LWPOLYLINE?
Post by: Lee Mac on July 28, 2019, 06:48:19 AM
Assuming linear segments only, use the ideas shared in this thread (https://www.theswamp.org/index.php?topic=47969.0) to check whether each vertex of one polyline lies inside the other - you'll need to decide the appropriate output if the polylines are partially overlapping.
Title: Re: (Algorithms) How to determine the position of two LWPOLYLINE?
Post by: well20152016 on July 28, 2019, 08:11:17 PM
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tt()
  2. (setq l1 (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget (car (entsel "\nLWPOLYLINE1")))))
  3.       l2 (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget (car (entsel "\nLWPOLYLINE2")))))
  4.       k1 (mapcar'(lambda (x) (raycast x l2)) l1)
  5.       K2 (mapcar'(lambda (x) (ptonline x l2)) l1)
  6.       )
  7.   (cond ((and (apply'and k1) (null(vl-remove 'nil (apply 'append k2)))) (princ  "\n*********  1 in 2"))
  8.         ((and (null (apply'and k1)) (null (vl-remove 'nil (apply 'append k2)))) (princ  "\n*********  1 outside 2"))
  9.         ((and (null (apply'and k1)) (vl-remove 'nil (apply 'append k2))) (princ  "\n*********  1 outside 2-Tangency"))
  10.         ((and (apply'and k1) (vl-remove 'nil (apply 'append k2))) (princ  "\n*********  1 in 2-Tangency"))
  11.         )
  12.  
  13. (defun raycast ( p l )
  14.     (= 1 (setq y (logand 1(length (vl-remove 'nil (setq kl (mapcar'(lambda ( a b ) (inters p (mapcar '+ p '(1e8 0.0)) a b))  (cons (last l) l) l )))))))
  15. )
  16. (defun ptonline ( p l )
  17.     (vl-remove 'nil (mapcar'(lambda (a b) (equal (- (distance a b)(distance p a)(distance p b)) 0 1e-7))  (cons (last l) l) l ))
  18. )
Title: Re: (Algorithms) How to determine the position of two LWPOLYLINE?
Post by: roy_043 on July 29, 2019, 03:56:30 AM
The ray cast approach has a known problem:
Code: [Select]
(RAYCAST '(0 0 0) '((1 0 0) (1 1 0) (-1 1 0) (-1 -1 0) (2 -1 0) (2 0 0))) => nil
Title: Re: (Algorithms) How to determine the position of two LWPOLYLINE?
Post by: well20152016 on August 04, 2019, 07:55:35 AM
Special examples, what's wrong?