Jump to content

Recommended Posts

Posted (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

 

 

1.jpg

Edited by prodromosm
Posted

Google 'Polygon Triangulation', especially 'Ear Clipping'.

Posted

Hi Kirby. I search in google but nothing helps me !!

 

Any other ideas?

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

 

Posted (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 by prodromosm
Posted (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 by mhupp
Posted (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 by kirby
forgot link
Posted

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

Posted (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 by exceed
Posted (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 by GP_
Posted (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

 

example.jpg.2c2d4b1ca9f0f3e60d06f486ab2a06a5.jpg

Edited by prodromosm

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