[英]Calculating a the length of an arc in D3
Presumably if I know the innerRadius
for an arc (which will be the same length for A and B) I can plot an imaginary triangle and use the Law of Cosines 如果我知道一个圆弧的innerRadius
(对于A和B的长度相同),我可以绘制一个虚构的三角形并使用余弦定律
c2 = a2 + b2 - 2ab cos C c2 = a2 + b2-2ab cos C
But I'd need the angle C
. 但是我需要角度C
This be retrieved in D3 by getting the difference in start and end angles. 通过获取起始角度和终止角度的差值,可以在D3中进行检索。
var x = d3.scaleLinear()
.range([0, 2 * Math.PI])
.clamp(true);
var y = d3.scaleLinear()
.range([0, this.radius])
.clamp(true);
var.arc = d3.arc()
.startAngle(function(d) {
return x(d.x0);
})
.endAngle(function(d) {
return x(d.x1);
});
function getRingRadius() {
// for example
return 50;
}
function measureSegment(d) {
var a = getRingRadius() * (d.depth || 0), b = a;
var C = arc.startAngle()(d) - arc.endAngle()(d);
return Math.sqrt((a*a + b*b) - 2*a*b*Math.cos(C));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.