;; LWPolyline to Point List - Lee Mac
;; Returns a list of points describing the supplied LWPolyline
(defun LMWPoly->List ( ent / der di1 di2 inc lst par rad )
(setq par 0)
(repeat (cdr (assoc 90 (entget ent)))
(if (setq der (vlax-curve-getsecondderiv ent par))
(if (equal der '(0.0 0.0 0.0) 1e-8)
(setq lst (cons (vlax-curve-getpointatparam ent par) lst))
(if
(setq rad (distance '(0.0 0.0) (vlax-curve-getfirstderiv ent par))
di1 (vlax-curve-getdistatparam ent par)
di2 (vlax-curve-getdistatparam ent (1+ par))
)
(progn
(setq inc (/ (- di2 di1) (1+ (fix (* 25 (/ (- di2 di1) rad (+ pi pi)))))))
(while (< di1 di2)
(setq lst (cons (vlax-curve-getpointatdist ent di1) lst)
di1 (+ di1 inc)
)
)
)
)
)
)
(setq par (1+ par))
)
lst
)
; Restituisce una griglia di punti all'interno del getboundingbox della poly selezionata
; Returns a grid of points within the BoundingBox of the selected poly
(defun grid_1 (/ P1_ P2_ n P> )
(vla-getboundingbox POLY_vl 'p1 'p2)
(setq P1_ (vlax-safearray->list p1))
(setq P2_ (vlax-safearray->list p2))
(setq P1_ (list (car P1_) (cadr P1_)))
(setq P2_ (list (car P2_) (cadr P2_)))
(setq Dx (/ (- (car P2_) (car P1_)) step1))
(setq Dy (/ (- (cadr P2_) (cadr P1_)) step1))
(setq n 0)
(setq P> P1_)
(setq Lp (list P1_))
(repeat (* (1+ step1) step1)
(setq P> (list (+ (car P>) Dx) (cadr P>)))
(setq Lp (cons P> Lp))
(setq n (1+ n))
(if (= n step1)
(progn
(setq n 0)
(setq P1_ (list (car P1_) (+ (cadr P1_) Dy)))
(setq P> P1_)
(setq Lp (cons P> Lp))
)
)
)
(setq Lp (cdr Lp))
)
; Restituisce una griglia di punti intorno al punto centrale (provvisorio)
; Returns a grid of points around the center point (provisional)
(defun grid_2 (/ P1_ P> n)
(setq list_p_int nil)
(setq P1_ (list (- (car P_center) (* Dx 2)) (- (cadr P_center) (* Dy 2))))
(setq Dx (/ (* 4 Dx) step2))
(setq Dy (/ (* 4 Dy) step2))
(setq n 0)
(setq P> P1_)
(setq list_p_int (list P1_))
(repeat (* (1+ step2) step2)
(setq P> (list (+ (car P>) Dx) (cadr P>)))
(setq list_p_int (cons P> list_p_int))
(setq n (1+ n))
(if (= n step2)
(progn
(setq n 0)
(setq P1_ (list (car P1_) (+ (cadr P1_) Dy)))
(setq P> P1_)
(setq list_p_int (cons P> list_p_int))
)
)
)
)
; restituisce la lista dei punti interni ad un poligono
; dati: - lista coordinate dei punti -> Lp
; - lista coordinate vertici poligono -> list_vert_poly
; Returns the list of points inside the polyline
(defun Point_int (/ P_distant n Pr cont attr p# Pa Pa_ Pb )
(setq P_distant (list (car (getvar "extmax")) (* 2 (cadr (getvar "extmax")))))
(setq list_p_int nil)
(foreach Pr Lp
(setq cont -1)
(setq attr 0)
(setq p# nil)
(setq Pa (nth (setq cont (1+ cont)) list_vert_poly))
(setq Pa_ Pa)
(repeat (length list_vert_poly)
(setq Pb (nth (setq cont (1+ cont)) list_vert_poly))
(if (= cont (length list_vert_poly)) (setq Pb Pa_))
(setq P# (inters Pa Pb Pr P_distant))
(if (/= P# nil) (setq attr (1+ attr)))
(setq Pa Pb)
)
(if (> (rem attr 2) 0) (setq list_p_int (cons Pr list_p_int)))
)
)
; Infittisce la griglia inserendo altri punti
; nel centro delle diagonali tra i punti interni
; Insert points (interior) to increase the density of the grid
(defun grid+ (/ G+)
(setq G+
(mapcar '(lambda ( x ) (list (+ (car x) (/ Dx 2)) (+ (cadr x) (/ Dy 2)))) list_p_int)
)
(setq list_p_int (append G+ list_p_int))
)
; Da una lista di punti restituisce quello più lontano da un oggetto
; dati: - lista dei punti -> list_p_int
; - oggetto -> POLY_vl
; Returns the farthest point from the polyline
(defun Point_center (/ Pa n Pvic)
(setq Dist 0.0000001)
(setq P_center nil)
(foreach Pa list_p_int
(setq Pvic (vlax-curve-getClosestPointTo POLY_vl Pa))
(if (> (distance Pa Pvic) Dist)
(progn
(setq P_center Pa)
(setq Dist (distance Pa Pvic))
)
)
)
(if (>= Dist 0.5) (setq Dist 0.5))
)
(defun date2sec ()
(setq s (getvar "DATE"))
(setq seconds (* 86400.0 (- s (fix s))))
)