Jump to content

vlax-invoke intersectwith catches the neighboring segments.


Kowal

Recommended Posts

I am analyzing the function of Lee Mac.

http://www.lee-mac.com/intersectionfunctions.html

;; Intersections  -  Lee Mac
;; Returns a list of all points of intersection between two objects
;; for the given intersection mode.
;; ob1,ob2 - [vla] VLA-Objects
;;     mod - [int] acextendoption enum of intersectwith method

(defun LM:intersections ( ob1 ob2 mod / lst rtn )
   (if (and (vlax-method-applicable-p ob1 'intersectwith)
            (vlax-method-applicable-p ob2 'intersectwith)
            (setq lst (vlax-invoke ob1 'intersectwith ob2 mod))
       )
       (repeat (/ (length lst) 3)
           (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
                 lst (cdddr lst)
           )
       )
   )
   (reverse rtn)
)

I noticed that if the coordinates are large, the function catches the neighboring segments.

 

 

Example 1: intersections two LWPOLYLINE.

 

Intersection 1.jpg

 

(LM:intersections (vlax-Ename->Vla-Object (car (entsel))) (vlax-Ename->Vla-Object (car (entsel))) acextendnone)

 

LWPOLYLINE 1: ((-0.112 0.093) (0.296 0.085) (0.717 0.255))
LWPOLYLINE 2: ((-0.043 0.177) (0.08 0.003) (0.234 0.177) (0.323 -0.022) (0.373 0.227))

 

Returns 4 correct points.

 

((0.0180291 0.090385 0.0) (0.155541 0.0875826 0.0) (0.275268 0.0851427 0.0) (0.34906 0.106104 0.0))

 

Example 2: intersections two LWPOLYLINE transformed.

 

LWPOLYLINE 1: ((8405375.127 5679451.655) (8405375.535 5679451.647) (8405375.955 5679451.818))
LWPOLYLINE 2: ((8405375.195 5679451.739) (8405375.319 5679451.565) (8405375.473 5679451.739) (8405375.562 5679451.54) (8405375.612 5679451.789))

 

Returns 6 points. 4 correct and 2 incorrect.

 

((8.40538e+006 5.67945e+006 0.0) (8.40538e+006 5.67945e+006 0.0) (8.40538e+006 5.67945e+006 0.0) (8.40538e+006 5.67945e+006 0.0) (8.40538e+006 5.67945e+006 0.0) (8.40538e+006 5.67945e+006 0.0))

 

Is the only solution to move the objects to the beginning of the coordinate system for the time when calculating the intersections?

Link to comment
Share on other sites

Interesting, however I'm unable to reproduce this bug...

Thought to suggest using a function like the polyinters Lee offered (no idea he wrote such thing already :lol: ).

 

The only failure of the intersectwith method of which I was aware is:

(setq rtn ; in case the object is self intersecting
 (cons  ; but the problem is that this considers LWPOLY's/SPLINE's mid vertices as intersections (i.e. all vertices, except the endpoints)
   (vlax-list->3D-point (vlax-invoke o1 'InterSectWith o1 acExtendNone)) 
   rtn
 )
); setq rtn

 

BTW a variation of Lee's function that uses vlax-curveGetPointAtParam to split the curve at segments and use inters for every pair of segments from the two curve objects might "do the job", although this approach would vary on precision and speed performance. Maybe more effective way for this idea would be to incorporate it with this.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...