Aftertouch Posted October 4, 2018 Posted October 4, 2018 Hello everybody, Im wondering if somebody could help me with the following problem... I have a 3D polyline with multiple vertexes. I would like all vertexes to triangulate (like Civil3D), but draw a 3D polyline of each triangle.... Is this doable somehow???? I have added a DWG with the original polyline and the disired result. 3DPOLY.dwg Quote
marko_ribar Posted October 4, 2018 Posted October 4, 2018 Almost each pair of triangles can have middle common edge flipped with another possible triangle pair... There is no way computer can know which solution you want, which one is correct and which is not... Beside all this, because it is 3d polyline it complicates thing further more, no possibility to check point clockwise-p - it's 3d polyline... For LWPOLYLINE it's not that difficult, here is my old version : (defun c:triangulatepolygon-3dfaces ( / trianglst lw ptlst ) (defun trianglst ( ptlst / unique LM:ListClockwise-p clockwise-p l p1 p2 p3 trl ) (defun unique ( l ) (if l (cons (car l) (unique (vl-remove-if (function (lambda ( x ) (equal x (car l) 1e-6))) l)))) ) ;; List Clockwise-p - Lee Mac ;; Returns T if the point list is clockwise oriented (defun LM:ListClockwise-p ( lst ) (minusp (apply '+ (mapcar (function (lambda ( a b ) (- (* (car b) (cadr a)) (* (car a) (cadr b))) ) ) lst (cons (last lst) lst) ) ) ) ) (defun clockwise-p ( p1 p2 p3 ) (< (* (- (car p2) (car p1)) (- (cadr p3) (cadr p1))) (* (- (cadr p2) (cadr p1)) (- (car p3) (car p1))) ) ) (setq l ptlst) (while (> (length ptlst) 3) (setq p1 (car ptlst) p2 (cadr ptlst) p3 (caddr ptlst)) (cond ( (LM:ListClockwise-p ptlst) (if (and (clockwise-p p1 p2 p3) (= (length (unique (vl-remove nil (mapcar (function (lambda ( a b ) (inters p1 p2 a b))) l (cdr (reverse (cons (car l) (reverse l)))))))) 2) (= (length (unique (vl-remove nil (mapcar (function (lambda ( a b ) (inters p2 p3 a b))) l (cdr (reverse (cons (car l) (reverse l)))))))) 2) (= (length (unique (vl-remove nil (mapcar (function (lambda ( a b ) (inters p3 p1 a b))) l (cdr (reverse (cons (car l) (reverse l)))))))) 2) ) (progn (setq trl (cons (list p1 p2 p3) trl)) (setq ptlst (vl-remove p2 ptlst)) (setq ptlst (cdr (reverse (cons (car ptlst) (reverse ptlst))))) ) (setq ptlst (cdr (reverse (cons (car ptlst) (reverse ptlst))))) ) ) ( (not (LM:ListClockwise-p ptlst)) (if (and (not (clockwise-p p1 p2 p3)) (= (length (unique (vl-remove nil (mapcar (function (lambda ( a b ) (inters p1 p2 a b))) l (cdr (reverse (cons (car l) (reverse l)))))))) 2) (= (length (unique (vl-remove nil (mapcar (function (lambda ( a b ) (inters p2 p3 a b))) l (cdr (reverse (cons (car l) (reverse l)))))))) 2) (= (length (unique (vl-remove nil (mapcar (function (lambda ( a b ) (inters p3 p1 a b))) l (cdr (reverse (cons (car l) (reverse l)))))))) 2) ) (progn (setq trl (cons (list p1 p2 p3) trl)) (setq ptlst (vl-remove p2 ptlst)) (setq ptlst (cdr (reverse (cons (car ptlst) (reverse ptlst))))) ) (setq ptlst (cdr (reverse (cons (car ptlst) (reverse ptlst))))) ) ) ) ) (setq trl (cons (list (car ptlst) (cadr ptlst) (caddr ptlst)) trl)) trl ) (while (or (not (setq lw (car (entsel "\nPick LWPOLYLINE closed polygon to triangulate...")))) (if lw (or (/= (cdr (assoc 0 (entget lw))) "LWPOLYLINE") (/= 1 (logand 1 (cdr (assoc 70 (entget lw))))) (vl-some '(lambda ( x ) (/= (cdr x) 0.0)) (vl-remove-if '(lambda ( x ) (/= (car x) 42)) (entget lw)))))) (prompt "\nMissed or picked wrong entity type") ) (vl-cmdf "_.UCS" "_E" lw) (setq ptlst (mapcar '(lambda ( p ) (trans p lw 1)) (mapcar '(lambda ( p ) (list (car p) (cadr p) (cdr (assoc 38 (entget lw))))) (mapcar 'cdr (vl-remove-if (function (lambda ( x ) (/= (car x) 10))) (entget lw)))))) (foreach tr (trianglst ptlst) (entmake (list '(0 . "3DFACE") (cons 10 (trans (car tr) 1 0)) (cons 11 (trans (car tr) 1 0)) (cons 12 (trans (cadr tr) 1 0)) (cons 13 (trans (caddr tr) 1 0)) ) ) ) (vl-cmdf "_.UCS" "_P") (princ) ) HTH., M.R. Quote
Aftertouch Posted October 5, 2018 Author Posted October 5, 2018 Hey Marko, Thanks for the code! It works (almost) almost perfect for me. The code seems to fail when there are multiple vertextes in the same orthoganal line. So when i draw a rectangle with 3 vertexes on a side, itll fail. Quote
BIGAL Posted October 7, 2018 Posted October 7, 2018 (edited) It would be far easier to search here for "Triangulation" it will do what you want just create points of the co-ords of the pline and its free. TriangV0.5.9.lsp by YMG there may be a newer version. Edited October 7, 2018 by BIGAL 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.