ramon Posted November 19, 2019 Posted November 19, 2019 I have a program that will connect to lines to same size circles. however I need these lines to connect to different size circles.can anyone help me out? I added the program and also a picture of what the finished program i need help with is to accomplish. RSF-MakeSlot.LSP tangent.pdf Quote
BIGAL Posted November 19, 2019 Posted November 19, 2019 Way to much code Line tan tan all done Do you want it trimmed as well ? Quote
BIGAL Posted November 20, 2019 Posted November 20, 2019 Try this work in a clock direction when picking tangents ; draw 2 tangents to circle and trim circles ; By Alanh Nov 2019 ; info@alanh.com.aut (vl-load-com) (defun c:cslot ( / obj1 obj2 pt1 pt2 start1 start2 end1 end2) (princ "\nPick tangents work around clock") (command "line" "_tan" pause "_tan" pause "") (setq obj1 (entlast)) (command "line" "_tan" pause "_tan" pause "") (setq obj2 (entlast)) (setq obj (vlax-ename->vla-object obj1)) (setq start1 (vlax-get Obj 'StartPoint)) (setq end1 (vlax-get Obj 'EndPoint)) (setq obj (vlax-ename->vla-object obj2)) (setq start2 (vlax-get Obj 'StartPoint)) (setq end2 (vlax-get Obj 'EndPoint)) (command "Line" start1 end2 "") (setq obj1 (entlast)) (command "Line" start2 end1 "") (setq obj2 (entlast)) (setq pt1 (polar start1 (angle start1 end2) (/ (distance start1 end2) 2.0))) (setq pt2 (polar start2 (angle start2 end1) (/ (distance start2 end1) 2.0))) (command "trim" obj1 obj2 "" "f" pt1 pt2 "" "") (command "erase" obj1 obj2 "") (princ) ) Quote
dlanorh Posted November 20, 2019 Posted November 20, 2019 Try the attached. Asks for a selection set of two circles, draws a polyline slot on the current layer and deletes the circles. c2slot.LSP Quote
BIGAL Posted November 21, 2019 Posted November 21, 2019 Another bit simpler in the maths pick 2 circles use offsets to work out approx. tan points then as before code as above. Now need time to try it. Quote
ramon Posted November 21, 2019 Author Posted November 21, 2019 On 11/19/2019 at 7:17 PM, BIGAL said: Try this work in a clock direction when picking tangents ; draw 2 tangents to circle and trim circles ; By Alanh Nov 2019 ; info@alanh.com.aut (vl-load-com) (defun c:cslot ( / obj1 obj2 pt1 pt2 start1 start2 end1 end2) (princ "\nPick tangents work around clock") (command "line" "_tan" pause "_tan" pause "") (setq obj1 (entlast)) (command "line" "_tan" pause "_tan" pause "") (setq obj2 (entlast)) (setq obj (vlax-ename->vla-object obj1)) (setq start1 (vlax-get Obj 'StartPoint)) (setq end1 (vlax-get Obj 'EndPoint)) (setq obj (vlax-ename->vla-object obj2)) (setq start2 (vlax-get Obj 'StartPoint)) (setq end2 (vlax-get Obj 'EndPoint)) (command "Line" start1 end2 "") (setq obj1 (entlast)) (command "Line" start2 end1 "") (setq obj2 (entlast)) (setq pt1 (polar start1 (angle start1 end2) (/ (distance start1 end2) 2.0))) (setq pt2 (polar start2 (angle start2 end1) (/ (distance start2 end1) 2.0))) (command "trim" obj1 obj2 "" "f" pt1 pt2 "" "") (command "erase" obj1 obj2 "") (princ) ) Quote
ramon Posted November 21, 2019 Author Posted November 21, 2019 BIGAL. Thank you so much. This is exactly what I was trying to accomplish. I appreciate it. I might have one more lisp program that I am having a hard time putting together. Would you be willing to take a look at it if I can not get it right? Quote
hanhphuc Posted November 21, 2019 Posted November 21, 2019 (edited) 23 hours ago, BIGAL said: Another bit simpler in the maths pick 2 circles use offsets to work out approx. tan points then as before code as above. Now need time to try it. @BIGAL beware - offset method not always tangent, try if circle2 radius greater 5x than circle1, the line may intersects with bigger circle. should check secant. here' a bit math, not trim command (defun c:slot (/ s an a1 a2 cc c1 c2 d1 d2 r1 r2) ;hanhphuc 21.11.2019 (and (while (or (prompt "\nSelect ONLY 2 circles, <ENTER> to accept.. ") (not s) (> (sslength s) 2)) (setq s (ssget "_:E:L+." '((0 . "CIRCLE")))) ) (mapcar ''((a b) (mapcar 'set a (mapcar ''((i) (cdr (assoc i (entget b)))) '(10 40)))) '((c1 r1) (c2 r2)) (setq cc (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))) ) (setq d1 (distance c1 c2) a1 (angle c1 c2) d2 (- r1 r2) ) (< (abs d2) d1) ; bug fixed LM:2CircleTangents ;;; a2 (+ (* pi 0.5) (asin (/ r2 (* 2. d1)))) ; bug? (setq a2 (atan (sqrt (- (* d1 d1) (* d2 d2))) d2) an (list (+ a1 a2) (- a1 a2)) ep (mapcar ''((x) (setq x (eval (cons 'vl-list* x))) (entmakex (cons '(0 . "ARC") (mapcar 'cons '(10 40 50 51) x))) (mapcar ''((i) (polar (car x) (nth i x) (cadr x))) '(2 3)) ) '((c1 r1 an) (c2 r2 (reverse an))) ) ) (foreach x (apply 'mapcar (cons 'list (list (car ep) (reverse (cadr ep))))) (entmakex (cons '(0 . "LINE") (mapcar ''((a b) (cons a b)) '(10 11) x))) ) (mapcar 'entdel cc) ) (princ) ) Edited November 22, 2019 by hanhphuc (< (abs d2) d1) ; bug fixed refer to LM:2CircleTangents Quote
marko_ribar Posted November 21, 2019 Posted November 21, 2019 (edited) Shouldn't a2 be, just : (setq a2 (atan d2 d1)); and (setq d2 (abs (- r1 r2))) Edited November 21, 2019 by marko_ribar Quote
marko_ribar Posted November 21, 2019 Posted November 21, 2019 33 minutes ago, marko_ribar said: Shouldn't a2 be, just : (setq a2 (atan d2 d1)); and (setq d2 (abs (- r1 r2))) I just checked your code and it seems that you are right, although I don't quite know how you derived that formula and for what is worth it works as tangents and not what I initially thought as like shown on pictures... Quote
Lee Mac Posted November 21, 2019 Posted November 21, 2019 You may wish to consider my Circle Tangents program or my LM:2CircleTangents function for this task. 1 Quote
marko_ribar Posted November 21, 2019 Posted November 21, 2019 47 minutes ago, marko_ribar said: I just checked your code and it seems that you are right, although I don't quite know how you derived that formula and for what is worth it works as tangents and not what I initially thought as like shown on pictures... I got it... I wrongly visualized pitagoras triangle... Distance of tangent line between 2 circles is one edge of triangle wich hipotenuse is d1... So tangent = (sqrt (- (* d1 d1) (* d2 d2)))... And angle for addition/subtraction is angle of that triangle (bigger angle and not like in my wrong formula smaller one - my bad a2=(atan d2 d1)...) Quote
BIGAL Posted November 21, 2019 Posted November 21, 2019 hanhphuc just using the end points as a approximate pick point for the TAN selection so in my original code 2 picks now rather than 4. Need time to redo, lots on at moment. line tan pt1 tan pt2 Quote
hanhphuc Posted November 22, 2019 Posted November 22, 2019 7 hours ago, Lee Mac said: You may wish to consider my Circle Tangents program or my LM:2CircleTangents function for this task. as usual @Lee Mac very elegant code! dynamic & perfect math bulged Lwpolyline !! i never thought if 2 circle same position or smaller circle inside big circle - error occurs so i fixed based on your LM:2CircleTangents thanks (< (abs d2) d1) ; bug fixed LM Quote
hanhphuc Posted November 22, 2019 Posted November 22, 2019 (edited) 7 hours ago, marko_ribar said: I got it... I wrongly visualized pitagoras triangle... Distance of tangent line between 2 circles is one edge of triangle wich hipotenuse is d1... So tangent = (sqrt (- (* d1 d1) (* d2 d2)))... And angle for addition/subtraction is angle of that triangle (bigger angle and not like in my wrong formula smaller one - my bad a2=(atan d2 d1)...) A picture is worth a thousand words D2 either R1-R2 or R2-R1 just concept to visualize Edited November 22, 2019 by hanhphuc Quote
Lee Mac Posted November 22, 2019 Posted November 22, 2019 10 hours ago, hanhphuc said: as usual @Lee Mac very elegant code! dynamic & perfect math bulged Lwpolyline !! Many thanks @hanhphuc Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.