SVG import curves issue

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

SVG import curves issue

amundsen
Hello,

I import .SVG files from Inkscape but the curves appear to be split into
straight lines. It doesn't seem to be an export issue in Inkscape because if
I reopen the files in Inkscape the curves are displayed as such.

How can I avoid this?

Thank you in advance.
<http://forum.openscad.org/file/t2715/SVG_issue.jpg>



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import curves issue

doug.moen
On Sun, Sep 6, 2020, at 6:28 AM, amundsen wrote:
> I import .SVG files from Inkscape but the curves appear to be split into
> straight lines. It doesn't seem to be an export issue in Inkscape because if
> I reopen the files in Inkscape the curves are displayed as such.
>
> How can I avoid this?

Fundamentally, you can't avoid this, it is how OpenSCAD works. Internally, OpenSCAD represents curved 2D shapes as polygons.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import curves issue

rickan
In reply to this post by amundsen
I have drawn curves in PostScript and used the /setflat/, /flattenpath/,
/pathforall/, and /print/ operators to output polygons of the accuracy I
want for OpenSCAD using GhostScript (gs). It's a crude solution, but I've
also done it with two levels of accuracy so I can use a parameter to choose
one for viewing (less accuraste) and the other for rendering (more
accurate). The procedures given to /pathforall/ do the string composition
(using the /cvs/ operator) and printing producing output which can be
included  directly in the OpenSCAD file.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import curves issue

amundsen
In reply to this post by doug.moen
I undestand that but how can I increase the resolution? Should I make my
drawings bigger in Inkscape and then scale them down after import in
OpenSCAD? The picture displayed is an arc with a length of approximately
3cm.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
tp3
Reply | Threaded
Open this post in threaded view
|

Re: SVG import curves issue

tp3
On 06.09.20 15:28, amundsen wrote:
> I undestand that but how can I increase the resolution?

The proper way would be by using $fa/$fs/$fn but I think
that's not fully implemented at this point. So what might
always work is converting path to straight line segments
in Inkscape. In this case the segment resolution can be
specified in the "flatten curves" operation.

ciao,
  Torsten.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten
Reply | Threaded
Open this post in threaded view
|

Re: SVG import curves issue

amundsen
> So what might always work is converting path to straight line segments
in Inkscape.

I see. I'll try that. Thanks Torsten.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import curves issue

rickan
In reply to this post by amundsen
It seems that Inkscape will save files as Postscript (*.ps) and it looks like
it would be pretty straightforward to edit that file to flatten and output
the path to whatever accuracy you wish.

/prpoint{
  exch ([)print 20 string cvs print (, )print 20 string cvs print(],\n)print
}def

% Construct path here but do not stroke it that will be done after printing
it out.

gsave
  .2 setflat
  flattenpath
  {prpoint}{prpoint}{}{}pathforall
grestore
stroke

It seems that Inkscape redefines stroke to S, i.e. /S { stroke } bind def



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import curves issue

OpenSCAD mailing list-2
In reply to this post by amundsen
In the process of exploring this issue, I discovered that 0.92 Inkscape has a
pre-loaded extension:
Extensions, Modify Path, Flatten Beziers
Doing so provides for a dialog box of resolution, which defaulted to 0.1 in
my test. That's a relatively high resolution if that's what's desired.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import curves issue

rickan
In reply to this post by rickan
And if there are many strokes in the output you could modify

/S { stroke } bind def

thusly

/S {
  gsave
    .2 setflat
    flattenpath
    {prpoint}{prpoint}{}{}pathforall
  grestore
  stroke
} bind def



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: SVG import curves issue

amundsen
In reply to this post by OpenSCAD mailing list-2
I've just tried the Flatten Bezier option from Inkscape but the length of the
segments resulting from the operation depend on the size of the curve. For
instance, with my original file I could only divide the curve into 8
segments using the lowest possible value (0.1). However by scaling the
drawing 10,000% prior to the flattening, I got a lot more segments for the
same curve. I can then scale back the drawing to its original size.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org