Author Topic: Reconstruct Line Points  (Read 4977 times)

0 Members and 1 Guest are viewing this topic.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Reconstruct Line Points
« Reply #15 on: December 31, 2015, 05:45:12 AM »
Maybe this:
Code - Auto/Visual Lisp: [Select]
  1. (defun unex (lt ret / z u)
  2.   (setq u (car lt)
  3.         z (vl-remove-if
  4.             '(lambda (x / y)
  5.               (and (setq y (unelista u x))
  6.                    (setq u y)
  7.               )
  8.             )
  9.             (cdr lt)
  10.           )
  11.   )
  12.   (cond
  13.     ((not z)
  14.       (cons u ret)
  15.     )
  16.     ((< (length z) (1- (length lt)))
  17.       (unex (append z (list u)) ret)
  18.     )
  19.     (T
  20.       (unex z (cons u ret))
  21.     )
  22.   )
  23. )
Code - Auto/Visual Lisp: [Select]
  1. (unex polis nil)
  2. (unex data nil)

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Reconstruct Line Points
« Reply #16 on: December 31, 2015, 09:25:23 AM »
Hi Lee:
this case can be extended to other applications, such binding lists the type:
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (setq polis '((9 0 0 11) (1 0 0 2) (10 0 11) (6 0 0 0 7) (12 0 0 0 9) (13 0 1 4)  (4 0 6) (1 0 0 3) (2 0 0 5) (8 0 7)))
  3. (unex polis)
  4.  ((12 0 0 0 9 0 0 11 0 10) (3 0 0 1 0 0 2 0 0 5) (13 0 1 4 0 6 0 0 0 7 0 8))
  5. (grouppoints polis)
  6. ((9 0 0 11) (8 0 7) (2 0 1 0 0 2) (10 0 11) (4 0 6 0 0 0 7) (13 0 1 4) (12 0 0 0 9))
  7.  

Hi Carlos,

My earlier code could be quite easily adapted to account for lists of any length:
Code - Auto/Visual Lisp: [Select]
  1. (defun grouppoints ( l / foo )
  2.     (defun foo ( r l / m )
  3.         (foreach x l
  4.             (cond
  5.                 (   (equal (car r) (car x) 1e-8)
  6.                     (setq r (append (reverse x) (cdr r)))
  7.                 )
  8.                 (   (equal (car r) (last x) 1e-8)
  9.                     (setq r (append x (cdr r)))
  10.                 )
  11.                 (   (equal (last r) (car x) 1e-8)
  12.                     (setq r (append r (cdr x)))
  13.                 )
  14.                 (   (equal (last r) (last x) 1e-8)
  15.                     (setq r (append r (cdr (reverse x))))
  16.                 )
  17.                 (   (setq m (cons x m)))
  18.             )
  19.         )
  20.         (cond
  21.             (   (null m) (list r))
  22.             (   (= (length m) (length l)) (cons r (foo (car m) (cdr m))))
  23.             (   (foo r m))
  24.         )
  25.     )
  26.     (foo (car l) (cdr l))
  27. )
Code - Auto/Visual Lisp: [Select]
  1. _$ (grouppoints polis)
  2. ((12 0 0 0 9 0 0 11 0 10) (3 0 0 1 0 0 2 0 0 5) (13 0 1 4 0 6 0 0 0 7 0 8))

CarlosS

  • Mosquito
  • Posts: 3
Re: Reconstruct Line Points
« Reply #17 on: December 31, 2015, 10:39:23 AM »
Lee, Roy, excellent, both functions gives correct results.

 Thank you and happy new year.
« Last Edit: December 31, 2015, 10:42:35 AM by CarlosS »