두 직선에 접하는 호 그리는 리습입니다.

; Draws a arc with a specified radius and tangent to two lines.
; approach: outside point of a circle / direction from the point / finding center point
; tangent points from the pythagorean theorem c^2 = a^2 + b^2
(defun c:ttr()
(setq radi (getdist “Enter radius”)) ;Specifying radius
(setvar “osmode” 0) ;Osnap None
(setq ftl (entsel)) ;First tangent line
(setq stl (entsel)) ;Second tangent line
(setq fsp (cdr (assoc 10 (entget (car ftl))))) ;Start point of the ftl
(setq fep (cdr (assoc 11 (entget (car ftl))))) ;Endpoint of the ftl
(setq ssp (cdr (assoc 10 (entget (car stl))))) ;Start point of the stl
(setq sep (cdr (assoc 11 (entget (car stl))))) ;Endpoint of the stl
(setq pt1 (inters fsp fep ssp sep nil)) ;Intersection point
(setq mpt1 (mapcar ‘(lambda (x) (/ x 2.0) ) (mapcar ‘+ fsp fep))) ;Midpoint of the ftl
(setq mpt2 (mapcar ‘(lambda (x) (/ x 2.0) ) (mapcar ‘+ ssp sep))) ;Midpoint of the stl
(setq centroid (mapcar ‘(lambda (x) (/ x 3.0) ) (mapcar ‘+ pt1 mpt1 mpt2)))
;Centroid of the three points, determining offset direction.
(command “offset” radi ftl centroid “”) ;Offset line from the ftl
(setq line1 (entlast))
(command “offset” radi stl centroid “”) ;Offset line from the stl
(setq line2 (entlast))
(setq dxf1 (entget line1))
(setq sp1 (cdr (assoc 10 dxf1))) ;Start point of the line1 (setq ep1 (cdr (assoc 11 dxf1))) ;Endpoint of the line1
(setq dxf2 (entget line2))
(setq sp2 (cdr (assoc 10 dxf2))) ;Start point of the line2
(setq ep2 (cdr (assoc 11 dxf2))) ;Endpoint of the line2
(setq center (inters sp1 ep1 sp2 ep2 nil)) ;Center of the arc
(setq dist (distance pt1 center)) ;Distance betweeon pt1 and center (hypotenuse)
(setq tl(sqrt (- (expt dist 2) (expt radi 2)))) ;Tangent legnth from pt1
(setq tpt1 (polar pt1 (angle pt1 mpt1) tl)) ;Tangent point1
(setq tpt2 (polar pt1 (angle pt1 mpt2) tl)) ;Tangent point2
(command “erase” line1 line2 “”)
(command “arc” tpt1 “E” tpt2 “d” pt1 )
;Draws the arc using starpoint, endpoint, tangent direction
(setvar “osmode” (+ 1 32 128 2048))
(princ)
)