Jump to content
Ohnoto

Quick 3 Point Circle

Recommended Posts

Ohnoto

In my line of work we utilize 3 point circles a lot. I am trying to create a program that does the following:

 

- User can only select 3 points using a window. If more or less are selected, an error is displayed.

- Creates the circle from those 3 points.

- Erases the points used to create the circle.

 

Simply put, I am trying to speed up having the select each point individually and erasing them after the circle is created.

 

I know bits and pieces of code to use, but ultimately, I'm not quite sure how to proceed getting only 3 points selected to then be used to create a circle.

 

Any assistance is appreciated.

Share this post


Link to post
Share on other sites
Lee Mac

Maybe this will offer some insight:

 

http://lee-mac.com/3pointarccircle.html

 

Otherwise, simply:

 

(command "_.circle" "_3P" pause pause pause)

 

Not sure what you mean by 'window'?

Share this post


Link to post
Share on other sites
Ohnoto

I had looked there, where your examples showed drawing lines to create the circle. What I am doing is creating circles from the 3 points that are already in the drawing from data received on field sites.

 

The 3 points may be things like 3 points on a column, edge of building, etc. On a building that has a lot of columns, for instance, we have small groupings of 3 points for each column. I then create circles from these points and erase them. I'm trying to have it set where I can select one grouping of these and it create the circle and then erase those points.

 

Also, What is the pauses for in that short code?

Share this post


Link to post
Share on other sites
Lee Mac
I had looked there, where your examples showed drawing lines to create the circle. What I am doing is creating circles from the 3 points that are already in the drawing from data received on field sites.

 

I suggest you look a little closer. My examples are not drawing lines to create circles, they prompt the user for three points and the function (the main point of the page) then constructs a circle from the three supplied points. However, the example prompting the user to pick points is just that, an example. You can supply the functions with points picked from the drawing, or arbitrary point values sourced from elsewhere.

 

What is the pauses for in that short code.

 

So that the user can pick the points, it wasn't clear from your first post that the points were objects in the drawing.

Share this post


Link to post
Share on other sites
Ohnoto
I suggest you look a little closer.

 

Touche.

 

I believe that I understand what is going on with it, upon closer inspection. My question would be how to do a SSGET to each of the three points without selecting each one individually.

Share this post


Link to post
Share on other sites
Tharwat

This... ?

