Jump to content

Line-Arc intersection?


George Duls

Recommended Posts

Hello! (me again :))

I'll do my best to explane my problem.

Intersection between line and arc is my problem,

and I've got a kind of solution but it's not very good.

I will try to write with the code and make my self more clear.

 

(defun dtr (x)

(* pi (/ x 180.0))

)

(defun c:ninja-app ()

(setq line (entget (car (entsel "Line?"))))

(setq line-sp (cdr (assoc 10 line)))

(setq line-ep (cdr (assoc 11 line)))

I select a line, and take the start and the end point.

 

(setq arc (car (entsel "Arc?")))

I select an arc and prepare it for VLAX commands

 

 

(setq line-angle (angle line-sp line-ep))

I get the angle of the line (for POLAR command later)

 

(setq line-distance 0)

Setting this var to 0 so I can add that 0.000001 to it

 

(while (= distance nil)

(setq line-distance (+ line-distance 0.000001))

(setq line-point (polar line-sp line-angle line-distance))

(setq distance (vlax-curve-getdistatpoint arc line-point))

(if (> line-distance (distance profil-sp profil-ep)) (exit))

)

In this loop I am trying to "scan" a line point by point

and with (vlax-curve-getdistatpoint) hoping to find the intersection (and distance) point.

But even with this small step (0.0000001) I sometimes fail

to find it.

This could be simple if I could make the precision (like 1.235685=1.24) smaller (or something like that)

but I am lost, and even don't know am I on the right path here.

I hope I made my self clear enough

(i know my explaining sucks big time).

 

ThankYou very much!

Greetings! Danko.

Link to comment
Share on other sites

This may help you:

 

; Ints ~ by Lee McDonnell

; 2 Arg Input:
; cEnt VL Object
; dEnt VL Object

; Return:

; Point of Intersection

(defun Ints (cEnt dEnt)
 (alert (vl-princ-to-string
      (vlax-safearray->list
        (vlax-variant-value
          (vla-IntersectWith cEnt dEnt acExtendNone)))))
 (princ))

Link to comment
Share on other sites

CAB,

 

I have seen "vlax-invoke-method" but I didn't know that you could just use "vlax-invoke".

 

Just out of interest, is the return a variant? or does it return the point straight off?

 

Thanks as always

 

Lee

Link to comment
Share on other sites

These use & return standard points

vlax-invoke obj '

vlax-put- obj

vlax-get- obj

 

  (setq pt (vlax-invoke
      (vlax-ename->vla-object e1) 'IntersectWith
                 (vlax-ename->vla-object e2) acExtendNone))

 

 

==================================

These use & return variant points

vlax-invoke-method

vlax-put-property

vlax-get-property

 

  (setq pt (vlax-safearray->list
 	(vlax-variant-value 
 	(vlax-invoke-method
      (vlax-ename->vla-object e1) 'IntersectWith
        (vlax-ename->vla-object e2) acExtendNone))))

Link to comment
Share on other sites

Many thanks to you CAB, I am gradually understanding more of Visual LISP.

 

My preferred method still remains as Common LISP and messing around with DXF Tables, but once I am confident in VL, I am sure things will be a lot easier to manipulate.

 

Thanks once again for your patience and explanations, both are much appreciated.

 

Cheers

 

Lee

Link to comment
Share on other sites

ThankYou, I didn't know about (vla-intersectwith) :shock:

 

I am not in VL but I see I should try it.

(it is very confusing to me like AL once

was and is still in some moments :lol: )

 

Greetings.

 

p.s.

I know I will confuse myself again

with this VL, ActiveX (I don't have a clue about it)

variant, ACExtendNone, data conversion and so on.

I don't have a clue about anything here, but I will learn.

TNX

Link to comment
Share on other sites

Based on the link from Carl, I rewrote the intersection LISP:

 

(defun ssInter (ss / i y Ent1 Ent2 iArr iLst)
 (setq i (sslength ss))
 (while (not (minusp (setq y (1- i) i (1- i))))
   (setq Ent1 (vlax-ename->vla-object (ssname ss i)))
   (while (not (minusp (setq y (1- y))))
     (setq Ent2 (vlax-ename->vla-object (ssname ss y))
       iArr (vlax-variant-value
         (vla-IntersectWith Ent1 Ent2 acExtendNone)))
     (if (> (vlax-safearray-get-u-bound iArr 1) 0)
   (progn
     (setq iLst (vlax-safearray->list iArr))
     (while (not (zerop (length iLst)))
       (setq ptLst (cons (list (car iLst) (cadr iLst) (caddr iLst)) ptLst)
         iLst (cdddr iLst))))))))

(defun c:test (/ ptLst)
 (vl-load-com)
 (ssInter (ssget))
 (alert (vl-princ-to-string ptLst))
 (princ))

 

(*complete with tester program*)

Link to comment
Share on other sites

Another way:

 

(defun ssInter (ss / vLst i j obj1 obj2 iArr iLst)
 (setq vLst (mapcar 'vlax-ename->vla-object
            (vl-remove-if 'listp
              (mapcar 'cadr (ssnamex ss))))
   i (length vLst))
 (while (not (minusp (setq j (1- i) i (1- i))))
   (setq obj1 (nth i vLst))
   (while (not (minusp (setq j (1- j))))
     (setq obj2 (nth j vLst)
       iArr (vlax-variant-value
         (vla-IntersectWith obj1 obj2 acExtendNone)))      
     (if (> (vlax-safearray-get-u-bound iArr 1) 0)
   (progn
     (setq iLst (vlax-safearray->list iArr))
     (while (not (zerop (length iLst)))
       (setq ptLst (cons (list (car iLst) (cadr iLst) (caddr iLst)) ptLst)
         iLst (cdddr iLst))))))))


(defun c:test (/ ptLst)
 (vl-load-com)
 (ssInter (ssget))
 (alert (vl-princ-to-string ptLst))
 (princ))

Link to comment
Share on other sites

  • 6 months later...

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...