Author Topic: connect with arc  (Read 1774 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
connect with arc
« on: January 19, 2014, 07:11:14 AM »
I'll post code here for a change, if there is some suggestions they are welcomed... (Firstly thought to do it in show stuff forum, but then not logged members can't see it - and maybe someone can not be member - sign up denied)

Now to the code - it's almost the same as fillet, only there is no radius and extension to arc, but arc is drawn from end of first entity to end of second, and there is one little trick - you have to adjust positions of connecting pieces to touch end points with connected arc... So little tweaking and that's it... Think this can be helpful routine also... Only had problems when using join command - don't know jet why - vertices are the same - tried picking and stretching with mouse and it shows single common vertex - 2 vertices...

Code - Auto/Visual Lisp: [Select]
  1. ;; Coplanar-p  -  Lee Mac
  2. ;; Returns T if points p1,p2,p3,p4 are coplanar
  3.  
  4. (defun LM:Coplanar-p ( p1 p2 p3 p4 )
  5.     (
  6.         (lambda ( n )
  7.             (equal
  8.                 (last (trans p3 0 n))
  9.                 (last (trans p4 0 n))
  10.                 1e-8
  11.             )
  12.         )
  13.         (v^v (mapcar '- p1 p2) (mapcar '- p1 p3))
  14.     )
  15. )
  16.  
  17. (defun v^v ( u v / cda )
  18.   (defun cda ( p ) (cdr (append p p)))
  19.   (mapcar '- (mapcar '* (cda u) (cdr (cda v))) (mapcar '* (cdr (cda u)) (cda v)) '(0.0 0.0 0.0))
  20. )
  21.  
  22. (defun unit ( v )
  23.   (mapcar '(lambda ( x ) (/ x (distance '(0.0 0.0 0.0) v))) v)
  24. )
  25.  
  26. (defun marc ( c p1 p2 / dxf10 dxf40 dxf210 dxf50 dxf51 uz )
  27.   (setq dxf10 (trans c 0 (setq uz (v^v (mapcar '- p1 c) (mapcar '- p2 c)))))
  28.   (setq dxf40 (distance c p1))
  29.   (setq dxf210 (unit uz))
  30.   (setq dxf50 (angle dxf10 (trans p1 0 uz)))
  31.   (setq dxf51 (angle dxf10 (trans p2 0 uz)))
  32.   (entmake (list '(0 . "ARC") '(100 . "AcDbEntity") '(100 . "AcDbCircle") (cons 10 dxf10) (cons 40 dxf40) (cons 210 dxf210) '(100 . "AcDbArc") (cons 50 dxf50) (cons 51 dxf51)))
  33. )
  34.  
  35. (defun c:ca ( / e1 e2 ent1 ent2 p1 p2 par1 par2 der1 der2 p11 p22 nor n1 n2 p111 p222 c )
  36.   (setq e1 (entsel "\nPick first end point - first curve for connection with arc"))
  37.   (setq e2 (entsel "\nPick second end point - second curve for connection with arc"))
  38.   (setq ent1 (car e1) p1 (cadr e1))
  39.   (setq ent2 (car e2) p2 (cadr e2))
  40.   (setq par1 (vlax-curve-getparamatpoint ent1 p1))
  41.   (setq par2 (vlax-curve-getparamatpoint ent2 p2))
  42.   (if (< (- par1 (vlax-curve-getstartparam ent1)) (- (vlax-curve-getendparam ent1) par1))
  43.     (setq p1 (vlax-curve-getstartpoint ent1))
  44.     (setq p1 (vlax-curve-getendpoint ent1))
  45.   )
  46.   (if (< (- par2 (vlax-curve-getstartparam ent2)) (- (vlax-curve-getendparam ent2) par2))
  47.     (setq p2 (vlax-curve-getstartpoint ent2))
  48.     (setq p2 (vlax-curve-getendpoint ent2))
  49.   )
  50.   (if (or (equal der1 der2 1e-6) (equal der1 (mapcar '* der2 '(-1.0 -1.0 -1.0)) 1e-6))
  51.     (alert "\nTangents on picked end points are colinear or parallel - unable to connect with arc")
  52.     (progn
  53.       (setq p11 (mapcar '+ p1 der1))
  54.       (setq p22 (mapcar '+ p2 der2))
  55.       (if (LM:Coplanar-p p1 p2 p11 p22)
  56.         (progn
  57.           (setq nor (v^v (mapcar '- p11 p1) (mapcar '- p22 p2)))
  58.           (setq n1 (v^v nor (mapcar '- p11 p1)))
  59.           (setq n2 (v^v nor (mapcar '- p22 p2)))
  60.           (setq p111 (mapcar '+ p1 n1))
  61.           (setq p222 (mapcar '+ p2 n2))
  62.           (setq c (inters p1 p111 p2 p222 nil))
  63.           (marc c p1 p2)
  64.         )
  65.         (alert "\nTangents on picked end points aren't coplanar - unable to connect with arc")
  66.       )
  67.     )
  68.   )
  69.   (princ)
  70. )
  71.  

HTH, M.R.
« Last Edit: January 22, 2014, 06:45:07 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube