Jump to content

Recommended Posts

Posted

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

Posted

Way to much code 

 

Line tan tan all done 

 

Do you want it trimmed as well  ?

Posted

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)
)

 

Posted

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

Posted

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.

 

image.png.e37b146274a01ed1decf3f5ccfc5b8a2.png

 

Posted
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)
)

 

 

Posted

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? 

Posted (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.

 

image.png.e37b146274a01ed1decf3f5ccfc5b8a2.png

 

 

@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 by hanhphuc
(< (abs d2) d1) ; bug fixed refer to LM:2CircleTangents
Posted (edited)

Shouldn't a2 be, just : (setq a2 (atan d2 d1)); and (setq d2 (abs (- r1 r2)))

Edited by marko_ribar
Posted
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...

Posted
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)...)

Posted

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

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

 

slot.png

Edited by hanhphuc

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...