Guest Posted December 7, 2021 Posted December 7, 2021 (edited) Hi .I am using Heron formula to calculate the area of close polylines. I am searchin for a lisp code to select the polyline and draw the triagles like the attach image Thanks Edited December 7, 2021 by prodromosm Quote
kirby Posted December 7, 2021 Posted December 7, 2021 Google 'Polygon Triangulation', especially 'Ear Clipping'. Quote
Guest Posted December 7, 2021 Posted December 7, 2021 Hi Kirby. I search in google but nothing helps me !! Any other ideas? Quote
mhupp Posted December 7, 2021 Posted December 7, 2021 1 hour ago, prodromosm said: Any other ideas? Google better add Autolisp or Autocad to terms when searching. You can also do things like "site:Cadtutor.net Polygon Triangulation" or even hit up the search bar up top of this page. if your not finding any useful websites I then usually click images. and that will also take you to a webpages. Still nothing? how can you reword your search. also make it sound technical. Quote
Guest Posted December 7, 2021 Posted December 7, 2021 (edited) The problem is i can finsd a lot of triangulation TIN lisp but from points. I don't have 3d points but only 2d close polyline. I can not find something similar.Is not for surface but for Heron formula. Anyway Thanks Edited December 7, 2021 by prodromosm Quote
mhupp Posted December 7, 2021 Posted December 7, 2021 (edited) That's a bit different then i can't find anything. feed it cords anyway and see if it does what you need. This extrudes the polyline you can then flatten it again. not quite triangles. Edited December 7, 2021 by mhupp Quote
kirby Posted December 8, 2021 Posted December 8, 2021 (edited) No pre-made solutions for your specific problem (or time for tinkering), but good opportunity to start building a computational geometry library since a lot of this stuff is related. Try as follows: 1. Triangulate your polygon using YMG's triangulation. Specifying your polygon segments as breaklines, since you want the triangle edges to fall on the polygon segments. http://www.theswamp.org/index.php?topic=9042.msg555712#msg555712 2. Loop through each 3dface / triangle and get centroid e.g. xc=(x1+x2+x3)/3, yc=(y1+y+y3)/3 ignore Z coordinate 3. Test each centroid to see if it falls INSIDE the polygon using John Uhden's code (posted by Luis Esquivel) https://www.theswamp.org/index.php?topic=7785.msg98761#msg98761 4. Discard triangles whose centroid is not inside the polygon However, if you just want the polygon area then google the Shoelace formula (for polygons/polylines with line segments only). https://en.wikipedia.org/wiki/Shoelace_formula Really good video on the Shoelace formula Gauss's magic shoelace area formula and its calculus companion - YouTube (Apologies for referencing another AutoLisp forum, if this is frowned upon) Edited December 8, 2021 by kirby forgot link Quote
GP_ Posted December 15, 2021 Posted December 15, 2021 On 12/8/2021 at 2:55 PM, kirby said: However, if you just want the polygon area then google the Shoelace formula (for polygons/polylines with line segments only). https://www.cadtutor.net/forum/topic/70921-areag/ Quote
Guest Posted December 15, 2021 Posted December 15, 2021 I want to use Heron formula because i want the analytic calculation for buildings area.. That's why i am searching for a triangle lisp. Thanks Quote
exceed Posted December 15, 2021 Posted December 15, 2021 (edited) 1. Insert a point at each vertex of selected 2D or 3D polyline use pvtx to make points by polyline vertex 2. use triangulate lisp by Daniele Piazza http://www.pdcode.com/code.htm autolisp section > triangulate then just edit ; in (defun DRAWTRIANGLE~ delete ; before (entmake~, add ; before (grdraw~ then execute TRIANGULATE command to step 1's points 3. then select original polyline. use cookiecutter 2 By Joe Burke http://www.theswamp.org/index.php?topic=24646.0;all before extrim have to separate layer. it's delete all of outside polyline 4. use your heron.lsp with 3 points if you want clear lines. overkill the lines and polyline for delete overlapped with polyline if you want triangles instead lines, command boundary and area selection. these routine can be merged in one-procedure. but I'm sorry I can't Edited December 15, 2021 by exceed Quote
GP_ Posted December 15, 2021 Posted December 15, 2021 (edited) 3 hours ago, prodromosm said: I want to use Heron formula because i want the analytic calculation for buildings area.. That's why i am searching for a triangle lisp. Thanks Gauss is not analytic? Edited December 15, 2021 by GP_ Quote
Guest Posted December 15, 2021 Posted December 15, 2021 (edited) Hi GP .Gauss is analytic but i don't want calculate area with point coordinates. It must be done with Heron formula. I use this code for Heron formula. Thats way i want a lisp to cut triangles and then 1) select all triangle and inset text (E1,E2,..............) like the code below 2) I want to convert this code to inser a text or mtext like the image bilow Thanks (defun c:heron (/ tri-no p1 p2 p3 da db dc s E cp lst cnt fn fp Etotal) (vl-load-com) (setvar "OSMODE" 9) (command "_layer" "_m" "Τύπος του Ήρωνα" "_c" "7" "" "") (defun tricent (pt1 pt2 pt3)(mapcar '(lambda (x y z) (/ (+ x y z) 3)) pt1 pt2 pt3)) (setq tri-no 0 Etotal 0) (while (and (setq p1 (getpoint "\nP1 : "))(setq p2 (getpoint "\nP2 : "))(setq p3 (getpoint "\nP3 : ")) (setq da (distance p2 p3)) (setq db (distance p3 p1)) (setq dc (distance p1 p2)) (setq s (/ (+ da db dc) 2.0) ) (setq E (sqrt (* s (- s da) (- s db) (- s dc))))) ; while valid points are given (if (assoc (setq cp (tricent p1 p2 p3)) lst) (prompt "\nPoint allready entered") (progn (setq lst (append lst (list (cons cp (list (setq tri-no (1+ tri-no)) s da db dc E ))))) (entmakex (list '(0 . "TEXT") (cons 10 cp) (cons 40 0.5) (cons 1 (strcat "E" (itoa tri-no))))) ) ) ) (if (and (vl-consp lst) (setq fn (vl-filename-mktemp ".txt"))(setq fp (open fn "w"))) (progn (foreach x lst (setq x (cdr x) tri-no (nth 0 x) s (nth 1 x) da (nth 2 x) db (nth 3 x) dc (nth 4 x) E (last x)) (write-line (strcat "E" (vl-princ-to-string tri-no) " = " "\U+221A" " " (vl-princ-to-string (rtos s 2 2 )) " x (" (vl-princ-to-string (rtos s 2 2)) " - " (vl-princ-to-string (rtos da 2 2 )) ") x (" (vl-princ-to-string (rtos s 2 2)) " - " (vl-princ-to-string (rtos db 2 2 )) ") x (" (vl-princ-to-string (rtos s 2 2)) " - " (vl-princ-to-string (rtos dc 2 2 )) ") = " (rtos E 2 2) " m2" ) fp) (setq Etotal (+ Etotal E)) ) (write-line (strcat "E = " (vl-princ-to-string (rtos Etotal 2 2)) " m2") fp) (close fp) ) ) (startapp "notepad" fn) (setvar "OSMODE" 9) (princ) );close defun Edited December 15, 2021 by prodromosm 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.