Author Topic: Previous point and the next point on a LWPOLYLINE  (Read 2649 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
Previous point and the next point on a LWPOLYLINE
« on: January 26, 2015, 07:16:30 AM »
Hello everyone,
someone has already made a bit of code that, given the coordinates of a point on a polyline segment, to determine the coordinates of the start and end points of the segment?

Thanks in advance.

snownut2

  • Swamp Rat
  • Posts: 971
  • Bricscad 22 Ultimate
Re: Previous point and the next point on a LWPOLYLINE
« Reply #1 on: January 26, 2015, 08:01:32 AM »
Hint,  Read the vertex points into a list, then manipulate the list to retrieve the info you are looking for.  You will find that doing a search here.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Previous point and the next point on a LWPOLYLINE
« Reply #2 on: January 26, 2015, 10:48:40 AM »
This ?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ s e a)
  2.   (if (and (setq s (entsel "\n Select LWpolyline :"))
  3.            (eq (cdr (assoc 0 (entget (setq e (car s))))) "LWPOLYLINE")
  4.       )
  5.     (mapcar
  6.       '(lambda (p) (vlax-curve-getpointatparam e p))
  7.                            e
  8.                            (vlax-curve-getclosestpointto e (cadr s))
  9.                          )
  10.                     )
  11.             )
  12.             (1+ a)
  13.       )
  14.     )
  15.   )
  16. )

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Previous point and the next point on a LWPOLYLINE
« Reply #3 on: January 26, 2015, 11:19:51 AM »
or maybe:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:lwpi (/ p pl bl tl sl en ss ed ev)
  2.  
  3. ;;;++++++++++ 3D Is Point On Line ++++++++++++++++++++++++++++++++++++++
  4. ;;;ARG -> TestPt LinePt1 LinePt2 Fuzz
  5. ;;;RET T nil
  6. (defun is_pt_online (pt l1 l2 fz)
  7.   (and (numberp fz)
  8.        (equal (distance l1 l2)
  9.               (+ (distance l1 pt)
  10.                  (distance l2 pt)) fz)))
  11.  
  12. ;;;MULTIPLE ASSOCIATIONS OF DOTTED PAIRS
  13. (defun massoc (key lst / nl)
  14.   (foreach x lst
  15.     (if (eq key (car x))
  16.         (setq nl (cons (cdr x) nl))))
  17.   (reverse nl))
  18.  
  19.   (setq pl nil bl nil tl nil sl nil)
  20.  
  21.   (initget 1)
  22.   (setq p (getpoint "\nSelect Point On LWPLine:   "))
  23.  
  24.   (while (not en)
  25.          (and (setq ss (ssget '((0 . "LWPOLYLINE"))))
  26.               (= (sslength ss) 1)
  27.               (setq en (ssname ss 0))))
  28.  
  29.   (setq ed (entget en)
  30.         pl (massoc 10 ed)
  31.         bl (massoc 42 ed)
  32.         ev (cdr (assoc 38 ed)))
  33.   (setq tl pl)
  34.   (if (not (and (zerop (apply 'min bl))
  35.                 (zerop (apply 'max bl))))
  36.       (alert "ARC LWPLINE Segments Found - Aborting")
  37.       (progn
  38.         (while (> (length pl) 1)
  39.                (if (is_pt_online (trans p 1 (cdr (assoc 210 ed)))
  40.                                  (append (car pl)  (list ev))
  41.                                  (append (cadr pl) (list ev))
  42.                                  1e-8)
  43.                    (setq sl (cons (list (car pl) (cadr pl)) sl)))
  44.                (setq pl (cdr pl)))))
  45.  
  46.   (princ "\nPoint ")
  47.   (prin1 p)
  48.  
  49.   (foreach s sl
  50.     (princ " Intersects @ Start Pt ")
  51.     (prin1 (car s))
  52.     (princ " And Ends @ Pt ")
  53.     (prin1 (cadr s)))
  54.  

Just for kicks.

Straight segments only

-David
R12 Dos - A2K

owenwengerd

  • Bull Frog
  • Posts: 451
Re: Previous point and the next point on a LWPOLYLINE
« Reply #4 on: January 26, 2015, 04:52:53 PM »
The only robust way to do this is to use (vlax-curve-getdistatparam) to get the distance at the target point, then to step through each segment from the beginning of the polyline accumulating distance until the target distance is reached. The (vlax-curve-getpointatparam) solution relies on assumptions about the underlying parameterization of a polyline that are not guaranteed to be true.

Lupo76

  • Bull Frog
  • Posts: 343
Re: Previous point and the next point on a LWPOLYLINE
« Reply #5 on: January 27, 2015, 03:29:00 AM »
This ?

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ s e a)
  2.   (if (and (setq s (entsel "\n Select LWpolyline :"))
  3.            (eq (cdr (assoc 0 (entget (setq e (car s))))) "LWPOLYLINE")
  4.       )
  5.     (mapcar
  6.       '(lambda (p) (vlax-curve-getpointatparam e p))
  7.                            e
  8.                            (vlax-curve-getclosestpointto e (cadr s))
  9.                          )
  10.                     )
  11.             )
  12.             (1+ a)
  13.       )
  14.     )
  15.   )
  16. )


At the moment it looks perfect!
I modified the code for my needs and works well.

Thank You !!

Thanks also to all the others who responded.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Previous point and the next point on a LWPOLYLINE
« Reply #6 on: January 27, 2015, 03:31:09 AM »
At the moment it looks perfect!
I modified the code for my needs and works well.

Thank You !!

Good to hear that , you are welcome .