Last active
December 24, 2017 16:48
-
-
Save mo10/bb7e7270fc9c3f163e914a9d6a34341f to your computer and use it in GitHub Desktop.
SVG Path To Polyline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pathToPolygon(obj) { | |
var mypath = obj; | |
var pathLength = mypath.getTotalLength(); | |
var pathWidth = parseFloat(obj.style.strokeWidth); | |
var polygonPoints= []; | |
var out=""; | |
for (var i=0; i<pathLength; i++) { | |
var p = mypath.getPointAtLength(i); | |
polygonPoints.push(p.x); | |
polygonPoints.push(p.y); | |
out=out+"\""+i+"\",\""+Math.abs(p.x.toFixed(3))+"\",\""+Math.abs(p.y.toFixed(3))+"\",\",\"\n"; | |
} | |
console.log(out); | |
var mypolygon = document.getElementById("mypolygon"); | |
mypolygon.setAttribute("points", polygonPoints.join(",")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
在SVG包含path的标签内添加 ,用处是描路径
pathToPolygon(obj) 传入Path对象,控制台会输出CSV格式的Path的坐标信息,复制下来保存成xxx.csv文件
打开AD,随便画一个“实心区域(Region)”,打开属性对话框,”外框顶点“栏,点”菜单“,再点"从CSV文件导入",选择刚才保存的csv文件就行了
注意 如果路径包含封闭的洞/封闭的空心,请使用Inkscape打断区域
具体如何编辑出一个可以被导入的SVG请参考:https://learn.sparkfun.com/tutorials/importing-custom-images-into-eagle/method-1-svg-to-polygon