Author Topic: arc-to-line-segments duplicated vertices bug help to fix  (Read 1839 times)

0 Members and 1 Guest are viewing this topic.

nekonihonjin

  • Newt
  • Posts: 103
arc-to-line-segments duplicated vertices bug help to fix
« on: October 12, 2022, 01:43:25 PM »
I'm using (among many others) this cool lisp from Lee Mac to convert curves to straight line segments.

http://www.lee-mac.com/segmentcurve.html

It was only now that I'm doing a routine that inserts an object at each vertex of a polyline, that I realized I had duplicate objects at certain vertices. After checking my routine many times for errors, I checked the polyline and found two places where the vertices were duplicated, corresponding to the quadrants of a circle.

Don't know if Lee Mac himself will read this post, but if someone can make the correction I would be very grateful.

« Last Edit: October 12, 2022, 02:14:54 PM by nekonihonjin »

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Lee Mac lisp arc-to-line-segments duplicated vertices
« Reply #1 on: October 12, 2022, 02:08:20 PM »
nekonihonjin, I would consider using a better subject title for this post. That is to say, when people see a name in the subject line they may tend to not reply/read/etc. and this could limit the number of users that could help you answer your question (I only saw this post because I use "latest posts" view to help me moderate easier/faster whereas others may just use the "unread posts" to see a list of questions).

Example:
1. If you have a specific question about a program that someone has written, you can use several different methods to contact them directly (email, PM, etc).
2. If you have a generalized question about how to use/modify a routine written by a person then I would use the subject line to describe your general question (not direct a question at a specific person or persons).

