Find minimum enclosing triangle by approximation points of reference curve :
Approximation points (I've modified Lee's sub) :
(defun c:curve2pts ( / MR:ent->pts c acc pts )
(vl-load-com)
;; Entity to Point List - M.R.
;; Returns a list of points describing or approximating the supplied entity, else nil if the entity is not supported.
;; ent - [ent] Entity name to be described by point list (POINT/LINE/ARC/CIRCLE/LWPOLYLINE/POLYLINE/ELLIPSE/SPLINE)
;; acc - [num] Positive number determining the point density for non-linear objects
(defun MR:ent->pts ( ent acc / der di1 di2 enx inc lst par fds fdm )
(setq enx (entget ent))
(cond
( (= "POINT" (cdr (assoc 0 enx)))
(list (cdr (assoc 10 enx)))
)
( (= "LINE" (cdr (assoc 0 enx)))
(list (cdr (assoc 10 enx)) (cdr (assoc 11 enx)))
)
( (wcmatch (cdr (assoc 0 enx)) "ARC,CIRCLE")
(setq di1 0.0
di2 (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent))
inc (/ di2 acc)
di2 (- di2 1e-8)
)
(while (< di1 di2)
(setq lst (cons (vlax-curve-getpointatdist ent di1) lst)
di1 (+ di1 inc)
)
)
(reverse (if (vlax-curve-isclosed ent) lst (cons (vlax-curve-getendpoint ent) lst)))
)
( (and (wcmatch (cdr (assoc 0 enx)) "*POLYLINE") (zerop (logand 80 (cdr (assoc 70 enx)))))
(setq par 0)
(repeat (fix (+ 1.0 1e-8 (vlax-curve-getendparam ent)))
(cond
( (not (setq der (vlax-curve-getsecondderiv ent par))))
( (equal der '(0.0 0.0 0.0) 1e-8)
(if (/= par (vlax-curve-getendparam ent))
(setq lst (cons (vlax-curve-getpointatparam ent par) lst))
)
)
( (not (equal der '(0.0 0.0 0.0) 1e-8))
(if (/= par (vlax-curve-getendparam ent))
(progn
(setq di1 (vlax-curve-getdistatparam ent par)
di2 (vlax-curve-getdistatparam ent (1+ par))
)
(setq inc (/ (- di2 di1) acc)
di2 (- di2 1e-8)
)
(while (< di1 di2)
(setq lst (cons (vlax-curve-getpointatdist ent di1) lst)
di1 (+ di1 inc)
)
)
)
)
)
)
(setq par (1+ par))
)
(reverse (if (vlax-curve-isclosed ent) lst (cons (vlax-curve-getendpoint ent) lst)))
)
( (= "ELLIPSE" (cdr (assoc 0 enx)))
(setq di1 (vlax-curve-getdistatparam ent (vlax-curve-getstartparam ent))
di2 (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent))
inc (/ (- di2 di1) acc)
di2 (- di2 1e-8)
)
(while (< di1 di2)
(setq fds (cons (distance '(0.0 0.0 0.0) (vlax-curve-getfirstderiv ent (vlax-curve-getparamatdist ent di1))) fds)
di1 (+ di1 (distance '(0.0 0.0 0.0) (vlax-curve-getfirstderiv ent (vlax-curve-getparamatdist ent di1))))
)
)
(setq di1 (vlax-curve-getdistatparam ent (vlax-curve-getstartparam ent)))
(setq fdm (apply 'max fds))
(while (< di1 di2)
(setq lst (cons (vlax-curve-getpointatdist ent di1) lst)
di1 (+ di1 (* (/ (distance '(0.0 0.0 0.0) (vlax-curve-getfirstderiv ent (vlax-curve-getparamatdist ent di1))) fdm) inc))
)
)
(reverse (if (vlax-curve-isclosed ent) lst (cons (vlax-curve-getendpoint ent) lst)))
)
( (= "SPLINE" (cdr (assoc 0 enx)))
(setq di1 (vlax-curve-getdistatparam ent (vlax-curve-getstartparam ent))
di2 (vlax-curve-getdistatparam ent (vlax-curve-getendparam ent))
inc (/ (- di2 di1) acc)
di2 (- di2 1e-8)
)
(while (< di1 di2)
(setq fds (cons (distance '(0.0 0.0 0.0) (vlax-curve-getfirstderiv ent (vlax-curve-getparamatdist ent di1))) fds)
di1 (+ di1 (distance '(0.0 0.0 0.0) (vlax-curve-getfirstderiv ent (vlax-curve-getparamatdist ent di1))))
)
)
(setq di1 (vlax-curve-getdistatparam ent (vlax-curve-getstartparam ent)))
(setq fdm (apply 'max fds))
(while (< di1 di2)
(setq lst (cons (vlax-curve-getpointatdist ent di1) lst)
di1 (+ di1 (* (/ (distance '(0.0 0.0 0.0) (vlax-curve-getfirstderiv ent (vlax-curve-getparamatdist ent di1))) fdm) inc))
)
)
(reverse (if (vlax-curve-isclosed ent) lst (cons (vlax-curve-getendpoint ent) lst)))
)
)
)
(while (or (not (setq c (car (entsel "\nPick curve entity...")))) (if c (vl-catch-all-error-p (vl-catch-all-apply 'vlax-curve-getstartpoint (list c)))))
(prompt "\nMissed or picked wrong entity type...")
)
(initget 6)
(setq acc (getreal "\nSpecify number of point density <35> : "))
(if (null acc)
(setq acc 35.0)
)
(setq pts (MR:ent->pts c acc))
(foreach p pts
(entmake (list '(0 . "POINT") (cons 10 p)))
)
(princ)
)
Minimum and maximum enclosing triangle - convex hull :
http://www.theswamp.org/index.php?topic=50176.msg553387#msg553387When you find smallest triangle, cut the biggest apex area sub triangle with convex hull edge so the final result is 4 pt shape with smallest area...