Detecting the intersection points with the start and end points of the overlap.

Detecting the intersection points with the start and end points of the overlap.

neam
Collaborator Collaborator
1,087 Views
4 Replies
Message 1 of 5

Detecting the intersection points with the start and end points of the overlap.

neam
Collaborator
Collaborator

Hi everyone

I wanted to know if there is a way to distinguish between points of intersection and overlapping points.

I've attached a sample file to you.

0 Likes
Accepted solutions (2)
1,088 Views
4 Replies
Replies (4)
Message 2 of 5

marko_ribar
Advisor
Advisor
Accepted solution

Try this snippet :

 

(defun c:checkoverlappts ( / c1 c2 fuzz int pt pl d1 d2 p1c1 p2c1 p1c2 p2c2 ol )

  (vl-load-com)

  (while
    (or
      (not (setq c1 (car (entsel "\nPick first curve for checking..."))))
      (if c1
        (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getstartpoint (list c1)))
      )
    )
  )
  (while
    (or
      (not (setq c2 (car (entsel "\nPick second curve for checking..."))))
      (if c2
        (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getstartpoint (list c2)))
      )
    )
  )
  (initget 6)
  (setq fuzz (getdist "\nPick or specify checking fuzz distance <0.01> : "))
  (if (null fuzz)
    (setq fuzz 0.01)
  )
  (setq int (vlax-invoke (vlax-ename->vla-object c1) 'intersectwith (vlax-ename->vla-object c2) acextendnone))
  (if int
    (progn
      (repeat (/ (length int) 3)
        (setq pt (list (car int) (cadr int) (caddr int)))
        (setq int (cdddr int))
        (setq pl (cons pt pl))
      )
      (if (or (equal (vlax-curve-getstartpoint c1) (vlax-curve-getstartpoint c2) 1e-8) (equal (vlax-curve-getstartpoint c1) (vlax-curve-getendpoint c2) 1e-8))
        (setq pl (cons (vlax-curve-getstartpoint c1) pl))
      )
      (if (or (equal (vlax-curve-getendpoint c1) (vlax-curve-getstartpoint c2) 1e-8) (equal (vlax-curve-getendpoint c1) (vlax-curve-getendpoint c2) 1e-8))
        (setq pl (cons (vlax-curve-getendpoint c1) pl))
      )
      (foreach pt (setq pl (vl-sort pl '(lambda ( a b ) (< (vlax-curve-getparamatpoint c1 a) (vlax-curve-getparamatpoint c1 b)))))
        (setq d1 (vlax-curve-getdistatpoint c1 pt))
        (setq d2 (vlax-curve-getdistatpoint c2 pt))
        (setq p1c1 (vlax-curve-getpointatdist c1 (- d1 fuzz)))
        (setq p2c1 (vlax-curve-getpointatdist c1 (+ d1 fuzz)))
        (setq p1c2 (vlax-curve-getpointatdist c2 (- d2 fuzz)))
        (setq p2c2 (vlax-curve-getpointatdist c2 (+ d2 fuzz)))
        (if (or (equal p1c1 p1c2 1e-8) (equal p1c1 p2c2 1e-8) (equal p2c1 p1c2 1e-8) (equal p2c1 p2c2 1e-8))
          (setq ol (cons pt ol) pl (vl-remove pt pl))
        )
      )
      (prompt "\nIntersection points that don't overlap : ") (princ pl)
      (prompt "\nIntersection points that overlap : ") (princ (setq ol (reverse ol)))
    )
    (prompt "\nPicked curves don't intersect each other...")
  )
  (princ)
)

HTH., M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 3 of 5

neam
Collaborator
Collaborator

Thanks again Marco :
It was as good as ever

Smiley Very Happy

0 Likes
Message 4 of 5

marko_ribar
Advisor
Advisor
Accepted solution

Sorry, it was written quickly... Here is better revision...

(defun c:checkoverlappts ( / unique c1 c2 fuzz int pt pl d1 d2 p1c1 p2c1 p1c2 p2c2 ol )

  (vl-load-com)

  (defun unique ( l )
    (if l
      (cons (car l) (unique (vl-remove-if '(lambda ( x ) (equal x (car l) 1e-8)) l)))
    )
  )

  (while
    (or
      (not (setq c1 (car (entsel "\nPick first curve for checking..."))))
      (if c1
        (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getstartpoint (list c1)))
      )
    )
    (prompt "\nMissed or picked wrong entity type...")
  )
  (while
    (or
      (not (setq c2 (car (entsel "\nPick second curve for checking..."))))
      (if c2
        (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getstartpoint (list c2)))
      )
    )
    (prompt "\nMissed or picked wrong entity type...")
  )
  (initget 6)
  (setq fuzz (getdist "\nPick or specify checking fuzz distance <0.01> : "))
  (if (null fuzz)
    (setq fuzz 0.01)
  )
  (setq int (vlax-invoke (vlax-ename->vla-object c1) 'intersectwith (vlax-ename->vla-object c2) acextendnone))
  (if (or (equal (vlax-curve-getstartpoint c1) (vlax-curve-getstartpoint c2) 1e-8) (equal (vlax-curve-getstartpoint c1) (vlax-curve-getendpoint c2) 1e-8))
    (setq pl (cons (vlax-curve-getstartpoint c1) pl))
  )
  (if (or (equal (vlax-curve-getendpoint c1) (vlax-curve-getstartpoint c2) 1e-8) (equal (vlax-curve-getendpoint c1) (vlax-curve-getendpoint c2) 1e-8))
    (setq pl (cons (vlax-curve-getendpoint c1) pl))
  )
  (if (or int pl)
    (progn
(if int (repeat (/ (length int) 3) (setq pt (list (car int) (cadr int) (caddr int))) (setq int (cdddr int)) (setq pl (cons pt pl)) )
) (foreach pt (setq pl (unique (vl-sort pl '(lambda ( a b ) (< (vlax-curve-getparamatpoint c1 a) (vlax-curve-getparamatpoint c1 b)))))) (setq d1 (vlax-curve-getdistatpoint c1 pt)) (setq d2 (vlax-curve-getdistatpoint c2 pt)) (setq p1c1 (vlax-curve-getpointatdist c1 (- d1 fuzz))) (setq p2c1 (vlax-curve-getpointatdist c1 (+ d1 fuzz))) (setq p1c2 (vlax-curve-getpointatdist c2 (- d2 fuzz))) (setq p2c2 (vlax-curve-getpointatdist c2 (+ d2 fuzz))) (if (or (and p1c1 p1c2 (equal p1c1 p1c2 1e-8)) (and p1c1 p2c2 (equal p1c1 p2c2 1e-8)) (and p2c1 p1c2 (equal p2c1 p1c2 1e-8)) (and p2c1 p2c2 (equal p2c1 p2c2 1e-8))) (setq ol (cons pt ol) pl (vl-remove pt pl)) ) ) (prompt "\nIntersection points that don't overlap : ") (princ pl) (prompt "\nIntersection points that overlap : ") (princ (setq ol (reverse ol))) ) (prompt "\nPicked curves don't intersect each other...") ) (princ) )

Regards, M.R.

Thanks...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 5 of 5

neam
Collaborator
Collaborator

Thank you

Thank you

Thank you

Thank you

Thank you

0 Likes