discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Importing SVG : origin of coordinate system

Z
zipang@tethys.re
Sat, Jun 11, 2022 7:02 PM

Hello,

I am currently struggling to understand the logic of object location from imported svg files.

So I draw with Inkscape an A4 (210×297mm) rectangle on an A4 document, with an A4 viewport. For the SVG file, the top left angle is at 0,0.

When imported with import(“A4.svg“), OpenScad uses pixel units as is, and millimeters from the svg file are converted to pixels at 96 dpi. So it draws a rectangle of 793.7×1122.5. But it puts the top left angle at coordinates 0,396.

I don’t understand where this y=396 come from. I should expect that the top left corner be at 0,0 or 0,1122.5. It is a real issue when you need to translate imported object to accurate locations.

Do you have any explanation of this ? I’ve read the two similar previous posts but they didn’t help.

Hello, I am currently struggling to understand the logic of object location from imported svg files. So I draw with Inkscape an A4 (210×297mm) rectangle on an A4 document, with an A4 viewport. For the SVG file, the top left angle is at 0,0. When imported with import(“A4.svg“), OpenScad uses pixel units as is, and millimeters from the svg file are converted to pixels at 96 dpi. So it draws a rectangle of 793.7×1122.5. But it puts the top left angle at coordinates 0,396. ![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeoAAAKUCAIAAABEz+xBAAAAA3NCSVQICAjb4U/gAAAMZklEQVR4nO3dwXHbyBZAUeMXs+DOeSiPydCKw4qFceAvVMVZaIamYTQbF3POioVFq60qX0LNR3JZ19s3ft+yXP3qgIn+N3sDAGwh3wBJ8g2QJN8ASfINkCTfAEnyDZAk3wBJl9kbOKFluQ5d39uFgG/yPYK8Ai/g8AQgSb4BkuQbIEm+AZLkGyBJvgGS5Bsg6bRz36PfOzP35xotB06b79GBe5DpiT8a+O9weAKQJN8ASfINkCTfAEnyDZAk3wBJ8g2QJN8ASfINkCTfAEnyDZAk3wBJ8g2QJN8ASaf9wNiJfKAr8ALyvTNfpAC8hsMTgCT5BkiSb4Ak+QZIkm+AJPkGSDI4uLPXDH0bTwTke3+j2+ptQcA3hycAUfINkHTawxMnDMC5nTbfDqCBc3N4ApAk3wBJ8g2Q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XD8frOtt3ysAE50/319ru9cVgIkcngAkyTdAknwDJMk3QJJ8AyTJN0DSYh5um2W5+tUBE7n7BkiSb4AkhycASe6+AZLkGyBJvje6fwAhwBTyDZAk3wBJJk8Aktx9AyTJN0CSfG9k8gSYS74BkuQbIMnkCUCSu2+AJPkGSJLvjUyeAHPJN0CSfAMknXzy5H7Ecf9n7nUFYK6T5xvgrByeACTJ90YmT4C55BsgSb4Bkrx0CZDk7hsgSb4BkuR7I5MnwFzyDZAk3wBJJk8Aktx9AyTJN0CSfG9k8gSYS74BkuQbIMnkCUCSu2+AJPkGSJLvjUyeAHPJN0CSfAMkmTwBSHL3DZAk3wBJ8r2RyRNgrsvsDQx37+z9lH+vKwATeelyo2W5+tUBE8k3QJKzb4Ak+QZIku+NTJ4Ac8k3QJJ8AySZPAFIcvcNkCTfAEnyvZHJE2Au+QZIkm+AJJMnAEnuvgGS5BsgSb43MnkCzCXfAEnyDZBk8gQgyd33gThPB54n3wBJ8r2RO2VgLvkGSJJvgCT53sjEDjCXfAMkXab81M/X/e43sPeXAUNXAObytp2NluW6+69uxJrAWTk8AUiSb4Ak+d7IKQcwl3wDJMk3QJJ8b+QzT4C55BsgSb4PxMuhwPO8bQcgyd03QJJ8AyTJ90YmT4C55BsgSb4BkkyeACT9HxaWVj1hxqfUAAAAAElFTkSuQmCC) I don’t understand where this y=396 come from. I should expect that the top left corner be at 0,0 or 0,1122.5. It is a real issue when you need to translate imported object to accurate locations. Do you have any explanation of this ? I’ve read the two similar previous posts but they didn’t help.
RW
Raymond West
Sun, Jun 12, 2022 8:00 AM

not sure if it is an answer, but yesterday I created a dxf in openscad.
When I opened it in my cnc program, it was not correct, much of it
missing. I found that I had to have the drawing to top right of origin
before saving it as dxf. Perhaps your svg should have the origin at
bottom left.

On 11/06/2022 20:02, zipang@tethys.re wrote:

Hello,

I am currently struggling to understand the logic of object location
from imported svg files.

So I draw with Inkscape an A4 (210×297mm) rectangle on an A4 document,
with an A4 viewport. For the SVG file, the top left angle is at 0,0.

