TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: DEVITG on July 12, 2004, 09:20:37 AM

Title: converting spline to polylines
Post by: DEVITG on July 12, 2004, 09:20:37 AM
Hi all gurus , please I need to convert this all spline to Polylines.

the original file is acad 2000 , I have acad 2002

The lisp shall be to be used on acad 2000.


Thanks in advance.



http://theswamp.org/lilly.pond/devitg/spline-to%20poly.dwg
Title: converting spline to polylines
Post by: CAB on July 12, 2004, 10:16:38 AM
Here are two choices.
<untested>

Code: [Select]
(defun c:sptrace (/ ent spline cur pl end keep)
 (setq cur nil)
 (setq pl '((0 . "LWPOLYLINE")
     (100 . "AcDbEntity")
     (67 . 0)
     (8 . "0")
     (100 . "AcDbPolyline")
     (90 . 7)
     (70 . 0)
     (43 . 0.0)
     (38 . 0.0)
     (39 . 0.0)
    )
   )
 (setq end '(210 0.0 0.0 1.0));define polyline group codes
 (while (not (progn (princ "\rSelect Spline: ") ;select spline to convert
    (setq spline (ssget ":s" '((0 . "SPLINE"))))
     )
)
 )
 (initget "Yes No")
 (setq keep (getkword "Keep Original Spline [Yes/No]: "));keep original line or not
 (setq spline (ssname spline 0)); get ename
 (if (/= keep "No")
   (progn
     (entmake (entget spline));copy spline
     (setq spline (entlast));get ename of new spline
     )
   )
 (setq ent spline); copy ename to new variable
 (command "splinedit" ent "refine" "elevate" 26 "x" "x");add extra control points
 (setq ent (entget ent)); get data for spline
 (setq pl (subst (assoc 8 ent) (assoc 8 pl) pl)); set polylines layer to same as spline
 (if (= (rem (cdr (assoc 70 ent)) 2) 1);is spline closed
   (setq pl (subst (cons 70 1) (assoc 70 pl) pl));set polyline closed
   (setq pl (subst (cons 70 0) (assoc 70 pl) pl));set polyline open
 )
 (repeat (length ent);loop
   (progn
     (if (eq (car (car ent)) 10);get control point data
(setq cur (append cur (list (car ent))))
     )
     (setq ent (cdr ent));get next element in list
   )
 )
 (setq pl (subst (cons 90 (length cur)) (assoc 90 pl) pl));set number of points in polyline
 (repeat (length cur);loop
   (progn;add polyline point data
     (setq pl
    (append
      pl
      (list (car cur) (cons 40 0.0) (cons 41 0.0) (cons 42 0.0))
    )
     )
     (setq cur (cdr cur));get next element in list
   )
 )
 (setq pl (append pl (list end)));add normal vector to polyline data
 (entmake pl);make polyline
 (entdel (cdr (assoc -1 (entget spline))));entdel spline, original or copy
 (princ);exit quietly
)




Code: [Select]
;Convert SPLINES to PLINES - Mauricio Ferman©2001
(defun c:spl2pl (/ splines plinetype osmode i spl ed codepair)
  (if
    (setq splines (ssget (list (cons 0 "spline"))))
     (progn
       (if
         (zerop (setq plinetype (getvar "plinetype")))
          (setvar "plinetype" 1)
       ) ;if
       (setq osmode (getvar "osmode"))
       (setvar "osmode" 0)
       (setq i 0)
       (while
         (setq spl (ssname splines i))
          (setq i  (1+ i)
                ed (entget spl)
          ) ;setq
          (command ".pline")
          (foreach
                    codepair
                            ed
            (if
              (= 10 (car codepair))
               (command (cdr codepair))
            ) ;if
          ) ;foreach
          (command "")
          (command ".pedit" "l" "s" "")
       ) ;while
       (if plinetype
         (setvar "plinetype" plinetype)
       )
       (setvar "osmode" osmode)
     ) ;progn
  ) ;if
  (princ)
) ;defun
Title: converting spline to polylines
Post by: Columbia on July 12, 2004, 10:18:57 AM
Try this snippet.  What it does is step through the given spline at a given tolerance distance and pull a point off of the curve.  It then adds that point to a running list.  The snippet returns that list of points that you could then use to build your polyline.

Have fun!!

Code: [Select]

(vl-load-com)

(defun Spline->Pline (oSpline tol / 1stPoint dist fullLength lastPoint plinePoints point)
  (setq 1stPoint (vlax-curve-getPointAtParam oSpline (vlax-curve-getStartParam oSpline))
        lastPoint (vlax-curve-getPointAtParam oSpline (vlax-curve-getEndParam oSpline))
        fullLength (vlax-curve-getdistatparam oSpline (vlax-curve-getendparam oSpline))
        dist 0
        plinePoints (list 1stPoint)
  )
  (while (< (setq dist (+ dist tol)) fullLength)    
    (if (setq point (vlax-curve-getPointAtDist oSpline dist))
      (setq plinePoints (append plinePoints (list point)))
    )
  )
  (setq plinePoints (append plinePoints (list lastpoint)))
;;; Use the variable plinePoints (which is a list of vertex points)
;;; and whatever method you like to use for adding a polyline
;;; to the drawing.
)
Title: spline to polyline
Post by: DEVITG on July 12, 2004, 08:20:56 PM
Hia CAB ,  thanks for your help

I did some changes , so the lisp would take all the splines and change one after one , erasing the splines, as follow.




Code: [Select]
;; TO CHANGE THE COLOR TO COLOR THE LAST OBJECT MADE

(DEFUN CHGC (COLOR)
  (COMMAND "._CHANGE" "L" "" "P" "C" COLOR "")
)
;;END CHANGE COLOR THE LAST



;;(defun c:sptrace (/ ent spline cur pl end keep) "to keep variable global while debug"
(defun c:sptrace ()
  (setq cur nil)
  (setq pl '((0 . "LWPOLYLINE")
    (100 . "AcDbEntity")
    (67 . 0)
    (8 . "0")
    (100 . "AcDbPolyline")
    (90 . 7)
    (70 . 0)
    (43 . 0.0)
    (38 . 0.0)
    (39 . 0.0)
   ) ;_end list
  ) ;_end setq pl
  (setq end '(210 0.0 0.0 1.0))  ;define polyline group codes
  (setq spline# (ssget "x" '((0 . "SPLINE")))) ;_ I change it just to check after a run
  (setq pl-leng (sslength spline#))
  (setq ss# 0)
  (repeat pl-leng
;;;(setq spline (ssname spline# ss#))
;;;(print spline)
;;;(setq ss# (1+ ss#))
;;;)



    ;;(while (not (progn (princ "\rSelect Spline: ") ;select spline to convert
    ;;(while
    ;;sget ":s" '((0 . "SPLINE"))))
    ;;(setq spline entnext)

    ;;   );_PROGN
    ;;);_NOT
    ;;);_WHILE
    ;;(initget "Yes No")
    ;;(setq keep (getkword "Keep Original Spline [Yes/No]: "));keep original line or not
;;;(setq keep "No")
    (setq spline (ssname spline# ss#))  ; get ename
;;; (if (/= keep "No")
;;;   (progn
;;;     (entmake (entget spline));copy spline
;;;     (setq spline (entlast));get ename of new spline
;;;     );_end progn
;;;   );_end if  
    (setq ent spline)  ; copy ename to new variable
    (command "splinedit" ent "refine" "elevate" 26 "x" "x")
 ;add extra control points
    (setq ent (entget ent))  ; get data for spline
    (setq pl (subst (assoc 8 ent) (assoc 8 pl) pl))
 ; set polylines layer to same as spline
    (if (= (rem (cdr (assoc 70 ent)) 2) 1)  ;is spline closed
      (setq pl (subst (cons 70 1) (assoc 70 pl) pl))
 ;set polyline closed
      (setq pl (subst (cons 70 0) (assoc 70 pl) pl))
 ;set polyline open
    )
    (repeat (length ent)  ;loop
      (progn
(if (eq (car (car ent)) 10)  ;get control point data
 (setq cur (append cur (list (car ent))))
)
(setq ent (cdr ent))  ;get next element in list
      )
    )
    (setq pl (subst (cons 90 (length cur)) (assoc 90 pl) pl))
 ;set number of points in polyline
    (repeat (length cur)  ;loop
      (progn  ;add polyline point data
(setq pl
      (append
pl
(list (car cur) (cons 40 0.0) (cons 41 0.0) (cons 42 0.0))
      )
)
(setq cur (cdr cur))  ;get next element in list
      )
    )
    (setq pl (append pl (list end)))  ;add normal vector to polyline data
    (entmake pl)  ;make polyline
    (CHGC 1);_to change  color
    (entdel (cdr (assoc -1 (entget spline))))  ;entdel spline, original or copy
    (princ)  ;exit quietly
    (setq ss# (1+ ss#))


  ) ;_repeat
) ;_end defun

(c:sptrace) ;_to run it from vlide
;|«Visual LISP© Format Options»
(72 2 50 2 nil "end of " 60 9 0 0 0 T T nil T)
;*** DO NOT add text below the comment! ***|;


But as you could see at this drawing , the polyline join both splines and change the profile.






http://theswamp.org/lilly.pond/devitg/after%20spline-to%20poly03.dwg




http://theswamp.org/lilly.pond/devitg/before%20spline-to%20poly03.dwg

http://theswamp.org/lilly.pond/devitg/before%20spline-to%20poly03.dwg
Title: converting spline to polylines
Post by: JohnK on July 12, 2004, 10:27:30 PM
Columbia, Thats cool.

BTW, Long time... Where ya been?
Title: converting spline to polylines
Post by: Columbia on July 13, 2004, 07:44:22 AM
I've been up to my eyeballs in work, so I haven't had a whole lot of time to peruse and kbitz here.  But things have lightened a little right now, therefore you see me!!  Although, I think it's just the calm before the storm.  But on a different note, I'm trying my best to learn VBA, and not be stuck as a one language guru.

But back to VLISP...  I took the snippet I added above and added to it so that it'll turn all SPLINES in a drawing to PLINES.

Code: [Select]

(vl-load-com)

(defun Spline->Pline (oSpline tol / 1stPoint dist fullLength lastPoint plinePoints point)
  (setq 1stPoint (vlax-curve-getPointAtParam oSpline (vlax-curve-getStartParam oSpline))
        lastPoint (vlax-curve-getPointAtParam oSpline (vlax-curve-getEndParam oSpline))
        fullLength (vlax-curve-getdistatparam oSpline (vlax-curve-getendparam oSpline))
        dist 0
        plinePoints (list 1stPoint)
  )
  (while (< (setq dist (+ dist tol)) fullLength)    
    (if (setq point (vlax-curve-getPointAtDist oSpline dist))
      (setq plinePoints (append plinePoints (list point)))
    )
  )
  (setq plinePoints (append plinePoints (list lastpoint)))
)

;; here comes the command line entry that will use
;; the above sub function.  This code has almost no error
;; checking.  Use error checking/handling as you see fit.
;; Also I have not debugged this code - hell, I haven't even
;; run it to see if it actually works!!  You'll just have to cut &
;; paste to see for yourself.

(defun c:spline2pline (/ ss i points point obj)
  (if (setq ss (ssget "X" (list (cons 0 "SPLINE"))))
    (progn
      (setq i 0)
      (repeat (sslength ss)
        (setq obj (vlax-ename->vla-object (ssname ss i))
             points (Spline->Pline obj)
        )
        (command "._pline")
        (foreach point points
          (command "_non" point)
        )
        (command "")
        (vla-delete obj)
      )
    )
  )
  (princ)
)
Title: converting spline to polylines
Post by: CAB on July 13, 2004, 08:59:25 AM
You beat me to it.
I included the change layer, but if the layer is frozen or locked
the routine crashes.
Code: [Select]
(defun c:spl2pl(/ usrlay usrosm usrplw ent pdist idx ss )
  (setq usrosm (getvar "osmode"))
  (setq usrplw (getvar "plinewid"))
  (setvar "plinewid" 0 )
  (setvar "osmode" 0 )
  (setq pdist 36) ; distance between points on new pline
  (if (setq ss (ssget "X" '((0 . "SPLINE")))); get all splines
    (progn
      (setq idx (sslength ss))
      (while (>= (setq idx (1- idx)) 0)
        (setq ent (ssname ss idx))
        (if (setq plist (Spline->Pline ent pdist))
          (progn
            (command "._pline" )
            (mapcar '(lambda (x) (command x)) plist)
            (command "")
            (command "._change" "_Last" "" "_P" "_LA" (cdr(assoc 8(entget ent)))"")
            (entdel ent)
          ) ; progn
        ); endif
      ) ; while
    ) ; progn
    (prompt "\nNo splines in drawing.")
  ) ;endif
  (setvar "osmode" usrosm)
  (setvar "plinewid" usrplw)
  (princ)
);defun
Title: converting spline to polylines
Post by: CAB on July 13, 2004, 09:14:46 AM
Ok, I think I overcame the layer pit fall & avoided the osmode catch
in my other version by using entmod.
Code: [Select]
(defun c:spl2pl(/ usrlay usrosm usrplw ent pdist idx ss pl plist pentlst)
  (setq pdist 36) ; distance between points on new pline
  (setq pentlst '((0 . "LWPOLYLINE")
     (100 . "AcDbEntity")
     (67 . 0)
     (8 . "0")
     (100 . "AcDbPolyline")
     (90 . 7)
     (70 . 0)
     (43 . 0.0)
     (38 . 0.0)
     (39 . 0.0)
    )
   )
  (setq end '(210 0.0 0.0 1.0));define polyline group codes
  (if (setq ss (ssget "X" '((0 . "SPLINE")))); get all splines
    (progn
      (setq idx (sslength ss))
      (while (>= (setq idx (1- idx)) 0)
        (setq ent (ssname ss idx)
              pl pentlst)
        (if (setq plist (Spline->Pline ent pdist))
          (progn
            (foreach x plist
              (setq pl (append pl
                        (list (cons 10 (list (car x)(cadr x)))
                              (cons 40 0.0)
                              (cons 41 0.0)
                              (cons 42 0.0))))
            )
            ;;set number of points in polyline
            (setq pl (append
                       (subst (cons 90 (length plist)) (assoc 90 pl) pl)
                       pl
                       (list end))
            )
            ;;  update layer
            (setq pl (subst (assoc 8 (entget ent)) (assoc 8 pl) pl))
            (entmake pl);make polyline
            (entdel ent)
          ) ; progn
        ); endif
      ) ; while
    ) ; progn
    (prompt "\nNo splines in drawing.")
  ) ;endif
  (princ)
);defun
Title: converting spline to polylines
Post by: daron on July 14, 2004, 09:19:49 AM
These are great routines guys. I have a greater challenge, if anybody's really up for it. The production guys say that they need plines to be in the arcs of the spline. In other words, true arc plines. I've muddled through the dxf content and have even studied the (entget (car (entsel))) of a spline. I feel it can be done, but it seems to be a great challenge. So, if anybody wants to attempt this and get it working, I'd say you're a better lisp programmer than most, including that guy, Tony Tanzillo. I got a spline2pline that he wrote, and it is similar in end product to Columbia's, but longer in lisp content.
Title: converting spline to polylines
Post by: Columbia on July 14, 2004, 09:27:50 AM
So you're saying you want arc segments to make up the pline instead of line segments?
Title: converting spline to polylines
Post by: SMadsen on July 14, 2004, 09:30:01 AM
Oh, just to see that on the screen, "you are better than Tanzillo", would be worth it - no matter the real truth, of course  :)

If you take Columbia's approach and dig a little into vlax-curve-getFirstDeriv then I'm sure you'll be able to pull it off yourself, Daron.
Title: converting spline to polylines
Post by: SMadsen on July 14, 2004, 10:06:54 AM
Apropos: Check out the last post here (http://forums.augi.com/showthread.php?t=5769). It's the best explanation of curve derivatives I've seen.
Title: converting spline to polylines
Post by: daron on July 14, 2004, 12:43:14 PM
Oh Stig, I want to and I was thinking those vlax-curves had to be the answer. I just haven't had a chance to do more than ponder the thought and try to figure out what makes a spline do what it does.
Title: converting spline to polylines
Post by: daron on July 14, 2004, 12:50:00 PM
Stig, I can't as yet get in there. I've changed email and don't remember my password. Would there be any way you'd be able to copy and paste it to the swamp?
Title: converting spline to polylines
Post by: SMadsen on July 14, 2004, 05:56:22 PM
With kind permission from Richard Sincovec:

"No, you can't use the second derivative on line segments. There's an explanation in linear algebra, and a possibly simpler one in topology once you reach the point where you can understand all the 3-ball and 2-sphere stuff, but the easiest explanation might be a sort of real-world analogy. AutoCAD works in 3-D, and most of us probably had our first real experience with derivatives in physics anyway, with stuff like v = xdt and so forth, so that approach might be the best.

Let's imagine a polyline as being the path a ball has travelled. As you remember from physics, a derivative is a rate of change. So, since we're assuming the polyline represents the position of the ball over time, the first derivative would be the velocity the ball is travelling at any particular instant in time. For straight segments, this velocity vector is in the same direction as the direction of travel. For curves, this is in a line tangent to the curve at that point. AutoCAD returns this direction vector, or first derivative, as simply a coordinate, the endpoint of a vector; the vector is assumed to start at (0,0,0). And, niftily enough, it looks like AutoCAD defined things so that the length of the vector is the length of the line for line segments, and the radius of the curve for arcs. (I wouldn't recommend using this function to get lengths or radii, though... It might have just turned out that way in the few items I checked in some poking around...)

Now, let's look at the second derivative. We remember from physics that this is acceleration, or how much the ball's velocity is changing. In other words, the second derivative is another directional vector, this one showing which way some invisible force would need to push the ball to make it travel along our polyline. And, again from our physics, this directional acceleration vector would be in the plane of the curve, and perpendicular to the direction of travel. In AutoCAD terms, the direction of this vector is perpendicular to the curve, toward its radius. And again, because of the way the math works, the length of the direction vector is equal to the radius of the curve.

However, with lines, the direction of travel is not changing. In physics terms, the lateral acceleration is 0. This implies the second derivative of a line segment must ALWAYS be 0, regardless of its direction. (Conversely, the second derivative of a curve must ALWAYS be non-zero.)"
Title: converting spline to polylines
Post by: sinc on July 14, 2004, 11:27:56 PM
Stig got me curious, so I thought I'd see what was up.

Sounds interesting.  I haven't ever thought about it - I mean really, why would you want to convert a spline to arcs, anyway? - but it does sound like you might be able to pull it off by stepping through the spline and finding the radius at each point by using the derivative.  I'm not sure how splines are set up - let me know what you find out.  I don't have time to explore it right now.  I have noticed that the params go on splines like they do on lines, not like on polylines, so you can't do something simple like draw arcs between the params.  Unless, of course, it turns out that that's what a spline IS, a series of 1-unit-long arcs...

It's always possible (even likely) that the spline is implemented as a spline at a REALLY low level, and it isn't made up a series of arcs at all (the way a spiral curve is in LDD - or is a spiral a series of splines? yet another thing to explore...).  In that case, all you can do is approximate the spiral with curves by picking points at regular intervals, and declaring those the endpoints of your arc segments.  You can use the derivative to figure the tangent bearing at each point, and then try drawing a curve using a tan-tan fit.  I don't know if this will work - it might be a null solution set.  In that case, you would have to have tiny angle points between each arc.  The easiest way to do this would be to use the derivative to get the radius at each endpoint, and use the average as the radius of the arc segment.  Of course, if using the derivative to find a radius ever breaks down, this is probably how you'll find out.

Here, the only problem is that having arcs of equal length is inefficient.  You need more arcs where the spline is changing the most.  It sounds like you actually also might want a thirdDerivative function.  Then you could make the length of the arc segments inversely proportional to the average magnitude of the third derivative over that segment.

Note that I'm happy to sit here and spout things, and let you do the actual coding... :wink:

Enjoy!
Title: converting spline to polylines
Post by: sinc on July 15, 2004, 01:29:57 AM
Oh, duh!  The easiest thing to do would be to make your spline a series of ellipses, not arcs.  These would tend to follow a spline-like path more closely.  And it would be easy to make elliptical segments that were tangent to each other - just extend the tangent line segments until they intersect, and you have the lengths of the major and minor axes.  Oh wait, no, that won't work, it's a bit more complicated... but you probaly get the idea.  A parabolic fit.  Yeah, that's what I meant.

You could still put together some sort of function that would vary the lengths of each elliptical segment, based on how fast the curvature is changing, but this might be overkill.  (Or maybe not... you might have to do this.  But there are a couple of easy ways of computing or approximating this, since AutoCAD doesn't provide a thirdDerivative function for you...)
Title: converting spline to polylines
Post by: SMadsen on July 15, 2004, 03:38:20 AM
Quote from: sinc
Note that I'm happy to sit here and spout things, and let you do the actual coding... :wink:

Me too. I mean, Daron'll do the coding, right Daron? :)

Welcome to theSwamp, Richard. I hope I spelled your name right.

Acad uses real quadratic and cubic B-splines. I once wrote a simple bicubic function and it turned out to be an exact match to the SPLINETYPE 6 spline (actually for a task like this but didn't have time to finish it). So the Acad splines are well-defined.
I was thinking in the line of an average of radii and directions to build approximated arc representations.

It would be neat to use ellipses or parables but then you'd be stuck with single objects or back to splines (respectively). As I'm sure you know, plines can only hold circular arc segments.

An alternate workaround could perhaps be to convert the spline to the pline representation of a spline and then curve-fit it afterwards (Acad must have algoritms already to do this).
Title: converting spline to polylines
Post by: SMadsen on July 15, 2004, 05:09:07 AM
By the way, just remembered that Express Tools have a function in flattensup.lsp, ACET-FLATN-SPLINE, that makes arced plines from splines.

Once loaded (along with acetutil2.fas, acetutil3.fas and acet-wmf.lsp) all you need to call is (acet-flatn-spline ent), where ent is ename of the spline.
Title: converting spline to polylines
Post by: daron on July 15, 2004, 08:44:48 AM
Well, this is my understanding on the reason for the need for arced plines ILO splines. CNC machines can't use splines and their operators don't like lineal arcs because the machine has to stop and turn at each end point, which dulls the blade. That's what I've been told. Personally, I think they should upgrade the software for the CNC machine to read splines and something other than the zero layer. Blows that standard out of the water doesn't it? Anyway, I had actually thought of both ideas, but am not as yet able to move forward with it. Here's the dxf elist for a spline:
Code: [Select]
(-1 . <Entity name: 40082e20>)
(0 . "SPLINE")
(330 . <Entity name: 40082cf8>)
(5 . "74")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "0")
(100 . "AcDbSpline")
(210 0.0 0.0 1.0)
(70 . 11)
(71 . 3)
(72 . 15)
(73 . 11)
(74 . 9)
(42 . 1.0e-010)
(43 . 1.0e-010)
(44 . 0.0)
(12 0.603201 0.797589 0.0)
(13 0.603201 0.797589 0.0)
(40 . 0.0)
(40 . 0.0)
(40 . 0.0)
(40 . 0.0)
(40 . 3.82187)
(40 . 9.87265)
(40 . 13.4863)
(40 . 24.5968)
(40 . 30.176)
(40 . 32.7095)
(40 . 35.2406)
(40 . 37.836)
(40 . 37.836)
(40 . 37.836)
(40 . 37.836)
(10 14.5666 4.4524 0.0)
(10 15.335 5.4685 0.0)
(10 19.1201 5.12275 0.0)
(10 24.9566 3.43487 0.0)
(10 25.0266 12.7803 0.0)
(10 14.651 10.7029 0.0)
(10 9.10365 7.86196 0.0)
(10 9.638 1.97157 0.0)
(10 11.8376 6.10819 0.0)
(10 14.0447 3.7624 0.0)
(10 14.5666 4.4524 0.0)
(11 14.5666 4.4524 0.0)
(11 18.3386 5.06745 0.0)
(11 24.3846 5.30812 0.0)
(11 24.5451 8.91818 0.0)
(11 13.4697 9.80064 0.0)
(11 9.52459 5.85551 0.0)
(11 9.93843 3.35602 0.0)
(11 11.9983 4.82678 0.0)
(11 14.5666 4.4524 0.0)

I know you guys know where to find the dxf definitions for a spline so I won't post it, but I do believe from that, what we've been talking about is possible, either from a bulge factor on the lineal polyline or a curve derivative. Not that I know that much about them. Until I try it, it's all information overload.

Stig, is that express tool in 2002? I've never needed it before, so I didn't know it was there. I'll have to go look at home.

Richard, thanks for the information and welcome to the swamp. It's not your bosses cad forum.
Title: converting spline to polylines
Post by: sinc on July 15, 2004, 01:03:20 PM
Heh, I forgot that the original goal was to convert it to a pline, which is why we were talking arc segments in the first place.

Except now I'm wondering if that's what you really want.  If I understand you correctly, you don't want to approximate the spline with line segments because it dulls the cutting tool when it hits the angle point between segments.  Is this correct?  If so, then you'll still have the same problem if you use arc segments, just to a reduced degree.

If I understand Stig correctly, then a spline is really kind of like a polyline that consists only of parabolic segments (parts of ellipses) instead of lines and arcs.  If so, then it seems like you really want to convert a spline to its component parabolic segments, not an arc-based polyline.  Then each segment will be tangent to the next, solving your dulling problem.  Unless you have some overriding need to have the result be a single polyline instead of a series of parabolic arcs (which you shouldn't, if you merely want to use it to control a machine), this might be the better solution.

I haven't had time to dig into it any more, or look at the routine Stig mentioned.  Maybe this weekend.  Now I'm kind of curious about exactly how all this is implemented in AutoCAD.
Title: converting spline to polylines
Post by: daron on July 15, 2004, 01:08:28 PM
I've personally never used the machine. All I know is that they want closed plines using arc segments with as few end points as possible. Your understanding sounds about right. I personally don't want to get into parabolicism if I don't have to. This project seems complicated enough in its own right with arcs.
Title: converting spline to polylines
Post by: sinc on July 15, 2004, 02:19:26 PM
I don't think it's any more complicated.  Think of it as using pieces of ellipses instead of pieces of circles.  The math is roughly equally complicated either way, although circles might be easier because they are used more often, and therefore tend to have more "convenience" functions available.  They won't fit as well, though - think about how many circular arcs of different radii it takes to create a single elliptical segment with any reasonable accuracy...

Sounds like the routine Stig mentioned is the quick solution to get them that closed polyline they asked for, though...
Title: converting spline to polylines
Post by: daron on July 16, 2004, 08:21:26 AM
Now I just need to find it. The problem with ellipses, if I remember correctly, is that they can't be joined as a pline, unless it's created as a pellipse. Here's some more depth on that: the splines would be coming from art pieces designed in illustrator or photoshop. If I can't convert their splines to plines, I have to trace the art by hand to form this closed arc pline. A pain? Yes!

I haven't had a chance to look into the express tools, yet. They don't have them where I work and we have a very controlling IT dept. At home, I can look, but that'll most likely have to wait until tomorrow.