Jump to content
flopo

Lowest y value - coordinate for a polyline

Recommended Posts

flopo

Hello,

How to determine te smaller (and bigger) value,Y or X, for a polyline? I mean the Y coordinate on a polyline where Y has the minimum value for the whole polyline?

Share this post


Link to post
Share on other sites
JohnM

look at the min and max functions

also i think there was a post about this awhile back try to search for it

Share this post


Link to post
Share on other sites
Tharwat

This would make a point at the lowest coordinate point of the selected Polyline that has the smallest Y value in it , besides that it would show the Coordinates of the Point which the point lays on . :)

 

(vl-load-com)
(defun c:test (/ ss Coords l i p p1 pt)
 ; Tharwat 15. 06. 2011
 (if (eq (getvar 'pdmode) 0)
   (setvar 'pdmode 3)
 )
 (if
   (setq ss (ssget "_+.:L" '((0 . "*POLYLINE"))))
    (progn
      (setq Coords (vlax-get (vlax-ename->vla-object (ssname ss 0))
                             'Coordinates
                   )
      )
      (setq l (/ (length Coords) 2))
      (setq i 0
            p (cons 10 (list (car Coords) (cadr Coords)))
      )
      (repeat l
        (setq
          p1 (cons 10
                   (list (nth i Coords) (nth (setq i (1+ i)) Coords))
             )
        )
        (if (< (caddr p1) (caddr p))
          (setq p p1)
        )
        (setq i (1+ i))
      )
      (print p)

      (entmakex (list (cons 0 "POINT") p))
    )
    (princ)
 )
 (princ)
)

Tharwat

Share this post


Link to post
Share on other sites
BlackBox

???

 

*cough* GetBoundingBox *cough*

 

(defun c:GBB () (c:GetBoundingBox))
(defun c:GetBoundingBox (/ ss v mn mx)
 (vl-load-com)
 (princ "\rGET BOUNDING BOX \n")
 (if (and (setq ss (ssget ":S:E" ))
          (vlax-method-applicable-p 
            (setq v (vlax-ename->vla-object (ssname ss 0)))
            'getboundingbox))
    (progn
      (vla-getboundingbox v 'mn 'mx)
      (princ (mapcar 'vlax-safearray->list (list mn mx))))
    (cond (ss (prompt "\n** GetBoundingBox method not available ** "))
          ((prompt "\n** Nothing selected ** "))))
 (princ))

 

Untested - Written quickly on my MacBook from memory.

Edited by BlackBox
Code correction

Share this post


Link to post
Share on other sites
Tharwat

Hi Renderman .

 

The (min max) are functions and you have used them as variables . Is that possible ? :)

 

(/ ss v [color=blue][b]min max[/b][/color])

 

Regards.

 

Tharwat

Share this post


Link to post
Share on other sites
BlackBox
Hi Renderman .

 

The (min max) are functions and you have used them as variables . Is that possible ? :)

 

(/ ss v [color=blue][b]min max[/b][/color])

 

I noticed that too when I came to work to test (code works BTW).

 

Sadly, it was a typo on my part typing code in the forum text box. :oops: Code corrected.

Share this post


Link to post
Share on other sites
Tharwat

No worries mate . :)

 

Best regards.

Share this post


Link to post
Share on other sites
Lee Mac

Here's some old code I wrote to find the Max/Min points of a curve:

 

(defun LM:CurveMinMax 
 ( obj fuzz / _GetBoundingBoxWithOffset _GroupByNum _FlattenPoint a acdoc acspc lst obj tmp )

 (defun _GetBoundingBoxWithOffset ( obj o / ll ur )
   (
     (lambda ( a )
       (mapcar
         (function
           (lambda ( b )
             (mapcar
               (function
                 (lambda ( c ) ((eval c) a))
               )
               b
             )
           )
         )
        '(
           (
             (lambda ( x ) (- (caar  x) o))
             (lambda ( x ) (- (cadar x) o))
           )
           (
             (lambda ( x ) (+ (caadr x) o))
             (lambda ( x ) (- (cadar x) o))
           )
           (
             (lambda ( x ) (+ (caadr  x) o))
             (lambda ( x ) (+ (cadadr x) o))
           )
           (
             (lambda ( x ) (- (caar   x) o))
             (lambda ( x ) (+ (cadadr x) o))
           )
         )
       )
     )
     (mapcar 'vlax-safearray->list
       (progn (vla-getboundingbox obj 'll 'ur) (list ll ur))
     )
   )
 )

 (defun _GroupByNum ( l n / r)
   (if l
     (cons
       (reverse (repeat n (setq r (cons (car l) r) l (cdr l)) r))
       (_GroupByNum l n)
     )
   )
 )

 (defun _FlattenPoint ( p )
   (list (car p) (cadr p) 0.0)
 )
   
 (setq acdoc (vla-get-activedocument (vlax-get-acad-object))
       acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace))
 )  
 (cond
   ( (not (vlax-method-applicable-p obj 'GetBoundingBox))
   )
   ( t
     (setq tmp
       (mapcar
         (function
           (lambda ( x )
             (apply 'vla-addline (cons acspc (mapcar 'vlax-3D-point x)))
           )
         )
         (_GroupByNum (mapcar '_FlattenPoint (_GetBoundingBoxWithOffset obj (- fuzz))) 2)
       )
     )
     (setq lst
       (mapcar
         (function
           (lambda ( x )
             (car (_GroupByNum (vlax-invoke obj 'Intersectwith x acExtendOtherEntity) 3))
           )
         )
         tmp
       )
     )
     (mapcar 'vla-delete tmp)
     lst
   )
 )
)


;; Test Function

(defun c:test( / e m )
 (if
   (and
     (setq e (car (entsel)))
     (setq m (LM:CurveMinMax (vlax-ename->vla-object e) 1e-)
     (apply 'and m)
   )
   (foreach x m
     (entmakex (list (cons 0 "POINT") (cons 10 x)))
   )
 )
 (princ)
)

Share this post


Link to post
Share on other sites
irneb
Hi Renderman .

 

The (min max) are functions and you have used them as variables . Is that possible ? :)

 

(/ ss v [color=blue][b]min max[/b][/color])

 

Regards.

 

Tharwat

It's "possible", since you can redefine anything in Lisp - and since they're localized variables they won't affect enything outside the defun - so the min & max functions wont be removed in other places. Though this is not recommended and would cause a warning message in VLIDE (something like protected symbol redefined).

Share this post


Link to post
Share on other sites
Tharwat
(something like protected symbol redefined).

 

Thank you .

 

I have faced that message before which made me panic for a long time and after searching in that time I have realized the main issue of it , and I doubt I may forget these memories with it and the perfect lesson that I had . :D

 

Regards.

Share this post


Link to post
Share on other sites
flopo

Hi guys,

I have a lisp with points defined like j1, j2......j10. Sometimes i can have only j1...j6, and sometimes j1...j10. I' trying to calculate lowest point on y like this

(SETQ PMIN (MIN (CADR J1) (CADR J2 )(CADR J3 )(CADR J4 )(CADR J5 )(CADR J6 )(CADR J7 )
	    (CADR J8 )(CADR J9 )(CADR J10 )))

 

when i have only j1...j5 is not working (of course!!). How to do this ? Which condition to add to make this work?

...If j6 exist, then....

how to do this? Thanks!

Share this post


Link to post
Share on other sites
BlackBox

Consider using the MAPCAR function.

 

Here's a small example using the coordinates of a rectangle drawn in WCS, then rotated 5 degrees (so clearly one vertex is the lowest):

 

(defun _LowYcoord  (pointList)
 (car (vl-sort (mapcar 'cadr pointList) '<))
 )

 

 

VLIDE Console (lowest Y value):

_LOWYCOORD 
_$ (_LowYcoord '((-11.1758 20.4623 0.00) (2.19028 21.6316 0.00) (3.11153 11.1017 0.00) (-10.2546 [color=red]9.93234[/color] 0.00)))
9.93234
_$ 

 

** Note that the supplied argument may be a list of any number of coordinates, either 2D (X Y), or 3D (X Y Z).

 

HTH

Share this post


Link to post
Share on other sites
flopo

(SETQ POINTLIST (LIST 'J1 'J2 'J3 'J4 'J5 'J6 'J7 'J8 'J9 'J10))


(SETQ PCOTAMIN (car (vl-sort (mapcar 'cadr pointList) '<)))

 

LIKE THIS? HOW?

Share this post


Link to post
Share on other sites
alanjt
Consider using the MAPCAR function.

 

Here's a small example using the coordinates of a rectangle drawn in WCS, then rotated 5 degrees (so clearly one vertex is the lowest):

 

(defun _LowYcoord  (pointList)
 (car (vl-sort (mapcar 'cadr pointList) '<))
 )

 

 

VLIDE Console (lowest Y value):

_LOWYCOORD 
_$ (_LowYcoord '((-11.1758 20.4623 0.00) (2.19028 21.6316 0.00) (3.11153 11.1017 0.00) (-10.2546 [color=red]9.93234[/color] 0.00)))
9.93234
_$ 

 

** Note that the supplied argument may be a list of any number of coordinates, either 2D (X Y), or 3D (X Y Z).

 

HTH

 

cough.gif

(defun _lowYcoord (pointlist)
 (car (vl-sort pointlst (function (lambda (a b) (< (cadr a) (cadr b))))))
)

Share this post


Link to post
Share on other sites
BlackBox

Slight modification:

 

(defun _LowYcoord  (pointList)
 (car (vl-sort (mapcar 'cadr [color=blue](mapcar 'eval[/color] pointList[color=blue])[/color]) '<))
 )

 

Example:

(setq J1 '(-11.1758 20.4623 0.00))
(setq J2 '(2.19028 21.6316 0.00))
(setq J3 '(3.11153 11.1017 0.00))
(setq J4 '(-10.2546 9.93234 0.00))

(setq pointList '(J1 J2 J3 J4))

(_LowYcoord pointList)

Share this post


Link to post
Share on other sites
flopo

I don't understand... I need a point... Which is the lowest point in this case? How to use it in the lisp after? I need to set a point... (setq pmin ....) ?? how?

(SETQ PMIN (_LowYcoord pointList)) ???

Share this post


Link to post
Share on other sites
BlackBox
I don't understand... I need a point... Which is the lowest poit in this case? How to use it in the lisp after? I need to set a point... (setq pmin ....) ?? how?

(SETQ PMIN (_LowYcoord pointList)) ???

 

Sorry, I got hung up on the 'Y' in your previous post:

 

I' trying to calculate lowest point on y like this

!

 

Give this a try:

 

(defun _LowYcoord  (pointList)
 (car (vl-sort (mapcar 'eval pointList) '(lambda (a b) (< (cadr a) (cadr b)))))
 )

 

*Tips hat to Alan*

Edited by BlackBox

Share this post


Link to post
Share on other sites
flopo

Same question as above...hot to set that point??

Share this post


Link to post
Share on other sites
BlackBox
Same question as above...hot to set that point??

 

Same response as above...

 

Here's an(other) example from Console using this function:

 

_LOWYCOORD 
_$ (setq J1 '(-11.1758 20.4623 0.00))
(-11.1758 20.4623 0.0)
_$ (setq J2 '(2.19028 21.6316 0.00))
(2.19028 21.6316 0.0)
_$ (setq J3 '(3.11153 11.1017 0.00))
(3.11153 11.1017 0.0)
_$ (setq J4 '(-10.2546 9.93234 0.00))
(-10.2546 9.93234 0.0)
_$ [color=blue](setq pointList '(J1 J2 J3 J4))[/color]
(J1 J2 J3 J4)
_$[color=red] (setq pMin (_LowYcoord pointList))[/color]
(-10.2546 9.93234 0.0)
_$ 

Share this post


Link to post
Share on other sites
pBe
Same response as above...

 

Hello... Hello.. Hello... Hello....

 

:lol:

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

×