Jump to content

A square with a side equal to, equal to the square root of the area of the circle


Recommended Posts

Posted

How can I get a square with a side equal to the square root of the area of the specified circle?
Select a circle in the drawing, get the area of the circle, get the side of the square = (sqrt area circle), get a square.

(DEFUN C:square_50 (/ p1 p2 p3 p4) 
(setq p1 (getpoint "\nSpecify the base point : ")) 
(setq p2 (polar p1 0 50)) 
(setq p3 (polar p2 (/ pi 2) 50)) 
(setq p4 (polar p3 pi 50)) 
(setq osm (getvar "osmode")) 
(setvar "osmode" 0) 
(vl-cmdf "_.line" p1 p2 p3 p4 p1 "") 
(setvar "osmode" osm) 
) 

 

How to enter (sqrt area circle) instead of 50, i.e. get the side of the square
(setq p2 (polar p1 0 50))

area-circle_side-square.png

Posted (edited)

Simple example -

(defun c:sqcircle ( / ent enx ins len ocs )
    (cond
        (   (not (setq ent (car (entsel "\nSelect circle: ")))))
        (   (/= "CIRCLE" (cdr (assoc 0 (setq enx (entget ent)))))
            (princ "\nObject is not a circle.")
        )
        (   (not (setq ins (getpoint "\nPoint for square: "))))
        (   (setq ocs (trans '(0 0 1) 1 0 t)
                  len (* (sqrt pi) (cdr (assoc 40 enx)))
            )
            (entmake
                (list
                   '(0 . "LWPOLYLINE")
                   '(100 . "AcDbEntity")
                   '(100 . "AcDbPolyline")
                   '(090 . 4)
                   '(070 . 1)
                    (cons 010 (trans ins 1 ocs))
                    (cons 010 (trans (mapcar '+ ins (list len 0.0)) 1 ocs))
                    (cons 010 (trans (mapcar '+ ins (list len len)) 1 ocs))
                    (cons 010 (trans (mapcar '+ ins (list 0.0 len)) 1 ocs))
                    (cons 210 ocs)
                )
            ) 
        )
    )
    (princ)
)

 

Edited by Lee Mac
  • Like 1
Posted (edited)
1 hour ago, Lee Mac said:

Simple example -

(defun c:sqcircle ( / ent enx ins len ocs )

@Lee Mac Thank you very much. That's great!  🟠  🟪

I want to thank you for your wonderful programs, they help us a lot!

Edited by Nikon
Posted

Another real simple with no error checking, using rectang. Lee's is better having the error checking. Whilst entmake is faster than rectang as you are picking a circle speed is not a problem. Both methods draw in micro seconds.

 

(defun c:sqcirc ( / obj area side pt)
(setq obj (vlax-ename->vla-object (car (entsel "\nPick object "))))
(setq area (vlax-get obj 'area))
(setq side (sqrt area))
(setq pt (getpoint "\nPick bottom left point "))
(command "rectang" "D" side side pt pt)
(princ)
)
(c:sqcirc)

 

 

  • Thanks 1
Posted (edited)
8 hours ago, BIGAL said:

Another real simple with no error checking, using rectang. Lee's is better having the error checking. Whilst entmake is faster than rectang as you are picking a circle speed is not a problem. Both methods draw in micro seconds.

 

(defun c:sqcirc ( / obj area side pt)

@BIGAL Thank you for your participation.
But the square is not drawn according to the area of the selected object.
Writing on the command line:
A dot or keyword is required.
; error: The function has been canceled
Specify the point of the first corner or [Chamfer/Elevation/Fillet/Height/Width]:

In this string "D" this "Dimensions"?
(command "_.rectang" "_D" side side pt pt)

********************

If you delete D
(command "_.rectang" side side pt pt)
then an arbitrary rectangle is drawn, the area of the rectangle is not equal to the area of the circle...

area.png

Edited by Nikon
Posted

I use Bricscad and this is the rectang command you can see the "D" option.

 

image.thumb.png.1b94e0e695712085d83e4ade6d5c9f98.png

 

Ok a different way around it.

 

(defun c:sqcirc ( / obj area side pt)
(setq obj (vlax-ename->vla-object (car (entsel "\nPick object "))))
(setq area (vlax-get obj 'area))
(setq side (sqrt area))
(setq pt (getpoint "\nPick bottom left point "))
(command "rectang" pt (mapcar '+ pt (list side side 0.0)))
(princ)
)
(c:sqcirc)

 

 

  • Like 1
Posted (edited)
46 minutes ago, BIGAL said:

I use Bricscad and this is the rectang command you can see the "D" option.

 

image.thumb.png.1b94e0e695712085d83e4ade6d5c9f98.png

 

Ok a different way around it.

 

(defun c:sqcirc ( / obj area side pt)
(setq obj (vlax-ename->vla-object (car (entsel "\nPick object "))))
(setq area (vlax-get obj 'area))
(setq side (sqrt area))
(setq pt (getpoint "\nPick bottom left point "))
(command "rectang" pt (mapcar '+ pt (list side side 0.0)))
(princ)
)
(c:sqcirc)

@BIGAL Thanks!!! It's working!

**************************

An interesting features of a square and a circle with the same area:
if you combine the centers of these figures, then 4 areas of the circle and 4 areas of the square 
add up to the same area...

 

sum area.png

Edited by Nikon
Posted

@Nikon

You are not the first one. Others tried to solve this specific problem centuries ago. Also others proved that the problem has no solution (but they had no AutoCAD, nor AutoLisp at that time).

Squaring a circle

  • Like 1
Posted (edited)
30 minutes ago, fuccaro said:

@Nikon

You are not the first one. Others tried to solve this specific problem centuries ago. Also others proved that the problem has no solution (but they had no AutoCAD, nor AutoLisp at that time).

Squaring a circle

@fuccaro 

Thanks for the link.

I just happened to notice that the areas are equal...😉

I wonder if the inverse problem is possible, choose a square and get a circle with the area of the square?

Edited by Nikon
Posted
13 minutes ago, Nikon said:

I wonder if the inverse problem is possible, choose a square and get a circle with the area of the square?

It will be possible as soon as you will be able to draw a line with the length *exactly* Pi units.

Posted

... sorry, I meant the square root of Pi, not Pi

Posted (edited)
1 hour ago, fuccaro said:

It will be possible as soon as you will be able to draw a line with the length *exactly* Pi units. units.

Isn't it possible to get a circle with a radius from the area of a square?

R=√(area square/pi)

area circle = area square.png

Edited by Nikon
Posted

It can be done, but as long as there is a Pi in that formula, the result will be affected by the precision used to approximate Pi. Even the answers to your previous question are affected by the same imprecision. It is small enough for our engineering needs, but it is not zero!

  • Agree 1
Posted
6 hours ago, Nikon said:

Isn't it possible to get a circle with a radius from the area of a square?

R=√(area square/pi)

 

Certainly - the following will construct a circle with the area of any closed shape:
 

(defun c:carea ( / ent ins ocs )
    (cond
        (   (not (setq ent (car (entsel)))))
        (   (vl-catch-all-error-p (setq are (vl-catch-all-apply 'vlax-curve-getarea (list ent))))
            (princ "\nInvalid object selected.")
        )
        (   (not (setq ins (getpoint "\nPoint for circle: "))))
        (   (setq ocs (trans '(0 0 1) 1 0 t))
            (entmake
                (list
                   '(000 . "CIRCLE")
                    (cons 010 (trans ins 1 ocs))
                    (cons 040 (sqrt (/ are pi)))
                    (cons 210 ocs)
                )
            ) 
        )
    )
    (princ)
)

 

  • Like 1
Posted
17 minutes ago, Lee Mac said:

Certainly - the following will construct a circle with the area of any closed shape:
 

(defun c:carea ( / ent ins ocs )

Thanks! It's amazing!

Indeed, any closed shape: polygon, ellipse, rectangle...

carea.png

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