;;****************************************************************************;
;; swap by ymg ;
;; Cline & Renka Swap Test ;
;; ;
;; Given a triangle defined by three points indices v1, v2, v3 ;
;; and an index to point p, ;
;; Returns T is p is inside circle circumscribing triangle v1 v2 v3. ;
;; ;
;;****************************************************************************;
(defun swap
(v1 v2 v3 p
/ cosa cosb sina sinb v1 v2 v3
x1 x13 x1p x2 x23 x2p x3 xp
y1 y13 y1p y2 y23 y2p y3 yp)
x13 (- x1 x3) y13 (- y1 y3)
x23 (- x2 x3) y23 (- y2 y3)
x1p (- x1 xp) y1p (- y1 yp)
x2p (- x2 xp) y2p (- y2 yp)
cosa (+ (* x13 x23) (* y13 y23))
cosb (+ (* x1p x2p) (* y1p y2p))
)
(t
(setq sina
(- (* x13 y23
) (* x23 y13
)) sinb (- (* x2p y1p) (* x1p y2p))
)
(minusp (+ (* sina cosb
)(* sinb cosa
))) )
)
)
;;****************************************************************************;
;; (topp l v tl nl) ;
;; ;
;; Find Triangle Opposed to Vertex v. ;
;; ;
;; Input: tr Triangle as a list of 3 indices. ;
;; v Vertex number (Must be a member of triangle tr) ;
;' tl Triangle List ;
;; nl Neighbour List ;
;; ;
;;****************************************************************************;
(defun topp
(tr v tl nl
/ ln tr pos
) )
)
;;****************************************************************************;
;; (Vopp t1 t2) by ymg ;
;; ;
;; Find Opposed Vertex v. ;
;; ;
;; Input: t1 Triangle as a list of 3 Indices. ;
;; t2 Opposed Triangle as a list of 3 indices. ;
;; ;
;; Returns Index of Opposed Vertex. ;
;; ;
;;****************************************************************************;
)
)
(defun onleft_p
(p v1 v2 pl
) x1p (- x1 xp) y1p (- y1 yp)
x2p (- x2 xp) y2p (- y2 yp)
)
(minusp (- (* y1p x2p
) (* x1p y2p
))) )
;;****************************************************************************;
;; trunc by Gile Chanteau ;
;; Retourne la liste tronquée à partir de la première occurrence ;
;; de l'expression (liste complémentaire de celle retournée par MEMBER) ;
;; ;
;; Arguments ;
;; expr : l'expression recherchée ;
;; lst : la liste ;
;;****************************************************************************;
)
)
)
;;****************************************************************************;
;; (triloc p) ;
;; ;
;; Locates triangle which encloses point p using Lawson's Walk. ;
;; ;
;; Given p a point, Returns Index in tl of triangle containing the point. ;
;; If outside the triangulation Return is nil. ;
;; ;
;; Point List pl and Neigbour List nl are defined outside this routine. ;
;; by ymg August 2013 ;
;; Optimized Speed and re-organized code January 2014 ;
;; Nice but get lost when triangulation is disjointed. ;
;;****************************************************************************;
(defun triloc
(p pl tl nl
/ notfound i p1 p2 p3 x x1 x2 x3 y y1 y2 y3
)
x1x
(- (car p1
) x
) y1y
(- (cadr p1
) y
) x2x
(- (car p2
) x
) y2y
(- (cadr p2
) y
) x3x
(- (car p3
) x
) y3y
(- (cadr p3
) y
) )
)
)
tn
)
;;****************************************************************************;
;; addedge by ymg May 2014 ;
;; ;
;; As per paper: An Improved Incremental Algorithm For Constructing ;
;; Restricted Delaunay Triangulations. by Marc Vigo Anglada ;
;; ;
;; Arguments: a, Index of point in a triangulation. ;
;; b, Index second point, defining edge ab to be inserted ;
;; ;
;; External Variables tl and nl will be modified. ;
;; ;
;; Will insert an edge in an existing triangulation. Triangles crossed by ;
;; the edge will be deleted. Cavity will be re-triangulated to restore ;
;; Delaunay's condition. New triangle will be redrawn. ;
;; ;
;;****************************************************************************;
(defun addedge
(a b
/ 3df dl newtri pa pb poll polu topo tr v vopo vshr
) tn nil
tn
(triloc
(polar pa
(angle pa pb
) 0.001) pl tl nl
) v a
dl nil
)
(if (onleft_p
(car vshr
) a b pl
) )
(setq topo
(topp tr v tl nl
) vopo (vopp tr topo)
)
(if (onleft_p vopo a b pl
) )
(setq dl
(cons tr dl
) ; dl List of triangle to be deleted ; tr topo
)
)
(setq dl
(cons tr dl
)) ; Adding last triangle to be deleted ; )
(setq newtri
nil) ; New Triangles will be accumulated in newtri ; (tripol polu a b nil)
(tripol poll a b t )
)
(mk_layer
(list "TIN" 8)) (setq 3df '
(0 .
"3DFACE")) )
)
)
nl (get_neighbour tl)
)
)
;;****************************************************************************;
;; tripol by ymg ;
;; ;
;; Arguments: p, list of point index. ;
;; a, Index of First point of an Edge. ;
;; b, Index of Second point of Edge. ;
;; r, Flag for ccw polygon. ;
;; ;
;; Will accumulates in external variable newtri the Delaunay's Triangles ;
;; formed by the defining Points and Edge. ;
;; ;
;;****************************************************************************;
(defun tripol
(p a b r
/ c pe pd v
) )
)
)
(if pe
(tripol pe a c r
)) (if pd
(tripol pd c b r
)) )
)
)
;;****************************************************************************;
;; get_trname by ymg ;
;; ;
;; Given a triangle defined as a list of 3 indices into point list, ;
;; Returns the ENAME of 3DFACE. ;
;; ;
;;****************************************************************************;
(defun get_trname
(tr pl
/ cn f1 f2 p1 p2 p3 ss x1 x2 x3 y1 y2 y3
) cn
(list (/ (+ x1 x2 x3
) 3.
) (/ (+ y1 y2 y3
) 3.
)) ss
(acet
-ss
-intersection
(ssget "_F" f1 '
((0 .
"3DFACE"))) (ssget "_F" f2 '
((0 .
"3DFACE")))) )
)