My recommended subject title (because it looks to me, that Lee didn't write your routine but instead just a helper function(s) in your routine so you have a generalized question):
"Removing duplicated vertices on a polyline"
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

nekonihonjin

  • Newt
  • Posts: 103
Re: Lee Mac lisp arc-to-line-segments duplicated vertices
« Reply #2 on: October 12, 2022, 02:14:28 PM »
Hi John, I will change the title of the post according to your recommendation.

it is indeed the lisp that Lee Mac created that has the bug and the one that would need to be fixed, I was not using it as a helper in my code, but first I used Lee's to modify the line and then to that new line I apply mine. But the line comes out of Lee's code with duplicated vertices.

you could write a lisp to remove those duplicate vertices, but the correct thing to do would be to fix the original routine so that it does not produce them.

What happens is that I am a beginner and making this modification is way beyond my possibilities.
« Last Edit: October 12, 2022, 02:19:01 PM by nekonihonjin »

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: arc-to-line-segments duplicated vertices bug help to fix
« Reply #3 on: October 12, 2022, 02:57:37 PM »
I understand (so this is more of a "bug fix" type of request). Well, there are many people here that I'm sure could correct the bug/error so I'm sure you will find a solution quickly.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: arc-to-line-segments duplicated vertices bug help to fix
« Reply #4 on: October 20, 2022, 03:42:24 PM »
Hi John,

My program operates in a very simplistic manner in that it merely divides the total length of the selected object by the number of segments specified by the user (in order to obtain the length of a single segment), and then constructs a polyline with vertices positioned along the selected object every segment length.

As such, if the original object crosses over itself, then the resulting polyline will also cross over itself; and in such cases, depending on the number of segments specified, the vertices of the resulting polyline may coincide at these locations. This is not a bug in the program, but simply a consequence of how the program operates - if you test the program using a varying number of segments, you will observe what I have described above.

nekonihonjin

  • Newt
  • Posts: 103
Re: arc-to-line-segments duplicated vertices bug help to fix
« Reply #5 on: October 21, 2022, 09:59:04 AM »
Hi John,

My program operates in a very simplistic manner in that it merely divides the total length of the selected object by the number of segments specified by the user (in order to obtain the length of a single segment), and then constructs a polyline with vertices positioned along the selected object every segment length.

As such, if the original object crosses over itself, then the resulting polyline will also cross over itself; and in such cases, depending on the number of segments specified, the vertices of the resulting polyline may coincide at these locations. This is not a bug in the program, but simply a consequence of how the program operates - if you test the program using a varying number of segments, you will observe what I have described above.



Thanks for the response Lee Mac,
The same behavior occurs in a polyline that does not crosses itself, I attach an example.
It is rather at the end of the arc where it repeats the vertex.

mhupp

  • Bull Frog
  • Posts: 250
Re: arc-to-line-segments duplicated vertices bug help to fix
« Reply #6 on: October 21, 2022, 01:54:21 PM »
How are you splitting the arc up?

I am exploding the polyline running segs on the arc and join them back together. I get 23 vertex yours has 24 @ (22 & 23) are the same

nekonihonjin

  • Newt
  • Posts: 103
Re: arc-to-line-segments duplicated vertices bug help to fix
« Reply #7 on: October 21, 2022, 02:18:45 PM »
How are you splitting the arc up?

I am exploding the polyline running segs on the arc and join them back together. I get 23 vertex yours has 24 @ (22 & 23) are the same

I'm using the         SegmentCurveV1-1.lsp       
Lee Mac routine that I mentioned above, on the left polyline, getting as result the one on the right.

mhupp

  • Bull Frog
  • Posts: 250
Re: arc-to-line-segments duplicated vertices bug help to fix
« Reply #8 on: October 21, 2022, 02:39:20 PM »
I'm using the         SegmentCurveV1-1.lsp       
Lee Mac routine that I mentioned above, on the left polyline, getting as result the one on the right.

I get that. but you can't segment the arc only if you pick a polyline with that command. I must be missing something.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: arc-to-line-segments duplicated vertices bug help to fix
« Reply #9 on: October 21, 2022, 03:37:42 PM »
Hi John,

My program operates in a very simplistic manner in that it merely divides the total length of the selected object by the number of segments specified by the user (in order to obtain the length of a single segment), and then constructs a polyline with vertices positioned along the selected object every segment length.

As such, if the original object crosses over itself, then the resulting polyline will also cross over itself; and in such cases, depending on the number of segments specified, the vertices of the resulting polyline may coincide at these locations. This is not a bug in the program, but simply a consequence of how the program operates - if you test the program using a varying number of segments, you will observe what I have described above.

Thanks for the response Lee Mac,
The same behavior occurs in a polyline that does not crosses itself, I attach an example.
It is rather at the end of the arc where it repeats the vertex.

Based on your drawing, the object has either been exploded first, or has not been processed by my program as written (else the line segment of the polyline would also be divided into segments); as such, this is not a bug arising from my program.

nekonihonjin

  • Newt
  • Posts: 103
Re: arc-to-line-segments duplicated vertices bug help to fix
« Reply #10 on: October 21, 2022, 04:14:09 PM »
Hi John,

My program operates in a very simplistic manner in that it merely divides the total length of the selected object by the number of segments specified by the user (in order to obtain the length of a single segment), and then constructs a polyline with vertices positioned along the selected object every segment length.

As such, if the original object crosses over itself, then the resulting polyline will also cross over itself; and in such cases, depending on the number of segments specified, the vertices of the resulting polyline may coincide at these locations. This is not a bug in the program, but simply a consequence of how the program operates - if you test the program using a varying number of segments, you will observe what I have described above.

Thanks for the response Lee Mac,
The same behavior occurs in a polyline that does not crosses itself, I attach an example.
It is rather at the end of the arc where it repeats the vertex.

Based on your drawing, the object has either been exploded first, or has not been processed by my program as written (else the line segment of the polyline would also be divided into segments); as such, this is not a bug arising from my program.

You're absolutely correct Lee Mac, my sincere apologies, when I was looking for options to convert arcs to segments I downloaded several lisp from various sources. I kept one to work with and all this time I had been thinking it was yours.
I downloaded it again from your page and found that it is not the same.

What happened was that the person who created it used one of your functions as a prop, seeing your name at a quick glance, I assumed it was yours.

I gave it preference because it does not create vertices in straight sections.

Would you mind taking a look at it?


Code: [Select]
(defun c:seg ( / unit LM:LWPoly->List en lst n )

    (defun unit ( v )
        (mapcar '(lambda ( x ) (/ x (distance '(0.0 0.0 0.0) v))) v)
    )

    ;; LWPolyline to Point List  -  Lee Mac
    ;; Returns a list of points describing the supplied LWPolyline

    (defun LM:LWPoly->List ( ent n / der di1 di2 inc lst par rad )
        (vl-load-com)
        (setq par 0)
        (repeat (cdr (assoc 90 (entget ent)))
            (if (setq der (vlax-curve-getsecondderiv ent par))
                (if (or (equal der '(0.0 0.0 0.0) 1e-8) (equal (abs (apply '+ (mapcar '* (unit der) (cdr (assoc 210 (entget ent)))))) 1.0 1e-8))
                    (setq lst (cons (vlax-curve-getpointatparam ent par) lst))
                    (if
                        (setq di1 (vlax-curve-getdistatparam ent par)
                              di2 (vlax-curve-getdistatparam ent (1+ par))
                        )
                        (progn
                            (setq inc (/ (- di2 di1) n))
                            (while (< di1 di2)
                                (setq lst (cons (vlax-curve-getpointatdist ent di1) lst)
                                      di1 (+ di1 inc)
                                )
                            )
                            (if (equal (vlax-curve-getpointatdist ent di1) (vlax-curve-getendpoint ent) 1e-8)
                                (setq lst (cons (vlax-curve-getendpoint ent) lst))
                            )
                        )
                    )
                )
            )
            (setq par (1+ par))
        )
        (reverse lst)
    )

    (while
        (progn (setvar 'ERRNO 0) (setq en (car (entsel "\nSelect LWPolyline: ")))
            (cond
                (   (= 7 (getvar 'ERRNO))
                    (princ "\nMissed, try again.")
                )
                (   (eq 'ENAME (type en))
                    (if (not (eq "LWPOLYLINE" (cdr (assoc 0 (entget en)))))
                        (princ "\nInvalid Object Selected.")
                    )
                )
            )
        )
    )
    (initget 6)
    (setq n (getint "\nInput number of curved segments per arc <25> : "))
    (if (null n) (setq n 25))
    (if
        (and en
            (setq lst
                (mapcar
                    (function (lambda ( x ) (trans x 0 en)))
                    (LM:LWPoly->List en n)
                )
            )
        )
        (entmakex
            (append
                (list
                    (cons 0 "LWPOLYLINE")
                    (cons 100 "AcDbEntity")
                    (cons 100 "AcDbPolyline")
                    (cons 62 3)
                    (cons 90 (length lst))
                    (assoc 70 (entget en))
                    (assoc 38 (entget en))
                    (assoc 210 (entget en))
                )
                (mapcar '(lambda ( x ) (cons 10 x)) lst)
            )
        )
    )

(command "_erase" en "")
    (princ)
)


Regards and apologies again.

nekonihonjin

  • Newt
  • Posts: 103
Re: arc-to-line-segments duplicated vertices bug help to fix
« Reply #11 on: October 21, 2022, 04:21:53 PM »
I'm using the         SegmentCurveV1-1.lsp       
Lee Mac routine that I mentioned above, on the left polyline, getting as result the one on the right.

I get that. but you can't segment the arc only if you pick a polyline with that command. I must be missing something.

Sorry Mhupp, I mistakenly took someone else's lisp as Lee Mac's, but help is still needed with the code I just posted