PDA

View Full Version : get the tangential point

kalai
19th May 2011, 09:51 am
my coding

(setq p1 '(500 200 0)
(command "circle" ' (0 0 0) 10)

now at this point i have to draw line from p1 to tangential point on circle.
how can thisbe done?
help me.

Tharwat
19th May 2011, 11:38 am
This ?

(setq p1 '(500 200 0))
(command "circle" ' (0. 0. 0.) 10.)
(setq obj (entlast))
(setq obj (vlax-ename->vla-object obj))
(setq p2 (vlax-curve-getClosestPointTo obj p1))
(entmakex (list (cons 0 "LINE")(cons 10 p1)(cons 11 p2)))

Lee Mac
19th May 2011, 11:48 am
Tharwat,

The closest point will be perpendicular, not tangential.

Lee Mac
19th May 2011, 12:06 pm
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.

(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:

(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:

(defun LM:GetTangentPoints ( pt cen rad / a1 d1 tn )

(if (< rad (setq a1 (angle cen pt) d1 (distance pt cen)))
(progn
(list
(trans (polar cen (+ a1 tn) rad) 1 0)
(trans (polar cen (- a1 tn) rad) 1 0)
)
)
)
)

David Bethel
19th May 2011, 12:17 pm
As a starting point:

This should give you length of the tangent line ( s2 ) and the length of the 3 sides forming a right triangle.

(setq p1 '(6 2 0) ;;;PICK POINT
ce '(0 0 0) ;;;CIRCLE CENTER

(setq s3 (distance ce p1)
s1 ra
s2 (sqrt (- (* s3 s3) (* s1 s1))))

-David

paulmcz
19th May 2011, 01:43 pm
This is what I would write:

(setq osn (getvar "osmode")
p1 '(0.0 0.0 0.0)
r 10.0
dx 500.0
dy 200.0
a (sqrt (+ (* dx dx) (* dy dy)))
b (sqrt (- (* a a) (* r r)))
u1 (atan (/ dy dx))
u2 (atan (/ b r))
up (+ u1 u2)
down (- u1 u2)
p2 (polar p1 up r)
p3 (polar p1 down r)
p4 (polar p1 u1 a)
)
(setvar "osmode" 0)
(command "circle" p1 r)
(command "line" p2 p4 p3"")
(setvar "osmode" osn)