Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I make .P_1 at the intersection of a straight line and an arc?

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
jinkinglee
1149 Views, 10 Replies

How do I make .P_1 at the intersection of a straight line and an arc?

How do I make .P_1 at the intersection of a straight line and an arc?

 

(command "line" A p_E "")
(command "arc" P_16 B_25 P_13)
? Like this or?.
(SETQ P_1 (INTERS A p_E (arc) NIL))

10 REPLIES 10
Message 2 of 11
Kent1Cooper
in reply to: jinkinglee


@jinkinglee wrote:

How do I make .P_1 at the intersection of a straight line and an arc?

 

(command "line" A p_E "")
(command "arc" P_16 B_25 P_13)

....


Try this:

 

(vl-load-com); if necessary

(command "line" A p_E "")

(setq linobj (vlax-ename->vla-object (entlast)))
(command "arc" P_16 B_25 P_13)

(setq arcobj (vlax-ename->vla-object (entlast)))

(setq P_1 (vlax-invoke linobj 'intersectwith arcobj acExtendNone))

 

That assumes they actually meet, as in your image.  If they might not, but you still want to know their virtual/apparent intersection, change that last term to acExtendBoth, but that will return two intersection points [of the Line with the circle that is the extension of the Arc], in the form of an un-separated list of 6 coordinates, unless the Line misses that virtual circle entirely [in which case the acExtendNone version won't return an intersection, either].

Kent Cooper, AIA
Message 3 of 11
john.uhden
in reply to: jinkinglee

I'm sort of a trigonometry advocate.  Most of the time I would rather solve for an answer rather than draw it only to erase it.

 

My @Anonymous functions stands for ArcLineIntersect...

 

  ;; New function (8-22-16) to find intersection of Arc and Line.
  ;;  It presumes that arcs are relatively short so that there would be
  ;;  only one intersection.  It is NOT meant to handle where a line
  ;;  would intersect an arc more than once.
  (defun @ali (rp r ba ea p1 p2 / p x y px p3 p4)
     (setq px (polar rp (+ 1/2pi (angle p1 p2)) 100.0)
           px (inters rp px p1 p2 nil)
           y  (distance rp px)
     )
     (cond
        ((< r y)(prompt "\nNo intersection"))
        (1 (setq x  (sqrt (- (* r r)(* y y)))
                 p3 (polar px (angle p1 p2) x)
                 p4 (polar px (angle p2 p1) x)
             )
             (cond
                ((@insect (angle rp p3) ba ea) (setq p p3))
                ((@insect (angle rp p4) ba ea) (setq p p4))
           )
        )
     )
     p
  )

Oops, it requires my @Anonymous function...

 

  ;;------------------------------------------------------------
  ;; Function to determine if an angle is within the sector
  ;; defined by two other angles. (Taken from PTRACE.LSP 8-8-99)
  ;; Returns the delta angle measured from the first angle.
  ;; NOTE:  This presumes that sectors adhere to ARC definitions,
  ;;        that is all angles are measured counter-clockwise.
;; ang = angle to test
;; ba = beginning angle of an arc
;; ea = ending angle of an arc
;;
;; REQUIRES a fuzz factor not declared within the function
;; Usually (setq fuzz 1e-6) or maybe 1e-4 ;; (defun @insect (ang ba ea) (cond ((equal ang ba fuzz)(setq ang ba)) ((equal ang ea fuzz)(setq ang ea)) ) (if (> ba ea) (cond ((>= ang ba)(- ang ba)) ((<= ang ea)(+ ang (- (* 2 pi) ba))) (1 nil) ) (if (and (>= ang ba)(<= ang ea)) (- ang ba) nil ) ) )

John F. Uhden

Message 4 of 11
jinkinglee
in reply to: Kent1Cooper

What I want is

Make P_1 a variable
Creating a setq variable point
(SETQ P_1 (INTERSE p_E p_16 p_13 NIL))
(Setq P_1 (polar P_1 0.0 0.25)


I want to create a point by finding the intersection of line and arc.

 

Thanks

Jin

Message 5 of 11
Kent1Cooper
in reply to: jinkinglee


@jinkinglee wrote:

....
I want to create a point by finding the intersection of line and arc.

....


Does the code in Post 2 not do that?  Post 1 specifically includes actually drawing the Line and the Arc -- was it not a valid assumption that they would be there?  I'm not sure I understand what you want, because the supposed (inters) function's arguments are so different between Post 1 and Post 4.  But if you want to calculate the intersection from only two line endpoints and three points that define an arc, without any drawn objects, that's quite another story.  Is that what you're trying to do?

 

It looks to me [in a very quick perusal, lacking any description of what the arguments represent] as though @john.uhden's ALI routine requires knowing the center and radius of the arc, rather than 3 points along it -- if that's correct, it won't do for you, but maybe a calculation could be done.  However, I expect it would be easier to have the routine do what's in Post 2, just draw the Line and the Arc to get their intersection, then get rid of them if you don't want them around any more.

Kent Cooper, AIA
Message 6 of 11
john.uhden
in reply to: Kent1Cooper

If the OP would like to use 3 points to define the arc, then I have that too.

It's actually a 3PCircle function that returns the radius point (center), but getting the radius is simple.

 

;; Adapted (02-07-00) from above written in 1996
;; Function to find the radius point of a circle
;; defined by three (3) points and a Z value:
;; If valid (not in a straight line), it returns the radius point
;;
(defun @3PCIRCLE (p1 p2 p3 z / x1  x2  x3  y1  y2  y3
                              x12 x22 x32 y12 y22 y32
                              a adenom)
   (setq x1 (car p1) y1 (cadr p1)
         x2 (car p2) y2 (cadr p2)
         x3 (car p3) y3 (cadr p3)
         x12 (* x1 x1) y12 (* y1 y1)
         x22 (* x2 x2) y22 (* y2 y2)
         x32 (* x3 x3) y32 (* y3 y3)
         adenom (- (* (- x1 x2)(- y1 y3)) (* (- x1 x3)(- y1 y2)))
   )
   (if (zerop adenom)
      (prompt "\nInfinite radius.")
      (list
         (setq a
            (/ (+ (* y1 (- (+ x32 y32) x22 y22))
                  (* y2 (- (+ x12 y12) x32 y32))
                  (* y3 (- (+ x22 y22) x12 y12))
               )
               adenom 2.0
            )
         )
         (cond
            ((not (zerop (- y1 y2)))
               (/ (- (+ x12 y12) x22 y22 (* 2.0 a (- x1 x2)))
                  (- y1 y2) 2.0
               )
            )
            ((not (zerop (- y1 y3)))
               (/ (- (+ x12 y12) x32 y32 (* 2.0 a (- x1 x3)))
                  (- y1 y3) 2.0
               )
            )
            ((not (zerop (- y2 y3)))
               (/ (- (+ x22 y22) x32 y32 (* 2.0 a (- x2 x3)))
                  (- y2 y3) 2.0
               )
            )
         )
         z
      )
   )
)

John F. Uhden

Message 7 of 11
jinkinglee
in reply to: Kent1Cooper

;;Question this way 
;;the intersection of line and arc. Make point name= X_1
;;Next: How can make Dimension Line From P5 to X_1. now 10.5489
;;I want just like drawing now.
;;Thanks Jin

Message 8 of 11
john.uhden
in reply to: jinkinglee

My apologies.  I should have read more closely earlier.

 

@jinkinglee wrote:

 

"What I want is

Make P_1 a variable
Creating a setq variable point
(SETQ P_1 (INTERSE p_E p_16 p_13 NIL))
(Setq P_1 (polar P_1 0.0 0.25)


I want to create a point by finding the intersection of line and arc."

 

Do you really have an INTERSE function, or do you mean INTERS?  If the latter, it requires 4 points.  3 points and a nil won't suffice.

If you want to do this programmatically then you have to have sufficient data to represent the line and the arc.

I have given you the functions you can use.  Maybe you just need a little guidance in how to use them?

Would three (3) points for the arc definition work for you, or could you come up with the center (aka radius point), radius, beginning angle, and ending angle on your own?

 

Maybe you would prefer @Kent1Cooper's semi-graphical method, which is fine, but at that rate an "apparent intersection" might work just as well.

 

Are the line and arc at the same elevation (Z value)?  If not, do you want a 2D answer (where Z=0)?

 

John F. Uhden

Message 9 of 11
CADaSchtroumpf
in reply to: jinkinglee

After line

(Command "arc" P4 O P1)

 

No find intersecting between line and arc, but just polar with center and radius

(setq x_1 (polar (cdr (assoc 10 (entget (entlast)))) 0.0 (cdr (assoc 40 (entget (entlast))))))
(command "_dimlinear" P5 x_1 pause)

Message 10 of 11
Kent1Cooper
in reply to: jinkinglee


@jinkinglee wrote:

;;Question this way 
;;the intersection of line and arc. Make point name= X_1
;;Next: How can make Dimension Line From P5 to X_1. now 10.5489
;;I want just like drawing now.
;;Thanks Jin


If the relationships will not always be just the same as in the sample code and drawing, so that @CADaSchtroumpf's suggestion in Post 9 may not always apply, then you can do just as I suggested in Post 2 -- save the Line and Arc as VLA objects immediately after drawing each one, so you can find their intersection:

 

  (command "line" P5 P6 "")

  (setq linobj (vlax-ename->vla-object (entlast)))

  (Command "arc" P4 O P1)

  (setq arcobj (vlax-ename->vla-object (entlast)))

  (setq X_1 (vlax-invoke linobj 'intersectwith arcobj acExtendNone))

 

and then do the Dimension from P5 to X_1 as already suggested.  Or you could eliminate the pause for User input on the Dimension line location, something like:

  (command "_.dimlinear" P5 X_1 (polar P5 pid 1))

Kent Cooper, AIA
Message 11 of 11
jinkinglee
in reply to: Kent1Cooper

Thanks

I found what i want

Make the intersection of line and arc.

 

Jin

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost