Author Topic: Triangulation (re-visited)  (Read 312939 times)

0 Members and 2 Guests are viewing this topic.

pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #330 on: January 17, 2015, 12:02:00 PM »
I have  1.txt file with cross section details
I draw the section in the test.dwg

Can any one have a lisp to select the polyline and write the destanse and the elevetion ander the datum line?

pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #331 on: January 21, 2015, 05:30:53 AM »
Hi ymg.Is it possible to update your code

1) Identify oasis
2)select a boudary and delete all the TINS out of it. (i have seen your boudary command with +,- keys but is not all the times correct)

thanks

sanju2323

  • Newt
  • Posts: 68
Re: Triangulation (re-visited)
« Reply #332 on: January 29, 2015, 06:58:27 AM »
hello ymg sir, can you upgrade your in your tin lisp to calculate CUTTING FILLING Area from. 3DFACE

AARYAN

  • Newt
  • Posts: 72
Re: Triangulation (re-visited)
« Reply #333 on: February 12, 2015, 10:59:21 PM »
Hello ymg,

Please upgrade the program to calculate Cut and Fill Quantity from 2 sets of 3dFaces.

lamarn

  • Swamp Rat
  • Posts: 636
Re: Triangulation (re-visited)
« Reply #334 on: February 13, 2015, 03:47:43 AM »
An other question and request.

Can anyone explain me why the triangulate routine by Elpanov Evgeniy only constructs faces in WCS (top view oriented) i would like to see it work on vertical elements as well (side view orientated). For use .xyz data of interiour work and constructions

Thanks in advance
Design is something you should do with both hands. My 2d hand , my 3d hand ..

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #335 on: February 13, 2015, 09:36:24 AM »
Lammerts,

For this you would need a 3d triangulation.

This one is a so called 2.5d which means plan view with a z.

If you have data for a wall you could rotate it, do the tin and then rotate it back.

ymg

sanju2323

  • Newt
  • Posts: 68
Re: Triangulation (re-visited)
« Reply #336 on: February 13, 2015, 11:51:27 PM »
YMG,
  This lisp to change tin direction of vertex

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #337 on: February 14, 2015, 01:26:36 PM »
sanju,

Thanks! for the contribution.

However for something like a tunnel a 3d triangulation
would be needed.

Not sure I  want to tackle this in autolisp. :?

ymg

lamarn

  • Swamp Rat
  • Posts: 636
Re: Triangulation (re-visited)
« Reply #338 on: February 14, 2015, 02:14:39 PM »
Thank you for clarification ymg. I noticed i would need to rotate the model to get it done. Flipping the face is not needed, but thanks for this routine also
Design is something you should do with both hands. My 2d hand , my 3d hand ..

sanju2323

  • Newt
  • Posts: 68
Re: Triangulation (re-visited)
« Reply #339 on: February 16, 2015, 12:20:56 AM »
ymg,
  i don't know what you need. but i get you lisp to different result from 3d face.

pedroantonio

  • Guest
Re: Triangulation (re-visited)
« Reply #340 on: February 20, 2015, 12:32:29 PM »
Hi ymg.Can you add add an option to identify Boundary and oasis ? Dynamic Boundary is not all the time correct.
It's easyer to have an option select oasis (Y/N) and select boundary (Y/N) as close polylines

Thanks

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #341 on: February 20, 2015, 06:09:11 PM »
topographer,

It certainly is possible.

However lately my interest has turned to some other problem.

So progress is kinda slow!

ymg

sanju2323

  • Newt
  • Posts: 68
Re: Triangulation (re-visited)
« Reply #342 on: March 17, 2015, 06:00:27 AM »
Why is forgotten in this topic. Think of something new
« Last Edit: March 17, 2015, 06:05:28 AM by sanju2323 »

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Triangulation (re-visited)
« Reply #343 on: March 26, 2015, 12:08:27 PM »
Hi all...

Recently, I've tried to understand EE's main triangulation algorithm, so I've almost copied it entirely, changing only subfunction (getcircumcircle) and making it shorter - without unnecessary comments as ymg described it deeply... So what I did is replicate the code for my better understanding and learning... And now to my point... The main algorithm was developed according to insertion points from sorted point list by X axis... I tried to make my second version according to sorted point list by Y axis, and there was something wrong... I carefully changed every statement where it was needed to make it adapted for Y axis triangulation and by my observations and testing this variant failed to be consistent and functional like first X axis algorithm... Can someone see what I was missing, or this is some kind of bug in ACAD... I don't really know, but it would be nice if master Evgeniy or ymg could look into it... I've made comments where I thought it was desirable to describe what's difference between those 2 codes... I'll also attach my test DWG with points where one triangulation was done and where on other point clouds it's prepared for you to test and see why second algorithm is failing to produce the same result as first one...

Thanks for your attention and kind regards from me... Please if you see the trick shed some light - it will be beneficial for learning this very useful algorithm for all interested programmers...

First code - this one works fine :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:triangulate-MR-EE-Xsort ( / triangulate ss i p pl tl )
  2.  
  3.   (defun triangulate ( pl / getcircumcircle xmin xmax ymin ymax cs pmin pmax t1 t2 t3 al p el tr l )
  4.  
  5.     (defun getcircumcircle ( p el / v^v mid circumcircle cp cr rr )
  6.        
  7.       (defun v^v ( u v )
  8.         (mapcar '(lambda ( s1 s2 a b ) (+ ((eval s1) (* (nth a u) (nth b v))) ((eval s2) (* (nth a v) (nth b u))))) '(+ - +) '(- + -) '(1 0 0) '(2 2 1))
  9.       )
  10.  
  11.       (defun mid ( p1 p2 )
  12.         (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) p1 p2)
  13.       )
  14.  
  15.       (defun circumcircle ( p1 p2 p3 / p12 p23 p31 c1 c2 c r )
  16.         (setq p12 (mid p1 p2))
  17.         (setq p23 (mid p2 p3))
  18.         (setq p31 (mid p3 p1))
  19.         (setq c1 (inters p12 (mapcar '+ p12 (v^v (mapcar '- p2 p1) '(0.0 0.0 1.0))) p23 (mapcar '+ p23 (v^v (mapcar '- p3 p2) '(0.0 0.0 1.0))) nil))
  20.         (setq c2 (inters p12 (mapcar '+ p12 (v^v (mapcar '- p2 p1) '(0.0 0.0 1.0))) p31 (mapcar '+ p31 (v^v (mapcar '- p3 p1) '(0.0 0.0 1.0))) nil))
  21.         (setq c (mid c1 c2))
  22.         (setq r (distance c p1))
  23.         (list (list (car c) (cadr c)) r)
  24.       )
  25.  
  26.       (setq cp (car (setq cr (circumcircle (list (car p) (cadr p) 0.0) (list (caar el) (cadar el) 0.0) (list (caadr el) (cadadr el) 0.0)))) rr (cadr cr))
  27.       (list (mapcar '+ cp (list rr 0.0)) cp rr (list p (car el) (cadr el))) ;;; Added X apex of circumscribed triangle circle as first element of (getcircumcircle) output list ;;;
  28.     )
  29.  
  30.     (setq xmin (caar (setq pl (vl-sort pl '(lambda ( a b ) (< (car a) (car b))))))) ;;; Sorted pl by X ;;;
  31.     (setq xmax (caar (vl-sort pl '(lambda ( a b ) (> (car a) (car b))))))
  32.     (setq ymin (cadar (vl-sort pl '(lambda ( a b ) (< (cadr a) (cadr b))))))
  33.     (setq ymax (cadar (vl-sort pl '(lambda ( a b ) (> (cadr a) (cadr b))))))
  34.     (setq cs (list (+ xmin (/ (- xmax xmin) 2.0)) (+ ymin (/ (- ymax ymin) 2.0))))
  35.     (setq pmin (list xmin ymin) pmax (list xmax ymax))
  36.     (setq t1 (polar cs 0.0 (setq rs (* 4.0 (distance pmin cs))))) ;;; Added 0.0 in polar for rotating supertriangle t1 is max X apex ;;;
  37.     (setq t2 (polar cs (+ 0.0 (/ (* 2.0 pi) 3.0)) rs))
  38.     (setq t3 (polar cs (+ 0.0 (/ (* 4.0 pi) 3.0)) rs))
  39.     (setq al (list (list t1 cs rs (list t1 t2 t3))))
  40.     (while pl
  41.       (setq p (car pl))
  42.       (setq pl (cdr pl))
  43.       (setq el nil)
  44.       (while al
  45.         (setq tr (car al))
  46.         (setq al (cdr al))
  47.         (cond
  48.           ( (< (caar tr) (car p)) ;;; Comparison of X values ;;;
  49.             (setq tl (cons (cadddr tr) tl))
  50.           )
  51.           ( (< (distance p (cadr tr)) (caddr tr))
  52.             (setq el (append (list
  53.                               (list (car (last tr)) (cadr (last tr)))
  54.                               (list (cadr (last tr)) (caddr (last tr)))
  55.                               (list (caddr (last tr)) (car (last tr)))
  56.                             ) el
  57.                     )
  58.             )
  59.           )
  60.           ( t (setq l (cons tr l)) )
  61.         )
  62.       )
  63.       (if l (setq al l l nil))
  64.       ;;; This sorting doesn't help ;;;
  65.       ;;; You can ommit this step ;;;
  66.       (setq el (vl-sort el '(lambda ( a b )
  67.                             (if (>= (caar a) (caar b))
  68.                               (< (caadr a) (caadr b))
  69.                               (< (caar a) (caar b))
  70.                             )
  71.                           )
  72.               )
  73.       )
  74.       ;;; End of comment - it work well with or without sorting ;;;
  75.       (while el
  76.         (if (or (member (reverse (car el)) el)
  77.                (member (car el) (cdr el))
  78.             )
  79.             (setq el (vl-remove (reverse (car el)) el)
  80.                   el (vl-remove (car el) el)
  81.             )
  82.             (setq al (cons (getcircumcircle p (car el)) al)
  83.                   el (cdr el)
  84.             )
  85.         )
  86.       )
  87.     )
  88.     (foreach tr al (setq tl (cons (cadddr tr) tl)))
  89.     (setq tl (vl-remove-if '(lambda ( x ) (or (member t1 x) (member t2 x) (member t3 x))) tl))
  90.   ) ;;; end of triangulate
  91.  
  92.   (setq ss (ssget '((0 . "POINT"))))
  93.   (repeat (setq i (sslength ss))
  94.     (setq p (cdr (assoc 10 (entget (ssname ss (setq i (1- i)))))))
  95.     (setq pl (cons p pl))
  96.   )
  97.   (triangulate pl)
  98.   (foreach trr tl
  99.     (entmake
  100.       (list (cons 0 "3DFACE")
  101.         (cons 10 (car trr))
  102.         (cons 11 (car trr))
  103.         (cons 12 (cadr trr))
  104.         (cons 13 (caddr trr))
  105.       )
  106.     )
  107.   )
  108.   (princ)
  109. )
  110.  

And the second corrected buggy one :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:triangulate-MR-EE-Ysort ( / triangulate ss i p pl tl )
  2.  
  3.   (defun triangulate ( pl / getcircumcircle xmin xmax ymin ymax cs pmin pmax t1 t2 t3 al p el tr l )
  4.  
  5.     (defun getcircumcircle ( p el / v^v mid circumcircle cp cr rr )
  6.        
  7.       (defun v^v ( u v )
  8.         (mapcar '(lambda ( s1 s2 a b ) (+ ((eval s1) (* (nth a u) (nth b v))) ((eval s2) (* (nth a v) (nth b u))))) '(+ - +) '(- + -) '(1 0 0) '(2 2 1))
  9.       )
  10.  
  11.       (defun mid ( p1 p2 )
  12.         (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) p1 p2)
  13.       )
  14.  
  15.       (defun circumcircle ( p1 p2 p3 / p12 p23 p31 c1 c2 c r )
  16.         (setq p12 (mid p1 p2))
  17.         (setq p23 (mid p2 p3))
  18.         (setq p31 (mid p3 p1))
  19.         (setq c1 (inters p12 (mapcar '+ p12 (v^v (mapcar '- p2 p1) '(0.0 0.0 1.0))) p23 (mapcar '+ p23 (v^v (mapcar '- p3 p2) '(0.0 0.0 1.0))) nil))
  20.         (setq c2 (inters p12 (mapcar '+ p12 (v^v (mapcar '- p2 p1) '(0.0 0.0 1.0))) p31 (mapcar '+ p31 (v^v (mapcar '- p3 p1) '(0.0 0.0 1.0))) nil))
  21.         (setq c (mid c1 c2))
  22.         (setq r (distance c p1))
  23.         (list (list (car c) (cadr c)) r)
  24.       )
  25.  
  26.       (setq cp (car (setq cr (circumcircle (list (car p) (cadr p) 0.0) (list (caar el) (cadar el) 0.0) (list (caadr el) (cadadr el) 0.0)))) rr (cadr cr))
  27.       (list (mapcar '+ cp (list 0.0 rr)) cp rr (list p (car el) (cadr el))) ;;; Added Y apex of circumscribed triangle circle as first element of (getcircumcircle) output list ;;;
  28.     )
  29.  
  30.     (setq xmin (caar (vl-sort pl '(lambda ( a b ) (< (car a) (car b))))))
  31.     (setq xmax (caar (vl-sort pl '(lambda ( a b ) (> (car a) (car b))))))
  32.     (setq ymin (cadar (setq pl (vl-sort pl '(lambda ( a b ) (< (cadr a) (cadr b))))))) ;;; Sorted pl by Y ;;;
  33.     (setq ymax (cadar (vl-sort pl '(lambda ( a b ) (> (cadr a) (cadr b))))))
  34.     (setq cs (list (+ xmin (/ (- xmax xmin) 2.0)) (+ ymin (/ (- ymax ymin) 2.0))))
  35.     (setq pmin (list xmin ymin) pmax (list xmax ymax))
  36.     (setq t1 (polar cs (/ pi 2.0) (setq rs (* 4.0 (distance pmin cs))))) ;;; Added (/ pi 2.0) in polar for rotating supertriangle t1 is max Y apex ;;;
  37.     (setq t2 (polar cs (+ (/ pi 2.0) (/ (* 2.0 pi) 3.0)) rs))
  38.     (setq t3 (polar cs (+ (/ pi 2.0) (/ (* 4.0 pi) 3.0)) rs))
  39.     (setq al (list (list t1 cs rs (list t1 t2 t3))))
  40.     (while pl
  41.       (setq p (car pl))
  42.       (setq pl (cdr pl))
  43.       (setq el nil)
  44.       (while al
  45.         (setq tr (car al))
  46.         (setq al (cdr al))
  47.         (cond
  48.           ( (< (cadar tr) (cadr p)) ;;; Comparison of Y values ;;;
  49.             (setq tl (cons (cadddr tr) tl))
  50.           )
  51.           ( (< (distance p (cadr tr)) (caddr tr))
  52.             (setq el (append (list
  53.                               (list (car (last tr)) (cadr (last tr)))
  54.                               (list (cadr (last tr)) (caddr (last tr)))
  55.                               (list (caddr (last tr)) (car (last tr)))
  56.                             ) el
  57.                     )
  58.             )
  59.           )
  60.           ( t (setq l (cons tr l)) )
  61.         )
  62.       )
  63.       (if l (setq al l l nil))
  64.       ;;; This sorting doesn't help ;;;
  65.       ;;; You can ommit this step ;;;
  66.       (setq el (vl-sort el '(lambda ( a b )
  67.                             (if (>= (cadar a) (cadar b))
  68.                               (< (cadadr a) (cadadr b))
  69.                               (< (cadar a) (cadar b))
  70.                             )
  71.                           )
  72.               )
  73.       )
  74.       ;;; End of comment - it work well with or without sorting ;;;
  75.       (while el
  76.         (if (or (member (reverse (car el)) el)
  77.                (member (car el) (cdr el))
  78.             )
  79.             (setq el (vl-remove (reverse (car el)) el)
  80.                   el (vl-remove (car el) el)
  81.             )
  82.             (setq al (cons (getcircumcircle p (car el)) al)
  83.                   el (cdr el)
  84.             )
  85.         )
  86.       )
  87.     )
  88.     (foreach tr al (setq tl (cons (cadddr tr) tl)))
  89.     (setq tl (vl-remove-if '(lambda ( x ) (or (member t1 x) (member t2 x) (member t3 x))) tl))
  90.   ) ;;; end of triangulate
  91.  
  92.   (setq ss (ssget '((0 . "POINT"))))
  93.   (repeat (setq i (sslength ss))
  94.     (setq p (cdr (assoc 10 (entget (ssname ss (setq i (1- i)))))))
  95.     (setq pl (cons p pl))
  96.   )
  97.   (triangulate pl)
  98.   (foreach trr tl
  99.     (entmake
  100.       (list (cons 0 "3DFACE")
  101.         (cons 10 (car trr))
  102.         (cons 11 (car trr))
  103.         (cons 12 (cadr trr))
  104.         (cons 13 (caddr trr))
  105.       )
  106.     )
  107.   )
  108.   (princ)
  109. )
  110.  

I'll attach DWG for testing...
M.R.

[EDIT : Codes updated and fixed problem - thanks to mr. ymg for his observation...]
« Last Edit: April 03, 2015, 02:20:28 PM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ymg

  • Guest
Re: Triangulation (re-visited)
« Reply #344 on: March 27, 2015, 04:56:08 AM »
Marko,


Not sure, but the active triangle list al
should be modified to contain ymax of
each triangle.

Code: [Select]
al  (list (list xmax cp r sl))
      ;Initialize the Active Triangle list                            ;
      ; al, List contains active triangles defined by 4 items:        ;
      ;     item 0: Xmax of points in triangle.       ;
      ;     item 1: Center of circle circumscribing triangle.         ;
      ;     item 2: Radius of above circle.             ;
      ;     item 3: List of 3 vertices defining the triangle.         ;

ymg