Author Topic: How to make a line tangent to an arc in lisp  (Read 4402 times)

0 Members and 1 Guest are viewing this topic.

jitupnair

  • Guest
How to make a line tangent to an arc in lisp
« on: June 27, 2010, 12:45:16 AM »
How to find tangent point of an arc using lisp.

Regards

Jithesh

MeasureUp

  • Bull Frog
  • Posts: 465
Re: How to make a line tangent to an arc in lisp
« Reply #1 on: June 27, 2010, 07:08:54 AM »
Try this.
Code: [Select]
(defun c:TANGENT_LINE (/ OSMODE_0 Pt01 Pt02)
(setq OSMODE_0 (getvar "osmode"))
(setvar "osmode" 512)
(setq Pt01 (getpoint "Select 1st point: ")
      Pt02 (getpoint "Select 2nd point on a circle/arc: ")
); end of setq
(if (/= PEDITACCEPT 1)
    (setvar "PEDITACCEPT" 1))
(command "._line" "_tan" Pt01 "_tan" Pt02 "")
(setvar "osmode" OSMODE_0)
(princ)
); end of program

jitupnair

  • Guest
Re: How to make a line tangent to an arc in lisp
« Reply #2 on: June 27, 2010, 09:27:50 AM »
Thanks for your replay.
In my case I have a known point and an arc entity name. Without selecting the arc again I need to make a line from the known point to tangent to the arc.
In your program I have to select a point on the arc.

Jithesh

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: How to make a line tangent to an arc in lisp
« Reply #3 on: June 27, 2010, 09:56:40 AM »
Hi,

It's quite difficult to reply knowing so little...

Form a given point, there can be two, one or none tangent to an arc.
If two are able, wich one do you want to draw ?

Here's a way using 'command':

closer to the arc start point
Code: [Select]
(command "_.line" "_non" yourPoint "_tan" (vlax-curve-getStartPoint yourArc) "")
closer to the arc end point
Code: [Select]
(command "_.line" "_non" yourPoint "_tan" (vlax-curve-getEndPoint yourArc) "")
If youy want to avoid using the 'command' function, you can use a geometric method
The tangent points from a point to a circle are the intersection points betwenn the circle and another one wich center is the middle of the line between the circle center and the point and which radius is the half of this line length (see picture).



Here's a quick and dirty (no error handler) using this method

Code: [Select]
;; TangentToArc (gile)
;; Returns the tangent points list from the given point to the arc (or circle)
;;
;; Arguments
;; arc: an arc or circle (vla-object)
;; pt: a 3d point

(defun TangentToArc (arc pt / mid tmp)
  (vl-load-com)
  (setq mid (mapcar '(lambda (x1 x2) (/ (+ x1 x2) 2.))
    (vlax-get arc 'Center)
    pt
    )
tmp (vla-AddCircle
      (vla-get-ModelSpace
(vla-get-ActiveDocument (vlax-get-acad-object))
      )
      (vlax-3d-point mid)
      (distance mid pt)
    )
  )
  (if (setq int (vlax-invoke arc 'IntersectWith tmp acExtendNone))
    (setq int
   (cons
     (list (car int) (cadr int) (caddr int))
     (if (cdddr int)
       (list (list (nth 3 int) (nth 4 int) (nth 5 int)))
     )
   )
    )
  )
  (vla-Delete tmp)
  int
)
Speaking English as a French Frog

jitupnair

  • Guest
Re: How to make a line tangent to an arc in lisp
« Reply #4 on: June 27, 2010, 11:59:54 PM »
Thank you verymuch Gile,
Its working perfectly. Actually my aim is to make a program shown in this link. http://www.theswamp.org/index.php?topic=33861.0.

Thanks again .

Jithesh