Jump to content
amir0914

max and min coordinate in polyline

Recommended Posts

amir0914

hello everyone, i want an autolisp function to get maximum and minimum coordinate in a polyline, such as below image A is min and B is max Coordinates that i want to get them.

 

A = (x,y)

B = (x,y)

 

 

thanks in advanced.

Min-Max.jpg

Share this post


Link to post
Share on other sites
satishrajdev

Try this function :

 

(defun get:min (l)
 (list	(apply 'min (mapcar 'car l))
(apply 'min (mapcar 'cadr l))
 )
)

 

Example :

_$ (get:min '((1 6)(2 5)(3 4)))
(1 4)

 

Use (get:min (list a b)) in your case

Share this post


Link to post
Share on other sites
marko_ribar

(defun c:plminmax ( / lw pl pmin pmax )
 (while
   (or
     (not (setq lw (car (entsel "\nPick LWPOLYLINE..."))))
     (if lw
       (/= (cdr (assoc 0 (entget lw))) "LWPOLYLINE")
     )
   )
   (prompt "\nMissed or picked wrong entity type...")
 )
 (setq pl (mapcar '(lambda ( p ) (trans (list (car p) (cadr p) (cdr (assoc 38 (entget lw)))) lw 0)) (mapcar 'cdr (vl-remove-if  '(lambda ( x ) (/= (car x) 10)) (entget lw)))))
 (setq pmin  (car (setq pl (vl-sort pl '(lambda ( a b ) (if (equal (cadr a) (cadr b)  1e- (< (car a) (car b)) (< (cadr a) (cadr b))))))))
 (setq pmax (last pl))
 (prompt "\nA - pmin = ")(princ pmin)
 (prompt "\nB - pmax = ")(princ pmax)
 (princ)
)

Share this post


Link to post
Share on other sites
hanhphuc

$0.02 - 'bounding box' should return min max as well

Share this post


Link to post
Share on other sites
amir0914

thank you all,,, my problem has been resolved by your help. :)

Share this post


Link to post
Share on other sites
Lee Mac
Try this function :

 

(defun get:min (l)
 (list	(apply 'min (mapcar 'car l))
(apply 'min (mapcar 'cadr l))
 )
)

 

Example :

_$ (get:min '((1 6)(2 5)(3 4)))
(1 4)

 

Use (get:min (list a b)) in your case

 

$0.02 - 'bounding box' should return min max as well

 

Such solutions will not necessarily yield a point on the polyline. ;)

Share this post


Link to post
Share on other sites
pBe
Posted (edited)

What about the coordinates of:

 

WHAT ABOUT THIS.PNG

 

EDIT: I just realized its too easy for any shape :D

 

pseudo code --> enclosure+crate+adjacent+extension+horizontal

 

Lisp Code

Edited by pBe

Share this post


Link to post
Share on other sites
hanhphuc
Such solutions will not necessarily yield a point on the polyline. ;)

 

oops, i misunderstood. In case polyline has bulge, i thought OP looking merely min max like bbox :oops:

thanks Lee :)

Share this post


Link to post
Share on other sites
pBe
bbox

 

Oddly enough, that's exactly what i use: [ code removed from link ]

 

(defun c:HiLow (/ obj pts)
 (while (setq obj (Car (entsel)))
   (progn
     (vla-getboundingbox (vlax-ename->vla-object obj) 'll 'ur)
     (setq pts	(mapcar	'(lambda (p)
		   (vlax-curve-getClosestPointToProjection
		     obj
		     (vlax-safearray->list p)
		     '(1.0 0.0 0.0)
		   )
		 )
		(list ll ur)
	)
     )
     ;;	for showing the points		;;
     (Foreach p pts
(entmakex (list	(cons 0 "POINT")
		(cons 10 p)
	  )
)
     )
   )
 )
)

Share this post


Link to post
Share on other sites
hanhphuc
Oddly enough, that's exactly what i use: [ code removed from link ]

 

(defun c:HiLow (/ obj pts) .... )

 

BingoBox finally explained doubt thanks :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×