My grain of sand
another. Selecting 3 points. The third point will be on one side or the other of the main alignment.
The radius is equal to the distance from p3 to the line p1-p2/2
(defun punto_izda_dcha (p1 p2 p3 / a b c)
(defun det3 (a b c)
(+ (det2 b c) (det2 a b) (- (det2 a c)))
)
(defun det2 (a b)
(- (* (car a) (cadr b)) (* (car b) (cadr a)))
)
(setq resultado (/ (det3 p1 p2 p3) 2))
)
(defun c:llave (/ pt1 pt2 pt3 dist_pt1_pt2 radio bulge p2aux p3aux p4aux p5aux p6aux
area ang_perp)
(if (= cal nil) (arxload "geomcal"))
(setq pt1 (getpoint "\nIndica el punto 1: "))
(setq pt2 (getpoint "\nIndica el punto 2: "))
(setq pt3 (getpoint "\nIndica el punto 3: "))
(setq dist_pt1_pt2 (distance pt1 pt2))
(setq radio (/ (c:cal "dpl(pt3,pt1,pt2)") 2.))
(setq bulge (abs(- 1 (sqrt 2))))
(cond ((equal (c:cal "dpl(pt3,pt1,pt2)") 0.0 0.01)
(setq radio (/ dist_pt1_pt2 8))
)
((> (* (c:cal "dpl(pt3,pt1,pt2)") 4) dist_pt1_pt2)
(setq radio (/ dist_pt1_pt2 4))
)
)
(setq p2aux (polar pt1 (angle pt1 pt2) radio))
(setq p4aux (mapcar '(lambda (x y) (/ (+ x y) 2)) pt1 pt2))
(setq p3aux (polar p4aux (angle pt2 pt1) radio))
(setq p5aux (polar p4aux (angle pt1 pt2) radio))
(setq p6aux (polar pt2 (angle pt2 pt1) radio))
(setq area (punto_izda_dcha pt1 pt2 pt3))
(if (< area 0)
(setq ang_perp (+ (angle pt1 pt2) (* (/ pi 2)3)))
(setq ang_perp (+ (angle pt1 pt2) (/ pi 2)))
)
(setq p2 (polar p2aux ang_perp radio))
(setq p3 (polar p3aux ang_perp radio))
(setq p4 (polar p4aux ang_perp (* radio 2)))
(setq p5 (polar p5aux ang_perp radio))
(setq p6 (polar p6aux ang_perp radio))
(entmake (list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(90 . 7)
'(43 . 0.25);grosor
'(38 . 0.0);elevacion
'(62 . 1);color por capa
(list 10 (car pt1) (cadr pt1))
'(40 . 0.0) '(41 . 0.0)
(if (< area 0) (cons 42 bulge) (cons 42 (- bulge)))
(list 10 (car p2) (cadr p2))
'(40 . 0.0) '(41 . 0.0) '(42 . 0.0)
(list 10 (car p3) (cadr p3))
'(40 . 0.0) '(41 . 0.0)
(if (< area 0) (cons 42 (- bulge)) (cons 42 bulge))
(list 10 (car p4) (cadr p4))
'(40 . 0.0) '(41 . 0.0)
(if (< area 0) (cons 42 (- bulge)) (cons 42 bulge))
(list 10 (car p5) (cadr p5))
'(40 . 0.0) '(41 . 0.0) '(42 . 0.0)
(list 10 (car p6) (cadr p6))
'(40 . 0.0) '(41 . 0.0)
(if (< area 0) (cons 42 bulge) (cons 42 (- bulge)))
(list 10 (car pt2) (cadr pt2))
'(40 . 0.0) '(41 . 0.0) '(42 . 0.0)
'(210 0.0 0.0 1.0)
))
)