Author Topic: Arc with START, END, MIDDLE points?  (Read 2654 times)

0 Members and 1 Guest are viewing this topic.

V@no

  • Newt
  • Posts: 25
  • AutoCAD 2023
Arc with START, END, MIDDLE points?
« on: April 22, 2023, 11:04:45 AM »
Hello.

I'm looking for a way to draw an arc by using this EXACT order of points:
1. START
2. END
3. MIDDLE (bulge)

With showing preview of the arc during selection of 3nd point which should be "attached" to the cursor as if middle grip of the arc is being dragged and ability to use osnap with each of the 3 points


The drawing A (see screenshot) is the arc I'm looking for, but this was done by using arc command and selecting 1,3,2 points
when selecting 1,2,3 points it produces arc C
Drawing B is "Start, End, Radius" type, which draws correct geometry arc, but on opposite side.
None of the available commands produce the desired result.

3-points-circle does exactly what I'm looking for but with circle. At the moment I'm using it as a work around.

There is a script I've seen that uses grread to track the cursor and show the arc, but it doesn't allow osnap functionality.
People suggested to look for grSnap by LeeMac, which would definitely work, but I think it's overly complicated for this...

So, my thought was maybe there is a way after selecting first 2 points, draw an arc with 0 bulge (that's easy) and then somehow grab the middle of it to "attach" to the cursor simulating dragging a grip? is this possible?

Thank you.
« Last Edit: April 23, 2023, 08:24:59 AM by V@no »

liuhe

  • Mosquito
  • Posts: 8
Re: Arc with START, END, CENTER points?
« Reply #1 on: April 22, 2023, 11:24:31 AM »
Lisp has no other function that supports previewing except for grread, unless you load the real-time capture function of ENTITYJIG written in C # or C++

ribarm

  • Gator
  • Posts: 3313
  • Marko Ribar, architect
Re: Arc with START, END, CENTER points?
« Reply #2 on: April 22, 2023, 11:55:49 AM »
Your picture doesn't relate to title of the task...
What do you need START, END, MIDDLE, or START, END, CENTER...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

V@no

  • Newt
  • Posts: 25
  • AutoCAD 2023
Re: Arc with START, END, CENTER points?
« Reply #3 on: April 22, 2023, 12:20:07 PM »
Your picture doesn't relate to title of the task...
What do you need START, END, MIDDLE, or START, END, CENTER...
Not sure what's the difference there...
The picture shows the result from every possible arc commands selecting points in the correct order (1,2,3), where A is the desired result but achieved by selecting points in a wrong order.

ribarm

  • Gator
  • Posts: 3313
  • Marko Ribar, architect
Re: Arc with START, END, CENTER points?
« Reply #4 on: April 22, 2023, 01:24:28 PM »
Here is what I meant :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:arc-st-en-ce ( / LM:3pcircle LM:3parc MR:ce2parc st en mp an gr p pp ce arc arcs )
  2.  
  3.     ;; 3-Point Circle  -  Lee Mac
  4.     ;; Returns the center (UCS) and radius of the circle defined by three supplied points (UCS).
  5.  
  6.     (defun LM:3pcircle ( pt1 pt2 pt3 / cen md1 md2 vc1 vc2 )
  7.         (if (setq md1 (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) pt1 pt2)
  8.                   md2 (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) pt2 pt3)
  9.                   vc1 (mapcar '- pt2 pt1)
  10.                   vc2 (mapcar '- pt3 pt2)
  11.                   cen (inters md1 (mapcar '+ md1 (list (- (cadr vc1)) (car vc1) 0))
  12.                               md2 (mapcar '+ md2 (list (- (cadr vc2)) (car vc2) 0))
  13.                               nil
  14.                       )
  15.             )
  16.             (list cen (distance cen pt1))
  17.         )
  18.     )
  19.  
  20.     (defun LM:3parc ( pt1 pt2 pt3 / lst ocs arc )
  21.         (if (setq ocs (trans '(0.0 0.0 1.0) 1 0 t))
  22.             (if (setq lst (LM:3pcircle pt1 pt2 pt3))
  23.                 (progn
  24.                     (if (minusp (sin (- (angle pt1 pt3) (angle pt1 pt2))))
  25.                         (mapcar 'set '(pt1 pt3) (list pt3 pt1))
  26.                     )
  27.                     (setq arc
  28.                         (entmakex
  29.                             (list
  30.                                '(000 . "ARC")
  31.                                 (cons 010 (trans (car lst) 1 ocs))
  32.                                 (cons 040 (cadr lst))
  33.                                 (cons 050 (angle (trans (car lst) 1 ocs) (trans pt1 1 ocs)))
  34.                                 (cons 051 (angle (trans (car lst) 1 ocs) (trans pt3 1 ocs)))
  35.                                 (cons 210 ocs)
  36.                             )
  37.                         )
  38.                     )
  39.                 )
  40.                 (princ "\nPoints are collinear.")
  41.             )
  42.         )
  43.         (if arc
  44.             arc
  45.         )
  46.     )
  47.  
  48.     (defun MR:ce2parc ( ce st en / mp v1 pt arc d r )
  49.         (if
  50.             (and
  51.                 (setq mp (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) st en))
  52.                 (not (equal mp ce 1e-6))
  53.             )
  54.             (progn
  55.                 (setq v1 (mapcar '/ (mapcar '- mp ce) (list (setq d (distance mp ce)) d d)))
  56.                 (setq pt (mapcar '+ ce (mapcar '* v1 (list (setq r (distance ce st)) r r))))
  57.                 (setq arc (LM:3parc st pt en))
  58.             )
  59.         )
  60.         (if arc
  61.             arc
  62.         )
  63.     )
  64.  
  65.     (if
  66.         (and
  67.             (not (initget 1))
  68.             (setq st (getpoint "\nPick or specify start point : "))
  69.             (not (initget 1))
  70.             (setq en (getpoint st "\nPick or specify end point : "))
  71.             (setq mp (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) st en))
  72.             (setq an (angle st en))
  73.         )
  74.         (progn
  75.             (while (= (car (setq gr (grread t))) 5)
  76.                 (setq p (cadr gr))
  77.                 (setq ce (inters mp (polar mp (+ an (* 0.5 pi)) 1.0) p (polar p an 1.0) nil))
  78.                 (if
  79.                     (and
  80.                         ce
  81.                         (not (equal mp ce 1e-6))
  82.                     )
  83.                     (progn
  84.                         (grdraw p ce 3 3)
  85.                         (setq arcs (cons (setq arc (MR:ce2parc ce st en)) arcs))
  86.                         (if
  87.                             (and
  88.                                 arc
  89.                                 (not (equal pp p 1e-15))
  90.                             )
  91.                             (progn
  92.                                 (redraw)
  93.                                 (foreach arc arcs
  94.                                     (if (not (vlax-erased-p arc))
  95.                                         (entdel arc)
  96.                                     )
  97.                                 )
  98.                             )
  99.                         )
  100.                     )
  101.                 )
  102.                 (setq pp p)
  103.             )
  104.             (if ce
  105.                 (progn
  106.                     (foreach arc arcs
  107.                         (if (not (vlax-erased-p arc))
  108.                             (entdel arc)
  109.                         )
  110.                     )
  111.                     (setq arc (MR:ce2parc ce st en))
  112.                     (redraw arc)
  113.                 )
  114.             )
  115.         )
  116.     )
  117.     (princ)
  118. )
  119.  