When imported with import(“A4.svg“), OpenScad uses pixel units as is,
and millimeters from the svg file are converted to pixels at 96 dpi.
So it draws a rectangle of 793.7×1122.5. But it puts the top left
angle at coordinates 0,396.

I don’t understand where this y=396 come from. I should expect that
the top left corner be at 0,0 or 0,1122.5. It is a real issue when you
need to translate imported object to accurate locations.

Do you have any explanation of this ? I’ve read the two similar
previous posts but they didn’t help.


OpenSCAD mailing list
To unsubscribe send an email todiscuss-leave@lists.openscad.org

not sure if it is an answer, but yesterday I created a dxf in openscad. When I opened it in my cnc program, it was not correct, much of it missing. I found that I had to have the drawing to top right of origin before saving it as dxf. Perhaps your svg should have the origin at bottom left. On 11/06/2022 20:02, zipang@tethys.re wrote: > > Hello, > > I am currently struggling to understand the logic of object location > from imported svg files. > > So I draw with Inkscape an A4 (210×297mm) rectangle on an A4 document, > with an A4 viewport. For the SVG file, the top left angle is at 0,0. > > When imported with import(“A4.svg“), OpenScad uses pixel units as is, > and millimeters from the svg file are converted to pixels at 96 dpi. > So it draws a rectangle of 793.7×1122.5. But it puts the top left > angle at coordinates 0,396. > > > I don’t understand where this y=396 come from. I should expect that > the top left corner be at 0,0 or 0,1122.5. It is a real issue when you > need to translate imported object to accurate locations. > > Do you have any explanation of this ? I’ve read the two similar > previous posts but they didn’t help. > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email todiscuss-leave@lists.openscad.org
AR
Algot Runeman
Mon, Jun 13, 2022 3:33 PM

On 6/11/22 15:02, zipang@tethys.re wrote:

Hello,

I am currently struggling to understand the logic of object location
from imported svg files.

So I draw with Inkscape an A4 (210×297mm) rectangle on an A4 document,
with an A4 viewport. For the SVG file, the top left angle is at 0,0.

When imported with import(“A4.svg“), OpenScad uses pixel units as is,
and millimeters from the svg file are converted to pixels at 96 dpi.
So it draws a rectangle of 793.7×1122.5. But it puts the top left
angle at coordinates 0,396.

I don’t understand where this y=396 come from. I should expect that the
top left corner be at 0,0 or 0,1122.5. It is a real issue when you need
to translate imported object to accurate locations.

Do you have any explanation of this ? I’ve read the two similar
previous posts but they didn’t help.

I  cannot specifically answer your 396 unit offset question.

As I understand it, Inkscape places its 0,0 point at the top-left corner
of it's current page size.

Openscad 0,0 is at the bottom-left corner, relative to Inkscape's
current page size. I hope the following illustrations will help.

(I used Inkscape version 1.1.1 for these examples and the following
OpenSCAD code: import ("square.svg", convexity=2);]

If I make an Inkscape page 50.8 mm tall and put a 96px square (path) at
its top, like the next image, it will import to OpenSCAD like the second
image. It is 20.4 units up from the x/y origin. 96 px works out to 1
inch or 25.4 mm y offset from OpenSCAD's origin.

Note that the OpenSCAD rendered square is 25.4 units (mm) above the 0,0
OpenSCAD origin.

