Jump to content

Lowest y value - coordinate for a polyline


flopo

Recommended Posts

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?

Link to comment
Share on other sites

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • flopo

    6

  • BlackBox

    6

  • Tharwat

    4

  • pBe

    3

Top Posters In This Topic

Posted Images

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

Link to comment
Share on other sites

???

 

*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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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).
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 6 months later...

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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


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

 

LIKE THIS? HOW?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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

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