Here you specify center point and in your picture you specify pt3 as middle point... The code could be altered for mid point though... I'll see to do it, if you want it that way... Firstly you decide is this good or not...
« Last Edit: April 23, 2023, 01:33:32 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3313
  • Marko Ribar, architect
Re: Arc with START, END, MIDDLE points?
« Reply #5 on: April 22, 2023, 01:32:10 PM »
And here is alteration of previous code :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:arc-st-en-mp ( / LM:3pcircle LM:3parc st en mp an gr p pp mpp arc arcs )
  2.  
  3.     ;; 3-Point Circle  -  Lee Mac
  4.     ;; Returns the center (UCS) and radius of the circle defined by three supplied points (UCS).
  5.  
  6.     (defun LM:3pcircle ( pt1 pt2 pt3 / cen md1 md2 vc1 vc2 )
  7.         (if (setq md1 (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) pt1 pt2)
  8.                   md2 (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) pt2 pt3)
  9.                   vc1 (mapcar '- pt2 pt1)
  10.                   vc2 (mapcar '- pt3 pt2)
  11.                   cen (inters md1 (mapcar '+ md1 (list (- (cadr vc1)) (car vc1) 0))
  12.                               md2 (mapcar '+ md2 (list (- (cadr vc2)) (car vc2) 0))
  13.                               nil
  14.                       )
  15.             )
  16.             (list cen (distance cen pt1))
  17.         )
  18.     )
  19.  
  20.     (defun LM:3parc ( pt1 pt2 pt3 / lst ocs arc )
  21.         (if (setq ocs (trans '(0.0 0.0 1.0) 1 0 t))
  22.             (if (setq lst (LM:3pcircle pt1 pt2 pt3))
  23.                 (progn
  24.                     (if (minusp (sin (- (angle pt1 pt3) (angle pt1 pt2))))
  25.                         (mapcar 'set '(pt1 pt3) (list pt3 pt1))
  26.                     )
  27.                     (setq arc
  28.                         (entmakex
  29.                             (list
  30.                                '(000 . "ARC")
  31.                                 (cons 010 (trans (car lst) 1 ocs))
  32.                                 (cons 040 (cadr lst))
  33.                                 (cons 050 (angle (trans (car lst) 1 ocs) (trans pt1 1 ocs)))
  34.                                 (cons 051 (angle (trans (car lst) 1 ocs) (trans pt3 1 ocs)))
  35.                                 (cons 210 ocs)
  36.                             )
  37.                         )
  38.                     )
  39.                 )
  40.                 (princ "\nPoints are collinear.")
  41.             )
  42.         )
  43.         (if arc
  44.             arc
  45.         )
  46.     )
  47.  
  48.     (if
  49.         (and
  50.             (not (initget 1))
  51.             (setq st (getpoint "\nPick or specify start point : "))
  52.             (not (initget 1))
  53.             (setq en (getpoint st "\nPick or specify end point : "))
  54.             (setq mp (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) st en))
  55.             (setq an (angle st en))
  56.         )
  57.         (progn
  58.             (while (= (car (setq gr (grread t))) 5)
  59.                 (setq p (cadr gr))
  60.                 (setq mpp (inters mp (polar mp (+ an (* 0.5 pi)) 1.0) p (polar p an 1.0) nil))
  61.                 (if
  62.                     (and
  63.                         mpp
  64.                         (not (equal mp mpp 1e-6))
  65.                     )
  66.                     (progn
  67.                         (grdraw p mpp 3 3)
  68.                         (setq arcs (cons (setq arc (LM:3parc st mpp en)) arcs))
  69.                         (if
  70.                             (and
  71.                                 arc
  72.                                 (not (equal pp p 1e-15))
  73.                             )
  74.                             (progn
  75.                                 (redraw)
  76.                                 (foreach arc arcs
  77.                                     (if (not (vlax-erased-p arc))
  78.                                         (entdel arc)
  79.                                     )
  80.                                 )
  81.                             )
  82.                         )
  83.                     )
  84.                 )
  85.                 (setq pp p)
  86.             )
  87.             (if mpp
  88.                 (progn
  89.                     (foreach arc arcs
  90.                         (if (not (vlax-erased-p arc))
  91.                             (entdel arc)
  92.                         )
  93.                     )
  94.                     (setq arc (LM:3parc st mpp en))
  95.                     (redraw arc)
  96.                 )
  97.             )
  98.         )
  99.     )
  100.     (princ)
  101. )
  102.  

HTH.
M.R.
« Last Edit: April 23, 2023, 01:34:08 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

V@no

  • Newt
  • Posts: 25
  • AutoCAD 2023
Re: Arc with START, END, MIDDLE points?
« Reply #6 on: April 22, 2023, 01:35:14 PM »
So, "center" represents center point of the arc's radius. Obviously, that's not what I meant, but I got it, thanks, updated the original post.

ribarm

  • Gator
  • Posts: 3313
  • Marko Ribar, architect
Re: Arc with START, END, MIDDLE points?
« Reply #7 on: April 22, 2023, 02:56:16 PM »
I've updated my codes for better preview during execution of routines...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

V@no

  • Newt
  • Posts: 25
  • AutoCAD 2023
Re: Arc with START, END, MIDDLE points?
« Reply #8 on: April 22, 2023, 03:13:51 PM »
Thanks, unfortunately it doesn't allow use osnap during the preview.

ribarm

  • Gator
  • Posts: 3313
  • Marko Ribar, architect
Re: Arc with START, END, MIDDLE points?
« Reply #9 on: April 22, 2023, 03:53:40 PM »
If you need OSNAP functionality, implement it in already posted examples...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

BIGAL

  • Swamp Rat
  • Posts: 1444
  • 40 + years of using Autocad
Re: Arc with START, END, MIDDLE points?
« Reply #10 on: April 22, 2023, 07:44:45 PM »
Using a lisp what is problem ask for 3 points then do correct ARC command with points in the order required.
(command "arc" p1 p3 p2)
A man who never made a mistake never made anything

V@no

  • Newt
  • Posts: 25
  • AutoCAD 2023
Re: Arc with START, END, MIDDLE points?
« Reply #11 on: April 22, 2023, 08:07:14 PM »
Using a lisp what is problem ask for 3 points then do correct ARC command with points in the order required.
(command "arc" p1 p3 p2)
creating an arc is not the problem, the problem is creating an arc with a preview when setting last point, with ability to snap if desired (EXACTLY like (command "_circle" "_3p") does).

ribarm

  • Gator
  • Posts: 3313
  • Marko Ribar, architect
Re: Arc with START, END, MIDDLE points?
« Reply #12 on: April 23, 2023, 02:11:19 AM »
Why not just these 2 :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:3parc-S ( / st )
  2.   (if
  3.     (and
  4.       (not (initget 1))
  5.       (setq st (getpoint "\nPick or specify start point : "))
  6.     )
  7.     (vl-cmdf "_.ARC" "_non" st "\\" "\\")
  8.   )
  9.   (princ)
  10. )
  11.  

Or...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:3parc-C ( / st )
  2.   (if
  3.     (and
  4.       (not (initget 1))
  5.       (setq st (getpoint "\nPick or specify start point : "))
  6.     )
  7.     (vl-cmdf "_.ARC" "_non" st "_C" "\\" "\\")
  8.   )
  9.   (princ)
  10. )
  11.  
