Jump to content

creating slots


ramon

Recommended Posts

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

 

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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? 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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