0
此问题是Define a circle/arc animation in SVG和How to calculate the SVG Path for an arc (of a circle)的扩展。SVG:填充弧形动画?
我已经修改的@opsb答案如下:
function calculateArcPath(x, y, radius, spread, startAngle, endAngle){
var innerStart = polarToCartesian(x, y, radius, endAngle);
\t var innerEnd = polarToCartesian(x, y, radius, startAngle);
var outerStart = polarToCartesian(x, y, radius + spread, endAngle);
var outerEnd = polarToCartesian(x, y, radius + spread, startAngle);
var largeArcFlag = endAngle - startAngle <= 180 ? "0" : "1";
\t \t
var d = [
"M", outerStart.x, outerStart.y,
"A", radius + spread, radius + spread, 0, largeArcFlag, 0, outerEnd.x, outerEnd.y,
"L", innerEnd.x, innerEnd.y,
"A", radius, radius, 0, largeArcFlag, 1, innerStart.x, innerStart.y,
"L", outerStart.x, outerStart.y, "Z"
].join(" ");
return d;
}
function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
var angleInRadians = (angleInDegrees-90) * Math.PI/180.0;
return {
x: centerX + (radius * Math.cos(angleInRadians)),
y: centerY + (radius * Math.sin(angleInRadians))
};
}
var startPath = calculateArcPath(250, 250, 50, 30, 0, 30)
var endPath = calculateArcPath(250, 250, 50, 30, 0, 150)
d3.select("path").attr("d", startPath)
d3.select("path").transition().duration(2000).attr("d", endPath)
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<svg width="500" height="500" style="border:1px gray solid">
<path id="path" fill="blue" stroke="black"></path>
</svg>
但是,路径心不是绕了一圈的平稳过渡。
本来我是真的这样做....但是,如果使用厚的行程,让您的弧线,那么无论你有没有填充或者无法创建一个大纲(使用相同的SVG元素,尽管您总是可以制作另一个大纲)。使用不是通过粗大的笔划宽度的弧段是问题的症结所在,以及在S.O.中证明它的合理性。因为已经有几个关于stroke-dashoffset技巧 – SumNeuron