Nikon Posted December 9 Posted December 9 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)) Quote
Lee Mac Posted December 9 Posted December 9 (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 December 9 by Lee Mac 1 Quote
Nikon Posted December 9 Author Posted December 9 (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 December 9 by Nikon Quote
BIGAL Posted December 9 Posted December 9 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) 1 Quote
Nikon Posted December 10 Author Posted December 10 (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... Edited December 10 by Nikon Quote
BIGAL Posted December 10 Posted December 10 I use Bricscad and this is the rectang command you can see the "D" option. 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) 1 Quote
Nikon Posted December 10 Author Posted December 10 (edited) 46 minutes ago, BIGAL said: I use Bricscad and this is the rectang command you can see the "D" option. 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... Edited December 10 by Nikon Quote
fuccaro Posted December 10 Posted December 10 @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 1 Quote
Nikon Posted December 10 Author Posted December 10 (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 December 10 by Nikon Quote
fuccaro Posted December 10 Posted December 10 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. Quote
Nikon Posted December 10 Author Posted December 10 (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) Edited December 10 by Nikon Quote
fuccaro Posted December 10 Posted December 10 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! 1 Quote
Lee Mac Posted December 10 Posted December 10 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) ) 1 Quote
Nikon Posted December 10 Author Posted December 10 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... Quote
Recommended Posts
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.