TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Grrr1337 on June 25, 2019, 04:10:43 AM

Title: Convex Hull - Modification
Post by: Grrr1337 on June 25, 2019, 04:10:43 AM
Hi everyone,
I'm not sure how hard is this modification to be considered as challenge -
Basically provide a ConvexHull subfubfunction, (ConvexHull <PointList> <IndispensablePointList>),
where the result is something in between a "ConvexHull" and/or an "Outline" (see pic or dwg)

Sample test routine -
Code - Auto/Visual Lisp: [Select]
  1. (defun C:test ( / LWPoly L pL )
  2.  
  3.  
  4.   (defun LWPoly (lst cls)
  5.     (entmakex
  6.       (append
  7.         '((000 . "LWPOLYLINE")(100 . "AcDbEntity")(100 . "AcDbPolyline"))
  8.         (mapcar 'cons '(90 70) (list (length lst) (if cls 1 0)))
  9.         (mapcar (function (lambda (p) (cons 10 p))) lst)
  10.       )
  11.     )
  12.   )
  13.  
  14.   (setq L ; basically from this point-list will be generated a convex hull
  15.     (
  16.       (lambda ( / SS i pL )
  17.         (if (setq SS (ssget "_:L-I" '((0 . "LWPOLYLINE"))))
  18.           (progn
  19.             (repeat (setq i (sslength SS))
  20.               (setq pL (append (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) (entget (ssname SS (setq i (1- i)))))) pL))
  21.             )
  22.             pL
  23.           )
  24.         )
  25.       )
  26.     )
  27.   )
  28.  
  29.   (setq pL ; from this point-list the convex hull will be reshaped
  30.     (
  31.       (lambda ( / p L )
  32.         (if (setq p (getpoint "\nSpecify point: "))
  33.           (progn
  34.             (setq L (cons p L))
  35.             (while (setq p (getpoint p "\nSpecify next point: "))
  36.               (setq L (cons p L))
  37.             )
  38.             L
  39.           )
  40.         )
  41.       )
  42.     )
  43.   )
  44.  
  45.   (LWPoly (ConvexHull-Modified L pL) t)
  46.   (princ)
  47. )

In the above the standard convex hull would be generated from the polylines's vertices (turquoise in the picture),
however when manually are specified some points (red in pic) the convex hull will be reshaped/modified (red in the picture).

Title: Re: Convex Hull - Modification
Post by: ribarm on June 25, 2019, 05:31:39 AM
Are your requested shapes always othogonal like in your pictures? So if that's the case, Convex-Hull-Modified should recognize that new point list and recognize where should new points be inserted between original Convex-Hull point list... I am wondering do you actually need new point list, if you want shapes like you showed... Basically if point and next point at some angle - not 0.0; (/ pi 2.0); pi; (* 3.0 (/ pi 2.0)); (* 2.0 pi); new point should be inserted with coords (list (car p) (cadr nextp))? Is this you are looking for? - Then no need for new sub function, just post process Convex-Hull original point list...
Title: Re: Convex Hull - Modification
Post by: ribarm on June 25, 2019, 05:46:17 AM
Of course this condition should be satisfied :

- (< 0.0 ang (* 0.5 pi))
  (setq newpt (list (car p) (cadr nextp)))

- (< (* 0.5 pi) ang pi)
  (setq newpt (list (car nextp) (cadr p)))

- (< pi ang (* 1.5 pi))
  (setq newpt (list (car p) (cadr nextp)))

- (< (* 1.5 pi) ang (* 2.0 pi))
  (setq newpt (list (car nextp) (cadr p)))

HTH.
Title: Re: Convex Hull - Modification
Post by: Lee Mac on June 25, 2019, 02:58:21 PM
Here's the cheat's way (http://lee-mac.com/outlineobjects.html)  :-)
Title: Re: Convex Hull - Modification
Post by: ronjonp on June 25, 2019, 09:31:22 PM
Here's the cheat's way (http://lee-mac.com/outlineobjects.html)  :-)
LMFTFY .. "here's the clever way to do it" 8-)
Title: Re: Convex Hull - Modification
Post by: Lee Mac on June 26, 2019, 08:11:47 AM
Here's the cheat's way (http://lee-mac.com/outlineobjects.html)  :-)
LMFTFY .. "here's the clever way to do it" 8-)

 :-)