Author Topic: converting spline to polylines  (Read 15146 times)

0 Members and 1 Guest are viewing this topic.

sinc

  • Guest
converting spline to polylines
« Reply #15 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!

sinc

  • Guest
converting spline to polylines
« Reply #16 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...)

SMadsen

  • Guest
converting spline to polylines
« Reply #17 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).

SMadsen

  • Guest
converting spline to polylines
« Reply #18 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.

daron

  • Guest
converting spline to polylines
« Reply #19 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.

sinc

  • Guest
converting spline to polylines
« Reply #20 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.

daron

  • Guest
converting spline to polylines
« Reply #21 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.

sinc

  • Guest
converting spline to polylines
« Reply #22 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...

daron

  • Guest
converting spline to polylines
« Reply #23 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.