python如何画svg路径_Python中得到.svg文件矢量路径的坐标

So for a school project Iam supposed to program a so called "V-Plotter", my team built it and I managed to program all calculations and so on, basicly I can make it move to a certain x/y coordinate and lift/raise the pen. I converted an Image with potrace to an .svg file and as far as I understood it, the file should contain a certain path which the plotter would follow.

My idea here would be to read the vector path and save it in multiple vectors via an Array, then simply make an loop going through those arrays and thus drawing the vectors.

Or simply said:

Loop variable i=0

Loop:

pen up

move to (x1/y1) of Array i

pen down

move to (x2/y2) of Array i

increase i by 1

(this is not program code, but easy to program)

But i can not find any way to read the vector coordinates, shouldn't it be easy to get the coordinates where a vector starts (x1/y1) and where it stops (x2/y2)?

解决方案

SVGs are very simple formats, you could simply open it with a notepad and see the xml code for it. The xml tag is the type of curve you need to plot, and it can have some metadata inside it. You can directly use python to read this XML if you want.

But SVGs aren't as easy as you're assuming it to be - it isn't simply a bunch of vectors (not the classical vectors anyway)

In SVG, you basically define shapes - like Line, Arc, CubicBezier, etc. You'd need to implement each of these into your program, because something that shows an SVG image is expected to understand these already.

Now, as your question asked about the packages, I'm adding packages that are useful for SVG handling in python:

svg.path - https://pypi.python.org/pypi/svg.path - is a great library to create paths and also to get the XML info and convert into usable classes like Line, Arc etc. But I dont think they have support to read complete svg files.

pysvg - https://pypi.python.org/pypi/pysvg/0.2.2 - is another utilitiy i used a while back which can import an svg and make classes like PolyLine circle ellipse etc.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值