### Author Topic: Convex Hull - Modification  (Read 881 times)

0 Members and 1 Guest are viewing this topic.

#### Grrr1337

• Swamp Rat
• Posts: 728 ##### 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.         '((000 . "LWPOLYLINE")(100 . "AcDbEntity")(100 . "AcDbPolyline"))
6.         (mapcar 'cons '(90 70) (list (length lst) (if cls 1 0)))
7.         (mapcar (function (lambda (p) (cons 10 p))) lst)
8.       )
9.     )
10.   )
11.
12.   (setq L ; basically from this point-list will be generated a convex hull
13.     (
14.       (lambda ( / SS i pL )
15.         (if (setq SS (ssget "_:L-I" '((0 . "LWPOLYLINE"))))
16.             (repeat (setq i (sslength SS))
17.               (setq pL (append (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= 10 (car x))) (entget (ssname SS (setq i (1- i)))))) pL))
18.             )
19.             pL
20.           )
21.         )
22.       )
23.     )
24.   )
25.
26.   (setq pL ; from this point-list the convex hull will be reshaped
27.     (
28.       (lambda ( / p L )
29.         (if (setq p (getpoint "\nSpecify point: "))
30.             (setq L (cons p L))
31.             (while (setq p (getpoint p "\nSpecify next point: "))
32.               (setq L (cons p L))
33.             )
34.             L
35.           )
36.         )
37.       )
38.     )
39.   )
40.
41.   (LWPoly (ConvexHull-Modified L pL) t)
42.   (princ)
43. )

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)
)
)

#### ribarm ##### 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) #### ribarm ##### 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)  ##### Re: Convex Hull - Modification
« Reply #3 on: June 25, 2019, 02:58:21 PM »
Here's the cheat's way #### ronjonp ##### Re: Convex Hull - Modification
« Reply #4 on: June 25, 2019, 09:31:22 PM »
Here's the cheat's way LMFTFY .. "here's the clever way to do it" Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC ##### Re: Convex Hull - Modification
« Reply #5 on: June 26, 2019, 08:11:47 AM »
Here's the cheat's way LMFTFY .. "here's the clever way to do it"  