« Last Edit: May 07, 2023, 02:35:52 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

domenicomaria

  • Swamp Rat
  • Posts: 737
Re: Arc with START, END, MIDDLE points?
« Reply #13 on: April 23, 2023, 03:00:52 AM »
start, mid, end
Code - Auto/Visual Lisp: [Select]
  1. (defun C:A3P ( / p1 p2 )
  2.    (and
  3.       (setq p1 (getpoint "\nSTART  arc point <exit> : ") )
  4.       (setq p2 (getpoint "\nMID arc point <exit> : ") )
  5.       (princ "\nEND arc point : ")
  6.       (vl-cmdf "_pline" p1 "arc" "second" p2 "\\" "")
  7.       (vl-cmdf "explode" (entlast) )
  8.    )
  9.    (princ)
  10. )
« Last Edit: April 23, 2023, 08:15:30 AM by domenicomaria »

domenicomaria

  • Swamp Rat
  • Posts: 737
Re: Arc with START, END, MIDDLE points?
« Reply #14 on: April 23, 2023, 04:36:51 AM »
start, end, mid

maybe this is just what you want. . .

it's not elegant, but it seems to work

Code - Auto/Visual Lisp: [Select]
  1. (defun :DXF (code egl) (cdr (assoc code egl)))
  2.  
  3. (defun C:A3P (/ c-el c-en p1 p2 p3)
  4.    (and
  5.       (setq p1 (getpoint "\nSTART  arc point : ") )  
  6.       (setq p2 (getpoint "\nEND arc point : ") )      
  7.       (vl-cmdf "_circle" "3P" p1 p2)
  8.       (princ "\nMID arc point : ")
  9.       (vl-cmdf "\\")
  10.       (setq p3 (getvar "lastpoint") )
  11.       (setq c-en (entlast) )
  12.       (setq c-el (entget c-en) )
  13.       (= (:DXF 0 c-el) "CIRCLE")
  14.       (vl-cmdf "_pline" p1 "arc" "second" p3 p2 "")
  15.       (entdel c-en)
  16.       (vl-cmdf "explode" (entlast) )
  17.    )
  18.    (princ)
  19. )
« Last Edit: April 23, 2023, 08:08:22 AM by domenicomaria »