(defun c:3pCircle (/ ss i sn ers lst)
 ;;; Tharwat 06. may 2012 ;;;
 (if (and (setq ss (ssget '((0 . "POINT"))))
          (eq (setq i (sslength ss)) 3)
     )
   (progn
     (repeat i
       (setq sn (ssname ss (setq i (1- i))))
       (setq ers (cons sn ers))
       (setq lst (cons (cdr (assoc 10 (entget sn))) lst))
     )
     (command "_.circle"
              "_3P"
              (nth 0 lst)
              (nth 1 lst)
              (nth 2 lst)
     )
     (foreach x ers (entdel x))
   )
   (cond ((not ss) (princ "\n Nothing selected"))
         (t (princ "\n Error ... Please select 3 points only "))
   )
 )
 (princ)
)

Share this post


Link to post
Share on other sites
David Bethel

A little different using (entmake)

 

Assuming that all POINTs are on the same plane:

 

[b][color=BLACK]([/color][/b]defun c:3pt2ci [b][color=FUCHSIA]([/color][/b]/ ss p1 p2 p3 m1 m2 cp[b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]and [b][color=MAROON]([/color][/b]princ [color=#2f4f4f]"\nSelect 3 POINTs To Convert Into A Circle"[/color][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]setq ss [b][color=GREEN]([/color][/b]ssget '[b][color=BLUE]([/color][/b][b][color=RED]([/color][/b]0 . [color=#2f4f4f]"POINT"[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
             [b][color=MAROON]([/color][/b]= [b][color=GREEN]([/color][/b]sslength ss[b][color=GREEN])[/color][/b] 3[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]setq p1 [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 10 [b][color=BLUE]([/color][/b]entget [b][color=RED]([/color][/b]ssname ss 0[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
              p2 [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 10 [b][color=BLUE]([/color][/b]entget [b][color=RED]([/color][/b]ssname ss 1[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
              p3 [b][color=MAROON]([/color][/b]cdr [b][color=GREEN]([/color][/b]assoc 10 [b][color=BLUE]([/color][/b]entget [b][color=RED]([/color][/b]ssname ss 2[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
              m1 [b][color=MAROON]([/color][/b]polar p1 [b][color=GREEN]([/color][/b]angle p1 p2[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]* [b][color=BLUE]([/color][/b]distance p1 p2[b][color=BLUE])[/color][/b] 0.5[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
              m2 [b][color=MAROON]([/color][/b]polar p1 [b][color=GREEN]([/color][/b]angle p2 p3[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]* [b][color=BLUE]([/color][/b]distance p2 p3[b][color=BLUE])[/color][/b] 0.5[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b]
              cp [b][color=MAROON]([/color][/b]inters m1 [b][color=GREEN]([/color][/b]polar m1 [b][color=BLUE]([/color][/b]+ [b][color=RED]([/color][/b]angle p1 p2[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]* pi 0.5[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] 1[b][color=GREEN])[/color][/b]
                         m2 [b][color=GREEN]([/color][/b]polar m2 [b][color=BLUE]([/color][/b]+ [b][color=RED]([/color][/b]angle p2 p3[b][color=RED])[/color][/b] [b][color=RED]([/color][/b]* pi 0.5[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] 1[b][color=GREEN])[/color][/b] nil[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]entmake [b][color=MAROON]([/color][/b]list [b][color=GREEN]([/color][/b]cons 0 [color=#2f4f4f]"CIRCLE"[/color][b][color=GREEN])[/color][/b]
                       [b][color=GREEN]([/color][/b]cons 10 cp[b][color=GREEN])[/color][/b]
                       [b][color=GREEN]([/color][/b]cons 40 [b][color=BLUE]([/color][/b]distance cp p1[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]entdel [b][color=MAROON]([/color][/b]ssname ss 0[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]entdel [b][color=MAROON]([/color][/b]ssname ss 1[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
        [b][color=NAVY]([/color][/b]entdel [b][color=MAROON]([/color][/b]ssname ss 2[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
 [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]

 

You would need to tweak the data as to layers color etc

 

This would make the repetitive part a little easier.

 

-David

Share this post


Link to post
Share on other sites
Ohnoto

Thanks to both of you guys. I was able to get what I needed. I appreciate it!

Share this post


Link to post
Share on other sites
selvakumar

:D maybe that's is help

 

 

(defun c:3c () (Command "_.circle" "_3P" pause pause pause)

)

Share this post


Link to post
Share on other sites
SLW210

Why do you bring up old threads?

 

Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.

 
Your Code Here
 

Share this post


Link to post
Share on other sites
dilan
Posted (edited)

And how to create a circle by three points in 3D?

(defun gc:GetVector (p1 p2) (mapcar '- p2 p1))

(defun gc:CrossProduct (v1 v2)
  (list	(- (* (cadr v1) (caddr v2)) (* (caddr v1) (cadr v2)))
	(- (* (caddr v1) (car v2)) (* (car v1) (caddr v2)))
	(- (* (car v1) (cadr v2)) (* (cadr v1) (car v2)))
  )
)

(defun gc:MidPoint (p1 p2)
  (mapcar (function (lambda (x1 x2) (/ (+ x1 x2) 2.))) p1 p2)
)

(defun circleBy3Points (p1 p2 p3 / v1 v2 norm m1 m2 cen)
  (setq	v1   (gc:GetVector p1 p2)
	v2   (gc:GetVector p2 p3)
	norm (gc:CrossProduct v1 v2)
	m1   (gc:Midpoint p1 p2)
	m2   (gc:Midpoint p2 p3)
	cen  (inters m1
		     (mapcar '+ m1 (gc:CrossProduct v1 norm))
		     m2
		     (mapcar '+ m2 (gc:CrossProduct v2 norm))
		     nil
	     )
  )
  (entmakex
    (list
      (cons 0 "CIRCLE")
      (cons 10 (trans cen 0 norm))
      (cons 40 (distance cen p1))
      (cons 210 norm)
    )
  )
)

Found here

Edited by dilan
1

Share this post


Link to post
Share on other sites
BIGAL

If you want the circle on a plane matching the 3 points you need to do UCS 1st then draw your circle, so look at how UCS works. Save the 3 points (setq pt1 (getpoint "\nPick point))) pt2 pt3 etc. circle 3p pt1 pt2 pt3

Share this post


Link to post
Share on other sites
CADWORKER
On 5/6/2012 at 7:30 AM, Tharwat said:

This... ?

 


(defun c:3pCircle (/ ss i sn ers lst)
 ;;; Tharwat 06. may 2012 ;;;
 (if (and (setq ss (ssget '((0 . "POINT"))))
          (eq (setq i (sslength ss)) 3)
     )
   (progn
     (repeat i
       (setq sn (ssname ss (setq i (1- i))))
       (setq ers (cons sn ers))
       (setq lst (cons (cdr (assoc 10 (entget sn))) lst))
     )
     (command "_.circle"
              "_3P"
              (nth 0 lst)
              (nth 1 lst)
              (nth 2 lst)
     )
     (foreach x ers (entdel x))
   )
   (cond ((not ss) (princ "\n Nothing selected"))
         (t (princ "\n Error ... Please select 3 points only "))
   )
 )
 (princ)
)
 

 

Hi tharwat, Thanks for this code.

I tried modifying it a little by adding while T to repeat the code. After selection of the tree points I get the circle and when I select the next three point I am getting the points back for the previous circle which were erased when the circle was created and its repeating. Any Help/ suggestion please.

 

(defun c:3pC2 (/ ss i sn ers lst)
 ;;; Tharwat 06. may 2012 ;;;
(WHILE T
 (if (and (setq ss (ssget '((0 . "POINT"))))
          (eq (setq i (sslength ss)) 3)
     )
   (progn
     (repeat i
       (setq sn (ssname ss (setq i (1- i))))
       (setq ers (cons sn ers))
       (setq lst (cons (cdr (assoc 10 (entget sn))) lst))
     )
     (command "_.circle"
              "_3P"
              (nth 0 lst)
              (nth 1 lst)
              (nth 2 lst)
     )
     (foreach x ers (entdel x))
   )
   (cond ((not ss) (princ "\n Nothing selected"))
         (t (princ "\n Error ... Please select 3 points only "))
   )
 )
 (princ)
)
)

 

Share this post


Link to post
Share on other sites
Tharwat

Hi,

The program was recreating the points due to the active list of entities along with the entdel function.

Its not a good practice to feed While function with T and force to end stop the program with ESC button so try the following instead.

 

(defun c:3pC2 (/ ss i sn ers lst)
;;; Tharwat 19. Nov. 2020 ;;;
  (while
    (and (princ "\nSelect THREE points to create a circle between them : ")
         (setq ers nil ss  (ssget '((0 . "POINT"))))
    )
     (if (eq (setq i (sslength ss)) 3)
       (progn
         (repeat i
           (setq sn (ssname ss (setq i (1- i))))
           (setq ers (cons sn ers))
           (setq lst (cons (cdr (assoc 10 (entget sn))) lst))
         )
         (command "_.circle"
                  "_3P"
                  "_none"
                  (nth 0 lst)
                  "_none"
                  (nth 1 lst)
                  "_none"
                  (nth 2 lst)
         )
         (foreach x ers (entdel x))
       )
       (alert "Error ... Please select 3 points only")
     )
  )
  (princ)
)

 

 

  • Like 2

Share this post


Link to post
Share on other sites
CADWORKER

THANKS

Share this post


Link to post
Share on other sites
Tharwat
9 minutes ago, CADWORKER said:

THANKS

You're welcome anytime.

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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