aloy Posted August 5, 2017 Posted August 5, 2017 Hi everybody, I have list representing the vertices of a closed polygon. How can I find the area of the polygon with an autolisp expression?. Thanks in advance, Aloy Quote
Tharwat Posted August 5, 2017 Posted August 5, 2017 Hi, I am sure that I have seen this question on the swamp.org not from a quite long time but unfortunately I couldn't find it. Anyway you can create a polyline of these vertices then get the area of the newly created polyline then delete the polyline. Quote
aloy Posted August 5, 2017 Author Posted August 5, 2017 Thanks Tharwat, I did this more than twenty years ago while developing program for road cross section. I have forgotten that. There should be an easier way without having to do it manually. In fact the list is also prepared automatically. Regards, Aloy Quote
Tharwat Posted August 5, 2017 Posted August 5, 2017 I did not mean to do it manually but to have a function that draws the polyline then get the area then delete the polyline. Quote
Tharwat Posted August 5, 2017 Posted August 5, 2017 (edited) Try the following and be sure to have the current layer Unlocked to allow the function to delete the newly created polyline by the function. (defun AreaOfVertices (l / a e) (and (setq e (entmakex (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (length l)) '(70 . 0) ) (mapcar (function (lambda (p) (cons 10 p))) l) ) ) ) (setq a (vlax-curve-getarea e)) (entdel e) ) a ) Usage of the above function: (AreaOfVertices lst) Edited August 5, 2017 by Tharwat typo of 'l' variable Quote
GP_ Posted August 5, 2017 Posted August 5, 2017 Try the following: (defun areaG (lst) (abs (/ (apply '+ (mapcar '(lambda ( a b ) (- (* (car a) (cadr b)) (* (car b) (cadr a))) ) lst (cons (last lst) lst) ) ) 2.0 ) ) ) (setq Lv '((0.0 5.0 0.0) (3.0 5.0 0.0) (3.0 0.0 0.0) (0.0 0.0 0.0))) ((0.0 5.0 0.0) (3.0 5.0 0.0) (3.0 0.0 0.0) (0.0 0.0 0.0)) _$ (areaG Lv) 15.0 _$ Quote
aloy Posted August 5, 2017 Author Posted August 5, 2017 Tharwat, GP_ Thanks for the reply. However what I am looking for is a way to respond to " area" command of autocad by giving points out of my list. Aloy Quote
GP_ Posted August 5, 2017 Posted August 5, 2017 (setq Lv '((0.0 5.0 0.0) (3.0 5.0 0.0) (3.0 0.0 0.0) (0.0 0.0 0.0))) (command "area") (apply 'command Lv) (command "") (getvar 'area) 15.0 _$ Quote
Roy_043 Posted August 5, 2017 Posted August 5, 2017 I don't understand why the OP would want to do it this way. But whenever you use (command ..) you should be aware that the OSMODE setting can affect the result. Quote
aloy Posted August 6, 2017 Author Posted August 6, 2017 Roy_043, This means we have to set the "osmode" to "0" at the beginning and set it back to original at the end?. Thanks for the advice. Aloy Quote
Roy_043 Posted August 6, 2017 Posted August 6, 2017 This means we have to set the "osmode" to "0" at the beginning and set it back to original at the end?Yes, that is the usual approach. 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.