1

Building svg file using svgwrite-1.1.9 using polyline entities.

How can I prevent flipped output? It seems the coordinates are messed up - vertical (y) is flipped.

Here's the code I'm using to generate the polyline:

# generate svg element

line = dwg.add(dwg.polyline(
   pairs,
   stroke='black', fill='blue'))

Pairs is a list of tuples in cartesian coordinates (X Y pairs):

[(2228.427, 1643.919), (2419.889, 1643.919), (2419.889, 1814.927), (2431.918, 1985.935), (2216.397, 1985.935), (2228.427, 1814.927), (2228.427, 1643.919)]

I'm using InkScape to visualize the svg output, and an in-house editor to visualize an alternate data stream; the in-house version is the correct version. I'm missing one entity.

The right entity block is rotated (in source), the left one is not (but is flipped). You can see in the svg that the entire right block is also flipped vertically, so it's above where it should be.

I haven't set any user viewport/coordinates in the SVG.

I'm pretty sure XY are the same (SVG, other).

enter image description here

enter image description here

martineau
  • 119,623
  • 25
  • 170
  • 301
shawn
  • 549
  • 1
  • 5
  • 11
  • 1
    It's because the [default coordinate system](https://www.w3.org/TR/SVG/coords.html#InitialCoordinateSystem) in svg files is oriented with the positive y-axis pointing down, which is the opposite of how many of us learned in school in math. Many computer devices use this sort of upside-down system. You can "fix" it in this case by establishing a user coordinate system that flips or mirrors the y values to the other side of the x-axis. This transformation would involve scaling all y values by -1 and then translating (adding) the amount you want the x-axis to move to compensate. – martineau Jan 27 '17 at 19:30
  • Indeed, I only needed to invert the Y coordinate in order to correct it. Many thanks for your insight! – shawn Jan 31 '17 at 15:31

1 Answers1

1

Difference between SVG and data coordinate systems is the correct answer, I can't flag Martineau as correct (not enough rep?)enter image description here, but this lets me post an updated graphic.

shawn
  • 549
  • 1
  • 5
  • 11