Jump to content

max and min coordinate in polyline


RepCad

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites


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

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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
  • Like 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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

 

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

 

BingoBox finally explained doubt thanks :)

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...