Author Topic: ConvexHull----bug?  (Read 297 times)

0 Members and 1 Guest are viewing this topic.

well20152016

  • Newt
  • Posts: 75
ConvexHull----bug?
« on: January 04, 2019, 06:08:09 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test()
  2. (setq lst (LM:ConvexHull (mapcar 'cdr  (vl-remove-if-not'(lambda(x)(=(car x)10))(entget (car(entsel)))))))
  3.               (list (cons 0 "LWPOLYLINE")
  4.                     (cons 100 "AcDbEntity")
  5.                     (cons 100 "AcDbPolyline")
  6.                     (cons 90 (length lst))
  7.                     (cons 70 1 )
  8.                     (cons 62 1 )
  9.               )
  10.               (mapcar(function (lambda (p) (cons 10 p))) lst)
  11.             )
  12. )
  13. )
  14.  
  15.  
  16.  
  17.  
  18. ;; Convex Hull  -  Lee Mac
  19. ;; Implements the Graham Scan Algorithm to return the Convex Hull of a list of points.
  20.  
  21. (defun LM:ConvexHull ( lst / ch p0 )
  22.     (cond
  23.         (   (< (length lst) 4) lst)
  24.         (   (setq p0 (car lst))
  25.             (foreach p1 (cdr lst)
  26.                 (if (or (< (cadr p1) (cadr p0))
  27.                         (and (equal (cadr p1) (cadr p0) 1e-8) (< (car p1) (car p0)))
  28.                     )
  29.                     (setq p0 p1)
  30.                 )
  31.             )
  32.             (setq lst
  33.                 (vl-sort lst
  34.                     (function
  35.                         (lambda ( a b / c d )
  36.                             (if (equal (setq c (angle p0 a)) (setq d (angle p0 b)) 1e-8)
  37.                                 (< (distance p0 a) (distance p0 b))
  38.                                 (< c d)
  39.                             )
  40.                         )
  41.                     )
  42.                 )
  43.             )
  44.             (setq ch (list (caddr lst) (cadr lst) (car lst)))
  45.             (foreach pt (cdddr lst)
  46.                 (setq ch (cons pt ch))
  47.                 (while (and (caddr ch) (LM:Clockwise-p (caddr ch) (cadr ch) pt))
  48.                     (setq ch (cons pt (cddr ch)))
  49.                 )
  50.             )
  51.             ch
  52.         )
  53.     )
  54. )
  55.  
  56. ;; Clockwise-p  -  Lee Mac
  57. ;; Returns T if p1,p2,p3 are clockwise oriented or collinear
  58.                  
  59. (defun LM:Clockwise-p ( p1 p2 p3 )
  60.     (<  (-  (* (- (car  p2) (car  p1)) (- (cadr p3) (cadr p1)))
  61.             (* (- (cadr p2) (cadr p1)) (- (car  p3) (car  p1)))
  62.         )
  63.         1e-8
  64.     )
  65. )

ribarm

  • Water Moccasin
  • Posts: 2091
  • Marko Ribar, architect
Re: ConvexHull----bug?
« Reply #1 on: January 04, 2019, 06:20:26 AM »
Refer to this post :
http://www.theswamp.org/index.php?topic=53116.msg578882#msg578882

Also for ConvexHull - pts on Hull refer to my latest codes posted for TSP started by Evgeniy Elpanov

HTH., M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

well20152016

  • Newt
  • Posts: 75
Re: ConvexHull----bug?
« Reply #2 on: January 04, 2019, 07:00:05 AM »
thank!