### Author Topic: (Algorithms) How to determine the position of two LWPOLYLINE?  (Read 1073 times)

0 Members and 1 Guest are viewing this topic.

#### well20152016

• Newt
• Posts: 88 ##### (Algorithms) How to determine the position of two LWPOLYLINE?
« on: July 28, 2019, 02:27:24 AM »
How to determine the position of two LWPOLYLINE?

#### Dlanor

• Bull Frog
• Posts: 238 ##### Re: (Algorithms) How to determine the position of two LWPOLYLINE?
« Reply #1 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 ##### Re: (Algorithms) How to determine the position of two LWPOLYLINE?
« Reply #2 on: July 28, 2019, 06:48:19 AM »
Assuming linear segments only, use the ideas shared in this thread 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.

#### well20152016

• Newt
• Posts: 88 ##### Re: (Algorithms) How to determine the position of two LWPOLYLINE?
« Reply #3 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. ) ##### Re: (Algorithms) How to determine the position of two LWPOLYLINE?
« Reply #4 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`

#### well20152016

• Newt
• Posts: 88 ##### Re: (Algorithms) How to determine the position of two LWPOLYLINE?
« Reply #5 on: August 04, 2019, 07:55:35 AM »
Special examples, what's wrong?