This will return the two points (in WCS) which are tangent to the supplied circle entity from the supplied point projected onto the plane in which the Circle resides; or nil if the supplied point lies inside the circle.
Code:
(defun LM:GetTangentPoints ( pt ci / a1 c1 d1 el r1 tn )
(setq el (entget ci)
c1 (cdr (assoc 10 el))
r1 (cdr (assoc 40 el))
d1 (distance pt c1) a1 (angle c1 pt)
)
(if (< r1 d1)
(progn
(setq tn (sqrt (- (* d1 d1) (* r1 r1)))
tn (atan tn r1)
)
(list
(trans (polar c1 (+ a1 tn) r1) ci 0)
(trans (polar c1 (- a1 tn) r1) ci 0)
)
)
)
)
A test function:
Code:
(defun c:test ( / e p )
(if
(and
(setq e (car (entsel "\nSelect Circle: ")))
(eq "CIRCLE" (cdr (assoc 0 (entget e))))
(setq p (getpoint "\nSpecify Point: "))
(setq p (trans p 1 0))
)
(foreach x (LM:GetTangentPoints (trans p 0 e) e)
(entmakex
(list (cons 0 "LINE") (cons 10 p) (cons 11 x))
)
)
)
(princ)
)
Alternatively, here is a function accepting a Point, Circle Center and Circle Radius:
Code:
(defun LM:GetTangentPoints ( pt cen rad / a1 d1 tn )
(if (< rad (setq a1 (angle cen pt) d1 (distance pt cen)))
(progn
(setq tn (atan (sqrt (- (* d1 d1) (* rad rad))) rad))
(list
(trans (polar cen (+ a1 tn) rad) 1 0)
(trans (polar cen (- a1 tn) rad) 1 0)
)
)
)
)
Bookmarks