
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I want to find point cluster from point list by DFS (Depth First Search).
My algorithm is below...
1. Get selection set by layer name.
2. Get the point list like this from selection set.
((77000.4 135874.0) (76979.0 135874.0) (77000.4 136238.0) (76979.0 136238.0) (147524.0 108880.0) (147502.0 108880.0) (147524.0 109243.0) (147502.0 109243.0) (152374.0 105518.0) (152353.0 105518.0) (152374.0 105882.0) (152353.0 105882.0))
3. Setting visited (= check array) false for all points.
4. Iterate points, and run depth first search from the point unless it is not visited.
I want to 1 point cluster by running 1 depth first search.
But, I got this error message,
Command: MYGETPOINT
Hard error occurred ***
internal stack limit reached (simulated)
So I attached my code..
(defun setNth (l n w)
(cond
( (null l) '())
( (eq n 0) (cons w (cdr l)))
( (cons (car l) (setNth (cdr l) (- n 1) w)))))
(defun dfs(idx)
(setq cur (nth idx vertex))
(setq curx (nth 0 cur))
(setq cury (nth 1 cur))
(setq i 0)
(while (< i (length vertex))
(if (= (nth i visited) 0)
(progn
(setq nxt (nth i vertex))
(setq nxtx (nth 0 nxt))
(setq nxty (nth 1 nxt))
(setq dist (+ (* (- curx nxtx) (- curx nxtx)) (* (- cury nxty) (- cury nxty))))
(if (< dist 1000000) ; continue dfs if nxt point is sufficiently close to cur point
(progn
(setq cluster (append cluster (list i)))
(setNth visited i 1)
(dfs i)
)
)
)
)
(setq i (1+ i))
)
)
(defun c:MyGetPoint()
; Selection Set
(setq filter (list (cons 8 "polyline") (cons 0 "LWPOLYLINE")))
(setq ss (ssget "_X" filter))
; Make vertex list
(setq vertex nil)
(setq i 0)
(repeat (sslength ss)
(setq e (ssname ss i)
eType (cdr (assoc 0 (entget e)))
ePoint (cdr (assoc 10 (entget e)))
i (1+ i)
)
(setq vertex (append vertex (list (list (nth 0 ePoint) (nth 1 ePoint)))))
)
(print vertex)
;(princ (length vertex))
; visited -> check array
(setq i 0)
(setq visited nil)
(while (< i (length vertex))
(setq visited (append visited '(0)))
(setq i (1+ i))
)
;(print visited)
;(print (length visited))
(setq i 0)
(while (< i (length vertex))
(if (= (nth i visited) 0)
(progn
(setq cluster nil)
(setNth visited i 1)
(dfs i)
; TODO: cluster should be the set of indices of points which are very close
(print cluster)
)
)
(setq i (1+ i))
)
)
Could you find the cause of this error?
Thanks in advance!
Solved! Go to Solution.