Author Topic: Convex Hull - Modification  (Read 2444 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 812
Convex Hull - Modification
« 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).

(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Convex Hull - Modification
« Reply #1 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...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Convex Hull - Modification
« Reply #2 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.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Convex Hull - Modification
« Reply #3 on: June 25, 2019, 02:58:21 PM »

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Convex Hull - Modification
« Reply #4 on: June 25, 2019, 09:31:22 PM »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England