If, however, I move the square (carefully down to place it at the bottom
of the page, the OpenSCAD imported square will render at 0.0.

My typical "solution" is to create my desired shape in Inkscape. Then
use Document Properties to set the page size to just include the object
which will then place it so the left-lower corner of the object is at
0.0 in OpenSCAD.

If I want to have the object centered at the origin for easier
manipulation, place the shape to be centered on the lower left corner of
that page in Inkscape. The Inkscape page size really does not matter.
The imported OpenSCAD shape will render at x=0, y=0, z=0. From there, it
is relatively easy to use translate, rotate, etc. to position it (still
needing to use linear_extrude() to get a 3D representation.

On 6/11/22 15:02, zipang@tethys.re wrote: > > Hello, > > I am currently struggling to understand the logic of object location > from imported svg files. > > So I draw with Inkscape an A4 (210×297mm) rectangle on an A4 document, > with an A4 viewport. For the SVG file, the top left angle is at 0,0. > > When imported with import(“A4.svg“), OpenScad uses pixel units as is, > and millimeters from the svg file are converted to pixels at 96 dpi. > So it draws a rectangle of 793.7×1122.5. But it puts the top left > angle at coordinates 0,396. > I don’t understand where this y=396 come from. I should expect that the top left corner be at 0,0 or 0,1122.5. It is a real issue when you need to translate imported object to accurate locations. > > Do you have any explanation of this ? I’ve read the two similar > previous posts but they didn’t help. > I  cannot specifically answer your 396 unit offset question. As I understand it, Inkscape places its 0,0 point at the top-left corner of it's current page size. Openscad 0,0 is at the bottom-left corner, relative to Inkscape's current page size. I hope the following illustrations will help. (I used Inkscape version 1.1.1 for these examples and the following OpenSCAD code: import ("square.svg", convexity=2);] If I make an Inkscape page 50.8 mm tall and put a 96px square (path) at its top, like the next image, it will import to OpenSCAD like the second image. It is 20.4 units up from the x/y origin. 96 px works out to 1 inch or 25.4 mm y offset from OpenSCAD's origin. Note that the OpenSCAD rendered square is 25.4 units (mm) above the 0,0 OpenSCAD origin. If, however, I move the square (carefully down to place it at the bottom of the page, the OpenSCAD imported square will render at 0.0. My typical "solution" is to create my desired shape in Inkscape. Then use Document Properties to set the page size to just include the object which will then place it so the left-lower corner of the object is at 0.0 in OpenSCAD. If I want to have the object centered at the origin for easier manipulation, place the shape to be centered on the lower left corner of that page in Inkscape. The Inkscape page size really does not matter. The imported OpenSCAD shape will render at x=0, y=0, z=0. From there, it is relatively easy to use translate, rotate, etc. to position it (still needing to use linear_extrude() to get a 3D representation.
L
larry
Mon, Jun 13, 2022 5:09 PM

On Sat, 2022-06-11 at 19:02 +0000, zipang@tethys.re wrote:

Hello,

I am currently struggling to understand the logic of object location
from imported svg files.

So I draw with Inkscape an A4 (210×297mm) rectangle on an A4
document, with an A4 viewport. For the SVG file, the top left angle
is at 0,0.

When imported with import(“A4.svg“), OpenScad uses pixel units as is,
and millimeters from the svg file are converted to pixels at 96 dpi.
So it draws a rectangle of 793.7×1122.5. But it puts the top left
angle at coordinates 0,396.

When using Inkscape, you have to pay attention to the Document
properties.

Go to File->Document Properties->Page.

There you will find, under 'Custom size', Units. I suspect you will
find that it's currently pixels. Set it to mm.

Then, under Scale, click on the + beside Viewbox.
Set it to 0.00 for both x and y.

Save your svg again, and import to OpenSCAD.

I am using Inkscape V 0.92

I don’t understand where this y=396 come from. I should expect that
the top left corner be at 0,0 or 0,1122.5. It is a real issue when
you need to translate imported object to accurate locations.

Do you have any explanation of this ? I’ve read the two similar
previous posts but they didn’t help.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

On Sat, 2022-06-11 at 19:02 +0000, zipang@tethys.re wrote: > Hello, > > I am currently struggling to understand the logic of object location > from imported svg files. > > So I draw with Inkscape an A4 (210×297mm) rectangle on an A4 > document, with an A4 viewport. For the SVG file, the top left angle > is at 0,0. > > When imported with import(“A4.svg“), OpenScad uses pixel units as is, > and millimeters from the svg file are converted to pixels at 96 dpi. > So it draws a rectangle of 793.7×1122.5. But it puts the top left > angle at coordinates 0,396. When using Inkscape, you have to pay attention to the Document properties. Go to File->Document Properties->Page. There you will find, under 'Custom size', Units. I suspect you will find that it's currently pixels. Set it to mm. Then, under Scale, click on the + beside Viewbox. Set it to 0.00 for both x and y. Save your svg again, and import to OpenSCAD. I am using Inkscape V 0.92 > I don’t understand where this y=396 come from. I should expect that > the top left corner be at 0,0 or 0,1122.5. It is a real issue when > you need to translate imported object to accurate locations. > > Do you have any explanation of this ? I’ve read the two similar > previous posts but they didn’t help. > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
Z
zipang@tethys.re
Thu, Jun 16, 2022 3:12 AM

Hello,

My answer to discuss@lists.openscad.org seems to have vanished, so here it is again :

Thank you for your answers.

Algot I draw a square as you explained and got the same result as yours, which is the intended behavior.
So I opened my first svg file with a text editor and I noticed that :
- page size was declared in mm
- view box was not declared
- rectangle position and size was in pixel.

The mere fact to manually add a view box corrects the behavior and now the rectangle is correctly positioned at 0,0.

The OpenSCAD import is also correct without a view box if rectangle units are in millimeters.

I don't know why the view box wasn't there in the first place. May be, as suggested by Larry, the view box fields should at least be opened in Inkscape Document properties before to save the file.

Anyway, the case is solved, thanks !

Pierre

Hello, My answer to discuss@lists.openscad.org seems to have vanished, so here it is again : Thank you for your answers. \ \ Algot I draw a square as you explained and got the same result as yours, which is the intended behavior. \ So I opened my first svg file with a text editor and I noticed that : \ \- page size was declared in mm \ \- view box was not declared \ \- rectangle position and size was in pixel. \ \ The mere fact to manually add a view box corrects the behavior and now the rectangle is correctly positioned at 0,0. \ \ The OpenSCAD import is also correct without a view box if rectangle units are in millimeters. \ \ I don't know why the view box wasn't there in the first place. May be, as suggested by Larry, the view box fields should at least be opened in Inkscape Document properties before to save the file. \ \ Anyway, the case is solved, thanks ! \ \ Pierre