Author Topic: 3DPolyline Analysis  (Read 2014 times)

0 Members and 1 Guest are viewing this topic.

ChrisCarlson

  • Guest
3DPolyline Analysis
« on: March 02, 2016, 09:17:12 AM »
I'm drawing a blank this morning but how can you determine if a 3dpolyline is straight when it has vertexes? If there is only a start and end point that's easy to figure out but when vertexes are involved it gets confusing.

Comparing start and end point doesn't help as it would show both of these as "straight"
« Last Edit: March 02, 2016, 09:43:46 AM by ChrisCarlson »

David Bethel

  • Swamp Rat
  • Posts: 656
Re: 3DPolyline Analysis
« Reply #1 on: March 02, 2016, 10:30:11 AM »
Maybe:

Code: [Select]
;;;ARG -> TestPt LinePt1 LinePt2 Fuzz
;;;RET T nil
(defun is_pt_online (pt l1 l2 fz)
  (and (numberp fz)
       (equal (distance l1 l2)
              (+ (distance l1 pt)
                 (distance l2 pt)) fz)))

For 1st 3 points of the 3DPOLY :
Code: [Select]
(is_pt_online v1 v0 v2 1e-8)


-David
R12 Dos - A2K

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: 3DPolyline Analysis
« Reply #2 on: March 02, 2016, 11:25:43 AM »
If I was doing this in .net then i would just start at the beginning and get the first two points.  Call them my start and end point and calculate its normal vector.  I would then take the end point and call it the start point and then get the next point and call it the end point and calculate its normal vector.  If the two vectors are equal then the two segments are straight.  Rinse and repeat with the next segment.


I am not a lisp programmer so I hope I am not repeating the previous solution.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: 3DPolyline Analysis
« Reply #3 on: March 02, 2016, 01:05:57 PM »
As Keith has indicated, you can test every set of three vertices, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (defun straight3dpoly-p ( ent )
  2.     (pointsonline-p (polyvertices ent))
  3. )
  4. (defun polyvertices ( ent / enx )
  5.     (if (= "VERTEX" (cdr (assoc 0 (setq enx (entget ent)))))
  6.         (cons (cdr (assoc 10 enx)) (polyvertices (entnext ent)))
  7.         (if (= "POLYLINE" (cdr (assoc 0 enx)))
  8.             (polyvertices (entnext ent))
  9.         )
  10.     )
  11. )
  12. (defun pointsonline-p ( lst )
  13.     (or (null (caddr lst))
  14.         (and
  15.             (equal
  16.                 (distance (car lst) (caddr lst))
  17.                 (+ (distance (car lst) (cadr lst)) (distance (cadr lst) (caddr lst)))
  18.                 1e-8
  19.             )
  20.             (pointsonline-p (cdr lst))
  21.         )
  22.     )
  23. )
  24.  

ChrisCarlson

  • Guest
Re: 3DPolyline Analysis
« Reply #4 on: March 02, 2016, 04:18:44 PM »
Maybe:

Code: [Select]
;;;ARG -> TestPt LinePt1 LinePt2 Fuzz
;;;RET T nil
(defun is_pt_online (pt l1 l2 fz)
  (and (numberp fz)
       (equal (distance l1 l2)
              (+ (distance l1 pt)
                 (distance l2 pt)) fz)))

For 1st 3 points of the 3DPOLY :
Code: [Select]
(is_pt_online v1 v0 v2 1e-8)


-David
As Keith has indicated, you can test every set of three vertices, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (defun straight3dpoly-p ( ent )
  2.     (pointsonline-p (polyvertices ent))
  3. )
  4. (defun polyvertices ( ent / enx )
  5.     (if (= "VERTEX" (cdr (assoc 0 (setq enx (entget ent)))))
  6.         (cons (cdr (assoc 10 enx)) (polyvertices (entnext ent)))
  7.         (if (= "POLYLINE" (cdr (assoc 0 enx)))
  8.             (polyvertices (entnext ent))
  9.         )
  10.     )
  11. )
  12. (defun pointsonline-p ( lst )
  13.     (or (null (caddr lst))
  14.         (and
  15.             (equal
  16.                 (distance (car lst) (caddr lst))
  17.                 (+ (distance (car lst) (cadr lst)) (distance (cadr lst) (caddr lst)))
  18.                 1e-8
  19.             )
  20.             (pointsonline-p (cdr lst))
  21.         )
  22.     )
  23. )
  24.  

So if I'm reading these correctly the thought is as such;

3DPolyLine (numbers being vertices)
1 - 2 - 3 - 4 - 5 - 6

Test the following
1 - 2 - 3
2 - 3 - 4
3 - 4 - 5
4 - 5 - 6

if all the above is true, then the line is straight.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: 3DPolyline Analysis
« Reply #5 on: March 02, 2016, 04:53:31 PM »
Correct  :-)

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: 3DPolyline Analysis
« Reply #6 on: March 02, 2016, 06:23:00 PM »
Another 3 variants, first 2 using the same method as in Lee's lisp.
Code - Auto/Visual Lisp: [Select]
  1. (defun str_poly1 (e / r i n a b c)
  2.   (setq r T
  3.         i (vlax-curve-getstartparam e)
  4.         n (vlax-curve-getendparam e)
  5.         )
  6.   (while (and (<= i n)  r)
  7.     (or
  8.       (if (not a) (setq a c))
  9.       (if (not b) (setq b c))
  10.       (setq r (equal (+ (distance a b) (distance b c)) (distance a c) 1e-8)
  11.             a b b c i (1+ i))
  12.       )
  13.     )
  14.   r
  15.   )

Code - Auto/Visual Lisp: [Select]
  1. (defun str_poly2 (e / i l)
  2.     (setq l (cons (vlax-curve-getpointatparam e (setq i (1- i))) l))
  3.     )
  4.     '(lambda (a b c)
  5.        (equal (+ (distance a b) (distance b c)) (distance a c) 1e-8)
  6.      )
  7.     l (cdr l) (cddr l)
  8.   )
  9. )

Code - Auto/Visual Lisp: [Select]

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / e)
  2.   (while (setq e (ssget "_+.:S" '((0 . "*polyline"))))
  3.     (setq e (ssname e 0))
  4.     (print (str_poly1 e))
  5.     (princ "\t")
  6.     (princ (str_poly2 e))
  7.     (princ "\t")
  8.     (princ (str_poly3 e))
  9.     )
  10.   (princ)
  11.   )

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: 3DPolyline Analysis
« Reply #7 on: March 02, 2016, 06:43:13 PM »
Code - Auto/Visual Lisp: [Select]

Good observation Stefan, I like it  :-)

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2135
  • class keyThumper<T>:ILazy<T>
Re: 3DPolyline Analysis
« Reply #8 on: March 02, 2016, 07:07:47 PM »

Code - Auto/Visual Lisp: [Select]
  1. (defun str_poly3 (e)
  2. ;<...>
  3.  )


excellent return to first principles.

Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.