discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Sampling positions in an imported .SVG?

A
amundsen
Wed, Jun 17, 2020 7:52 PM

Hello,

Say we import an .SVG file containing a single curved line.

Is there some way to get a y position for any x?

The idea is to use a .svg as a kind of path to position shapes and solids.

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

Hello, Say we import an .SVG file containing a single curved line. Is there some way to get a y position for any x? The idea is to use a .svg as a kind of path to position shapes and solids. -- Sent from: http://forum.openscad.org/
RW
Ron Wheeler
Wed, Jun 17, 2020 9:03 PM

How is the curve defined in the svg?

If it is a path of points, you can look for the X value and get the Y or
find the 2 points between which your target X lies and then do a simple
interpolation.
This means parsing the svg but if it is simple enough, it should not be
too hard. If you want to do a better interpolation then I thnk that you
are into creating a Bezier with more points and figuring how to apply
your X to the formula.

If it is some other definition of a curve likeĀ  circle, you can get the
center and radius and calculate the 2 possible Ys

Interesting problem. You might want to explain a bit more about the
application to see if anyone has already solved the larger problem.

Ron

On 2020-06-17 3:52 p.m., amundsen wrote:

Hello,

Say we import an .SVG file containing a single curved line.

Is there some way to get a y position for any x?

The idea is to use a .svg as a kind of path to position shapes and solids.

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


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
Ron Wheeler
Artifact Software
438-345-3369
rwheeler@artifact-software.com

How is the curve defined in the svg? If it is a path of points, you can look for the X value and get the Y or find the 2 points between which your target X lies and then do a simple interpolation. This means parsing the svg but if it is simple enough, it should not be too hard. If you want to do a better interpolation then I thnk that you are into creating a Bezier with more points and figuring how to apply your X to the formula. If it is some other definition of a curve likeĀ  circle, you can get the center and radius and calculate the 2 possible Ys Interesting problem. You might want to explain a bit more about the application to see if anyone has already solved the larger problem. Ron On 2020-06-17 3:52 p.m., amundsen wrote: > Hello, > > Say we import an .SVG file containing a single curved line. > > Is there some way to get a y position for any x? > > The idea is to use a .svg as a kind of path to position shapes and solids. > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Ron Wheeler Artifact Software 438-345-3369 rwheeler@artifact-software.com
AC
A. Craig West
Wed, Jun 17, 2020 9:11 PM

Only way I know to do this is to parse the file yourself, except I don't
think openscad has a read function

On Wed, 17 Jun 2020, 17:03 Ron Wheeler via Discuss, <
discuss@lists.openscad.org> wrote:

How is the curve defined in the svg?

If it is a path of points, you can look for the X value and get the Y or
find the 2 points between which your target X lies and then do a simple
interpolation.
This means parsing the svg but if it is simple enough, it should not be
too hard. If you want to do a better interpolation then I thnk that you are
into creating a Bezier with more points and figuring how to apply your X to
the formula.

If it is some other definition of a curve like  circle, you can get the
center and radius and calculate the 2 possible Ys

Interesting problem. You might want to explain a bit more about the
application to see if anyone has already solved the larger problem.

Ron

On 2020-06-17 3:52 p.m., amundsen wrote:

Hello,

Say we import an .SVG file containing a single curved line.

Is there some way to get a y position for any x?

The idea is to use a .svg as a kind of path to position shapes and solids.

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


OpenSCAD mailing listDiscuss@lists.openscad.orghttp://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
Ron Wheeler
Artifact Software
438-345-3369rwheeler@artifact-software.com


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Only way I know to do this is to parse the file yourself, except I don't think openscad has a read function On Wed, 17 Jun 2020, 17:03 Ron Wheeler via Discuss, < discuss@lists.openscad.org> wrote: > How is the curve defined in the svg? > > If it is a path of points, you can look for the X value and get the Y or > find the 2 points between which your target X lies and then do a simple > interpolation. > This means parsing the svg but if it is simple enough, it should not be > too hard. If you want to do a better interpolation then I thnk that you are > into creating a Bezier with more points and figuring how to apply your X to > the formula. > > If it is some other definition of a curve like circle, you can get the > center and radius and calculate the 2 possible Ys > > Interesting problem. You might want to explain a bit more about the > application to see if anyone has already solved the larger problem. > > Ron > > On 2020-06-17 3:52 p.m., amundsen wrote: > > Hello, > > Say we import an .SVG file containing a single curved line. > > Is there some way to get a y position for any x? > > The idea is to use a .svg as a kind of path to position shapes and solids. > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing listDiscuss@lists.openscad.orghttp://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > > > -- > Ron Wheeler > Artifact Software > 438-345-3369rwheeler@artifact-software.com > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
A
amundsen
Wed, Jun 17, 2020 9:33 PM

Currently it's just a theoretical question but the idea is to draw a curve in
Inkscape and save it into a .svg file then use this curve to position
objects. However in between I've seen there's a library with splines, maybe
it might be a better function. Still parsing some data from an svg might be
of some interest.

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

Currently it's just a theoretical question but the idea is to draw a curve in Inkscape and save it into a .svg file then use this curve to position objects. However in between I've seen there's a library with splines, maybe it might be a better function. Still parsing some data from an svg might be of some interest. -- Sent from: http://forum.openscad.org/
RW
Ron Wheeler
Wed, Jun 17, 2020 10:13 PM

Splines sounds a lot easier.
Have you looked at an Inkscape file to see how a simple curve is
represented?
I suspect that the way the curve is defined in Inkscape makes a
difference in how the SVG is structured.

SVG is XML so there are a lot of tools to help in parsing it.

As long as the curve has only direction along the X axis it might not be
too bad.

Ron

On 2020-06-17 5:33 p.m., amundsen wrote:

Currently it's just a theoretical question but the idea is to draw a curve in
Inkscape and save it into a .svg file then use this curve to position
objects. However in between I've seen there's a library with splines, maybe
it might be a better function. Still parsing some data from an svg might be
of some interest.

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


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

--
Ron Wheeler
Artifact Software
438-345-3369
rwheeler@artifact-software.com

Splines sounds a lot easier. Have you looked at an Inkscape file to see how a simple curve is represented? I suspect that the way the curve is defined in Inkscape makes a difference in how the SVG is structured. SVG is XML so there are a lot of tools to help in parsing it. As long as the curve has only direction along the X axis it might not be too bad. Ron On 2020-06-17 5:33 p.m., amundsen wrote: > Currently it's just a theoretical question but the idea is to draw a curve in > Inkscape and save it into a .svg file then use this curve to position > objects. However in between I've seen there's a library with splines, maybe > it might be a better function. Still parsing some data from an svg might be > of some interest. > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Ron Wheeler Artifact Software 438-345-3369 rwheeler@artifact-software.com